Offset in filtered data when using filtfilt() Function
10 views (last 30 days)
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);
legend('unfiltered data', 'filtered data')
The figure below shows the result of some example data.
Paul on 19 Nov 2022
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)
filtfilt attenuates the dc component of x by dcgain^2
(20 + .5)*dcgain^2 % 0.5 is the mean of rand
x = rand(1, 200) + 20;
y = filtfilt(d, x);
plot(x, 'b'); hold('on');