
Correcting a y-shift when filtering signal in the frequency domain
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Josh Selfe
am 17 Aug. 2021
Kommentiert: Mathieu NOE
am 24 Aug. 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?

0 Kommentare
Akzeptierte Antwort
Mathieu NOE
am 23 Aug. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Filter Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!