Offset in filtered data when using filtfilt() Function

조회 수: 9 (최근 30일)
Kletzi
Kletzi 2022년 11월 19일
답변: Paul 2022년 11월 19일
Hello,
when filtering my data using the filtfilt() Function, I get a offset in the filtered data.Can anyone tell me where this offset could come from and how to get rid of it?
Below is the code I use for filterdesign and actual filtering:
fg = 0.1; % Desired Cutoff frequency
fs = 1/(mean(diff(Time))); % Derive sample frequency fs from Time vector
fc = 2*fg/fs; % Calculate normalized cutoff frequency
d = designfilt("lowpassfir", 'PassbandFrequency', fc, 'StopbandFrequency',fc+0.5*fc) % Filterdesign as lowpass filter
filtered_data = filtfilt(d, unfiltered_data);
figure()
plot(Time, unfiltered_data)
hold on
plot(Time, filtered_data)
legend('unfiltered data', 'filtered data')
The figure below shows the result of some example data.
  댓글 수: 2
Paul
Paul 2022년 11월 19일
Hi Kletzi,
It will be easier to get help if you post the full code and data that recreastes the example in your question (or something close to it).
Jan
Jan 2022년 11월 19일
편집: Jan 2022년 11월 19일
@Paul: You can reproduce the effect with dummy data:
fc = 0.4;
d = designfilt("lowpassfir", 'PassbandFrequency', fc, 'StopbandFrequency', 1.5 * fc);
x = rand(1, 200) + 20;
y = filtfilt(d, x);
plot(x, 'b'); hold('on');
plot(y, 'r');

댓글을 달려면 로그인하십시오.

답변 (1개)

Paul
Paul 2022년 11월 19일
Thanks @Jan
The filter, d, does not have unity gain at dc.
fc = 0.4;
d = designfilt("lowpassfir", 'PassbandFrequency', fc, 'StopbandFrequency', 1.5 * fc);
dcgain = sum(d.Coefficients)
dcgain = 0.9481
filtfilt attenuates the dc component of x by dcgain^2
(20 + .5)*dcgain^2 % 0.5 is the mean of rand
ans = 18.4273
x = rand(1, 200) + 20;
y = filtfilt(d, x);
plot(x, 'b'); hold('on');
plot(y, 'r');
plot(filtfilt(d,20+0.5+0*x),'g');

카테고리

Help CenterFile Exchange에서 Digital Filter Design에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by