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

조회 수: 1 (최근 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 CenterFile Exchange에서 Get Started with DSP System Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by