Correcting a y-shift when filtering signal in the frequency domain

2 vues (au cours des 30 derniers jours)
Josh Selfe
Josh Selfe le 17 Août 2021
Commenté : Mathieu NOE le 24 Août 2021
I am trying to apply a low-pass filter to a signal ro remove noise.
I have applied the filter and corrected for the x-shift as shown below:
filtertype = 'FIR';
Ts = (time(end)/1000)/N; %sampling interval. time is in ms
Fs = 1/Ts; %sampling frequency
Fpass = 10;
Fstop = 50;
Rp = 5;
Astop = 100;
LPF = dsp.LowpassFilter('SampleRate',Fs,...
'FilterType',filtertype,...
'PassbandFrequency',Fpass,...
'StopbandFrequency',Fstop,...
'PassbandRipple',Rp,...
'StopbandAttenuation',Astop);
output = step(LPF, voltage);
%plot
fig1 = figure ();
plot(time, voltage, time,output);
ylabel('voltage');
legend('Raw Data', 'Filtered Data');
%correcting for x-shift
grpdelay(LPF,numdatapoints,Fs);
delay = mean(grpdelay(LPF));
tshift = time(1:end-delay);
vshift = voltage(1:end-delay);
output(1:delay+1) = [];
%plot
plot(tshift,vshift,tshift,output);
legend('Original Signal','Filtered Shifted Signal');
However, there is a y-shift in the filtered data which I cannot seem to prevent (see attached PNG, with similar data with 6 traces before filtering and 6 after filtering), no matter how I change the filter parameters.
Is my method of filtering incorrect, and thus producing this shift? Or how can I correct for the shift?

Réponse acceptée

Mathieu NOE
Mathieu NOE le 23 Août 2021
hello Josh
when it comes to smooth a noisy signal, I usually go for smoothdata. Code is simple and it works well , no delay between output and input
% %%%%%%%%%%%%%%%%
output = smoothdata(voltage, 'gaussian' , 3500);
plot(time,voltage,time,output);legend('Raw','Smoothed');
title(['Data samples at Fs = ' num2str(round(Fs)) ' Hz / Smoothed with smoothdata' ]);
  2 commentaires
Josh Selfe
Josh Selfe le 24 Août 2021
Thank you Mathieu, this looks great. Appreciate your help.
Mathieu NOE
Mathieu NOE le 24 Août 2021
My pleasure
would you accept my answer ?
thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by