filt vs. filtfilt very different output
124 views (last 30 days)
Show older comments
Matlab version R2012b
I am filtering some complex singles (rich frequency content). When I apply the same filter to the same signal using FILTER() and FILTFILT(), the outputs are vastly different. This is not the only inconsistency. The method that gives me the output that I expect depends on what type of filter I am applying. e.g. cheby1 highpass applied to input using FILTFILT looks correct, using FILTER gives a very different and wrong output. Cheby1 lowpass applied using FILTER looks correct and unsig FILTFILT is very different and wrong output.
The difference in responses is too great to be accounted for by initial conditions and start-up transients (see attached figure). What is going on?
Code example:
% All frequency values are in Hz.
Fs = 1; % Sampling Frequency
Fpass = 0.02; % Passband Frequency
Fstop = 0.03; % Stopband Frequency
Apass = 1; % Passband Ripple (dB)
Astop = 80; % Stopband Attenuation (dB)
match = 'passband'; % Band to match exactly
% Construct an FDESIGN object and call its CHEBY1 method.
h = fdesign.lowpass(Fpass, Fstop, Apass, Astop, Fs);
Hd = design(h, 'cheby1', 'MatchExactly', match);
…
% Apply Filter to input An
Af1 = filtfilt(Hd.sosMatrix, Hd.scaleValues,An);
Af2 = filter(Hd,An);
Input:
This looks good:
This looks incorrect (Zoomed View):
Full View :
2 Comments
alessandro lapini
on 2 Jan 2018
Edited: alessandro lapini
on 2 Jan 2018
I recently posted a similar question ( myQuestion ) for cheby2. I guess it is an issue involving how filtfilt determines the starting and the ending conditions, but I am hopefully awaiting for a more clarifying answer.
John BG
on 3 Jan 2018
Hi Alessandro
MATLAB help clearly hints:
Do not use filtfilt with differentiator and Hilbert FIR filters, because the operation of these filters depends heavily on their phase response.
In any case you have chosen band pass filter parameters that look like more low pass filter, which is what you get, a heavily low pass filtered result.
Why don't you try a low pass filter with a far higher cut-off frequency and then decrease it gradually.
Answers (2)
Jan
on 2 Jan 2018
Edited: Jan
on 2 Jan 2018
This is an old question, but this might help others:
- cheby1 highpass applied to input using FILTFILT looks correct, using FILTER gives a very different and wrong output.
- Cheby1 lowpass applied using FILTER looks correct and unsig FILTFILT is very different and wrong output.
No, both outputs of filter and filtfilt are correct, of course. But the results can differ from your expectations. Remember that filtfilt tries to reduce transitional effects at the start and end of the signal. Take a look into the code to get the details and references for the applied method:
edit filtfilt
See also: https://www.mathworks.com/matlabcentral/fileexchange/32261-filterm - maybe the code in FiltFiltM is easier to understand, but it is equivalent to the builtin filtfilt.
0 Comments
Chad Greene
on 20 Jun 2014
I'm not very familiar with the behavior of Chebyshev but the filtfilt function filters forward, then backward, resulting in zero phase distortion. That's why filtfilt is typically my go-to filter. However, some filters (e.g. Hilbert FIR filters) are dependent on phase response, so filtfilt is not always the best choice.
See Also
Categories
Find more on Filter Design in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!