filt vs. filtfilt very different output

116 views (last 30 days)
Aaron
Aaron on 20 Jun 2014
Commented: John BG on 3 Jan 2018
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
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
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.

Sign in to comment.

Answers (2)

Jan
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.

Chad Greene
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.
  1 Comment
Aaron
Aaron on 20 Jun 2014
Hi Chad,
Thanks for the reply. I do understand what you write about Hilbert FIR filters. Even in that case I'd be surprised to find the stark difference in response that I am seeing. Chebyshev filters are very similar to Butterworth filters, and are IIR (non-linear phase). The link below is a nice summary of using the filter design in the SP toolbox.
This is an excerpt:
"Although IIR filters have nonlinear phase, data processing within MATLAB® software is commonly performed "offline," that is, the entire data sequence is available prior to filtering. This allows for a noncausal, zero-phase filtering approach (via the filtfilt function), which eliminates the nonlinear phase distortion of an IIR filter."
I think something else is going-on here than just phase distortion...

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!