nass-micro-station-measurem.../static-spindle/Macros_ttt_spindle/Spindle_error.m

132 lines
4.1 KiB
Mathematica
Raw Normal View History

2019-03-14 16:40:28 +01:00
function [Res] = Spindle_error(data, NbTurn, texte, path)
%%
L = length(data);
res_per_rev = L/NbTurn;
P = 0:(res_per_rev*NbTurn-1);
Pos = P' * 360/res_per_rev;
Theta = deg2rad(Pos)';
% Temperature correction
x1 = myfit2(Pos, data);
% Convert data to frequency domain and scale accordingly
X2 = 2/(res_per_rev*NbTurn)*fft(x1);
f2 = (0:L-1)./NbTurn; %upr -> once per revolution
%% Separate the fft integers and not-integers
for i = 1:length(f2)
if mod(f2(i), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
end
end
%% Case length(f2) is odd -> the mirror image of the FFT is reflected between 2 harmonique
if mod(length(f2),2) == 1
for i = length(f2)/2+1.5:length(f2)
if mod(f2(i-1), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
end
end
else % Case length(f2) is even -> the mirror image of the FFT is reflected at the Nyquist frequency
for i = length(f2)/2+1:length(f2)
if mod(f2(i), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
end
end
end
%%
X2int(1) = 0; %remove the data average/dc component
X2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% X2int(length(f2)) = 0; %remove the data average/dc component
X2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
%% Extract the fondamental -> exentricity
for i = 1:length(f2)
if i == NbTurn+1 || i == length(f2)-NbTurn+1
X2fond(i) = X2(i);
else
X2fond(i) = 0;
end
end
X2tot = X2int + X2dec;
Wxfond = real((res_per_rev*NbTurn)/2 * ifft(X2fond)); % Convert data to "time" domain and scale accordingly
Wxint = real((res_per_rev*NbTurn)/2 * ifft(X2int));
Wxdec = real((res_per_rev*NbTurn)/2 * ifft(X2dec));
Wxtot = real((res_per_rev*NbTurn)/2 * ifft(X2tot));
%%
fig = figure();
subplot(3, 2, 5);
bar(f2(1:50*NbTurn),1000*abs(X2int(1:50*NbTurn)),3);
axis([0,50,0,1000*max(abs(X2int(1:50*NbTurn)))]);
title ('Fourier integer');
xlabel('UPR'); ylabel ('nm')
subplot(3, 2, 6);
bar(f2(1:50*NbTurn),1000*abs(X2dec(1:50*NbTurn)),2);
title('Fourier non-integer');
axis([0,50,0,1000*max(abs(X2dec(1:50*NbTurn)))]);
title('Fourier non-integer');
xlabel('UPR'); ylabel ('nm')
% Eccentricity
Eccentricity = max(Wxfond) - min(Wxfond);
% total error motion X
Total_Error = max(Wxtot) - min(Wxtot);
% lsc X synchronous
Synchronous_Error = max(Wxint) - min(Wxint);
% lsc X Asynchronous
var = reshape(Wxdec,length(Wxdec)/NbTurn,NbTurn);
for i = 1:length(Wxdec)/NbTurn
Asynch(i) = max(var(i,:)) - min(var(i,:));
end
Asynchronous_Error = max(Asynch) - min(Asynch);
% Raw Error Motion without Exentricity (sync +asynch)
subplot(3, 2, 2);
polar2(Theta,Wxtot, 'b');
title ('Total error');
% Residual Synchronous Error Motion without Exentricity (ie fondamental sync err motion)
subplot(3, 2, 3);
polar2(Theta,Wxint,'b');
title('Residual synchronous error');
% Asynchronous Error Motion
subplot(3, 2, 4);
polar2(Theta,Wxdec, 'b');
title('Asynchronous error');
strmin0 = ['Eccentricity= ', num2str(Eccentricity), ' \mum '];
strmin1 = ['Total error = ', num2str(Total_Error*1000), ' nm'];
strmin2 = ['Residual synchronous error = ', num2str(Synchronous_Error*1000), ' nm' ];
strmin3 = ['Asynchronous error = ', num2str(Asynchronous_Error*1000), ' nm'];
dim0 = [0.1 0.55 0.3 .3];%x y w h basgauche to hautdroite
dim1 = [0.15 0.65 0.3 .3];
annotation('textbox',dim0, 'String',{ strmin0 ,strmin1 , strmin2, strmin3}, 'FitBoxToText', 'on')
annotation('textbox',dim1, 'String',texte, 'FitBoxToText', 'on')
saveas(fig,fullfile(path,char(texte)),'jpg');
Res = 1;
close all;
end