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

147 lines
4.6 KiB
Matlab

function Res = Tilt_Spindle_error(dataX, dataX2,NbTurn, texte, path)
L = length(dataX);
res_per_rev = L/NbTurn;
P = 0: (res_per_rev * NbTurn)-1;
Pos = P'*360/res_per_rev;
Theta = deg2rad(Pos)';
D = 76.2; %distance entre les deux balls en milimetres
x1 = myfit2(Pos, dataX);
y1 = myfit2(Pos, dataX2);
%Convert data to frequency domain and scale accordingly
X2 = 2/(res_per_rev*NbTurn)*fft(x1);
f2 = (0:L-1)./NbTurn;
Y2 = 2/(res_per_rev*NbTurn)*fft(y1);
% 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);
Y2dec(i) = 0;
Y2int(i) = Y2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
Y2dec(i) = Y2(i);
Y2int(i) = 0;
end
end
if mod(length(f2),2) == 1 % Case length(f2) is odd -> the mirror image of the FFT is reflected between 2 harmonique
for i = length(f2)/2+1.5:length(f2)
if mod(f2(i-1), 1) == 0
X2dec(i) = 0;
X2int(i) = X2(i);
Y2dec(i) = 0;
Y2int(i) = Y2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
Y2dec(i) = Y2(i);
Y2int(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);
Y2dec(i) = 0;
Y2int(i) = Y2(i);
else
X2dec(i) = X2(i);
X2int(i) = 0;
Y2dec(i) = Y2(i);
Y2int(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
Y2int(1) = 0; %remove the data average/dc component
Y2int(NbTurn+1) = 0; %Remove fondamental/eccentricity
% Y2int(length(f2)) = 0; %remove the data average/dc component
Y2int(length(f2)-NbTurn+1) = 0; %Remove eccentricity
% Extract the fondamentale-> exentricity
for i = 1:length(f2)
if i == NbTurn+1 || i== length(f2)-NbTurn + 1
X2fond(i) = X2(i);
Y2fond(i) = Y2(i);
else
X2fond(i) = 0;
Y2fond(i) = 0;
end
end
X2tot = X2int + X2dec;
Y2tot = Y2int + Y2dec;
%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));
%Convert data to "time" domain and scale accordingly
Wyint = real((res_per_rev*NbTurn)/2*ifft(Y2int));
Wydec = real((res_per_rev*NbTurn)/2*ifft(Y2dec));
Wytot = real((res_per_rev*NbTurn)/2*ifft(Y2tot));
Tint = atan((Wyint - Wxint)/(D*1000));
Tdec = atan((Wydec - Wxdec)/(D*1000));
Ttot = atan((Wytot - Wxtot)/(D*1000));
%%
fig = figure();
% total error motion
Total_Error = max(Ttot)- min(Ttot);
%lsc X synchronous
Synchronous_Error = max(Tint)- min(Tint);
%lsc X Asynchronous
var = reshape(Tdec,length(Tdec)/NbTurn,NbTurn);
for i = 1:length(Tdec)/NbTurn
Asynch(i) = max(var(i,:)) - min(var(i,:)) ;
end
Asynchronous_Error = max(Asynch)- min(Asynch);
% Raw Error Motion without Exentricity (sync +asynch)
subplot(2, 2, 2);
polar2(Theta,Ttot, 'b');
title('Total error');
% Residual Synchronous Error Motion without Exentricity (ie fondamental sync err motion)
subplot(2, 2, 3);
polar2(Theta,Tint,'b');
title('Residual synchronous error');
% Asynchronous Error Motion
subplot(2, 2, 4);
polar2(Theta,Tdec, 'b');
title ('Asynchronous error');
%%
strmin1 = ['Total error = ', num2str(Total_Error*1000000), ' \murad'];
strmin2 = ['Residual synchronous error = ', num2str(Synchronous_Error*1000000), ' \murad' ];
strmin3 = ['Asynchronous error = ', num2str(Asynchronous_Error*1000000), ' \murad'];
dim0 =[0.04 0.5 0.3 .3];%x y w h basgauche to hautdroite
dim1 =[0.15 0.65 0.3 .3];
annotation('textbox',dim0, 'String',{ strmin1 , strmin2, strmin3}, 'FitBoxToText', 'on')
annotation('textbox',dim1, 'String',texte, 'FitBoxToText', 'on')
saveas(fig,fullfile(path,char(texte)),'jpg');
Res = 1;
close all;
end