Correcting a y-shift when filtering signal in the frequency domain
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
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
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File 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!