Eliminate Outliers and filtering signal
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am using this code to apply different filters to my data from strain gages. How can I remove the outliers first, appy the filters and plot both signals? Do I need to use FFT ?
Thank you.
load('RRData.mat');
R=RRData.Strain_C_Fz;
L=RRData.Strain_HB_Fy;
t=RRData.Time;
samples = length(t);
Fs = (samples-1)/(t(samples)-t(1));
[R_max,idx]= max(R);
[L_max,idx]= max(L);
t_m = t(idx);
figure(1)
%subplot(3,2,1) ;
plot(t,R);hold on;plot(t,L);legend('Right','Left');
plot(t_m, R_max,'^r');hold on; plot (t_m, L_max,'ro')
text(t_m,R(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', R_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
text(t_m,L(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', L_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
title(['Data samples at Fs = ' num2str(round(Fs)) 'Hz' ]);
grid
% NB : decim = 1 will do nothing (output = input)
decim = 50;
if decim > 1
R = decimate (R,decim);
L = decimate (L,decim);
Fs = Fs/decim;
end
samples = length(R);
t = (0:samples - 1)*1/Fs;
[R_max,idx]= max(R);
[L_max,idx]= max(L);
t_m = t(idx);
figure(2)
%subplot(3,2,2) ;
plot(t,R); hold on; plot (t,L); legend('Right','Left');
plot(t_m, R_max,'^r');hold on; plot (t_m, L_max,'ro')
text(t_m,R(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', R_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
text(t_m,L(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', L_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
title(['Data samples at Fs = ' num2str(round(Fs)) 'Hz']);
grid on
figure(3)
N = 25;
Rs = slidingavg(R,N);
Ls = slidingavg(L,N);
[R_max,idx]= max(Rs);
[L_max,idx]= max(Ls);
t_m = t(idx);
%subplot(3,2,3) ;
plot(t,Rs); hold on; plot (t,Ls); legend('Right','Left');
plot(t_m, R_max,'^r');hold on; plot (t_m, L_max,'ro')
text(t_m,R(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', R_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
text(t_m,L(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', L_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
title(['Data samples at Fs = ' num2str(round(Fs)) 'Hz / Smoothed with slidingavg' ]);
grid on
figure(4)
N = 50;
Rs = medfilt1(R, N, 'truncate');
Ls = medfilt1(L, N, 'truncate');
[R_max,idx]= max(Rs);
[L_max,idx]= max(Ls);
t_m = t(idx);
%subplot(3,2,4) ;
plot(t,Rs); hold on; plot (t,Ls); legend('Right','Left');
plot(t_m, R_max,'^r');hold on; plot (t_m, L_max,'ro')
text(t_m,R(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', R_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
text(t_m,L(idx), sprintf('\\leftarrow Max = %.6f\n t = %.2f ', L_max,t_m), 'HorizontalAlignment','left', 'VerticalAlignment','top')
title(['Data samples at Fs = ' num2str(round(Fs)) 'Hz / Smoothed with medfilt1' ]);
grid on
figure(5)
N = 50;
Rs = sgolayfilt(R,3,51);
Ls = sgolayfilt(L,3,51);
[Rs_max,index]= max(Rs);
[Ls_max,index]= max(Ls);
t_max = t(index);
%subplot(3,2,5) ;
plot(t,Rs); hold on; plot (t,Ls); legend('Right','Left');
plot(t_max, Rs_max,'^r');hold on; plot (t_max, Ls_max,'ro')
text(t_max,Rs(index),sprintf('\\leftarrow Max = %.6f\n t = %.2f ', Rs_max, t_max), 'HorizontalAlignment','left', 'VerticalAlignment','top')
text(t_max,Ls(index),sprintf('\\leftarrow Max = %.6f\n t = %.2f ', Ls_max, t_max), 'HorizontalAlignment','left', 'VerticalAlignment','top')
title(['Data samples at Fs = ' num2str(round(Fs)) 'Hz / Smoothed with sgolayfilt' ]);
grid on
0 commentaires
Réponses (1)
Chunru
le 13 Août 2021
load RRData
% median filter to remove outliers (for 1 channel)
y1 = medfilt1(RRData.Strain_C_Fz, 7);
plot(RRData.Time, RRData.Strain_C_Fz, RRData.Time, y1)
0 commentaires
Voir également
Catégories
En savoir plus sur Detection, Range and Doppler Estimation dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!