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

3 ビュー (過去 30 日間)
Josh Selfe
Josh Selfe 2021 年 8 月 17 日
コメント済み: Mathieu NOE 2021 年 8 月 24 日
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?

採用された回答

Mathieu NOE
Mathieu NOE 2021 年 8 月 23 日
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 件のコメント
Josh Selfe
Josh Selfe 2021 年 8 月 24 日
Thank you Mathieu, this looks great. Appreciate your help.
Mathieu NOE
Mathieu NOE 2021 年 8 月 24 日
My pleasure
would you accept my answer ?
thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFilter Analysis についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by