Products & Services Solutions Academia Support User Community Company

Learn more about Signal Processing Toolbox   

filtfilt - Zero-phase digital filtering

Syntax

y = filtfilt(b,a,x)

Description

y = filtfilt(b,a,x) performs zero-phase digital filtering by processing the input data, x, in both the forward and reverse directions (see problem 5.39 in [1]). The vector b provides the numerator coefficients of the filter and the vector a provides the denominator coefficients. If you use an all-pole filter, enter 1 for b. If you use an all-zero filter (FIR), enter 1 for a. After filtering the data in the forward direction, filtfilt reverses the filtered sequence and runs it back through the filter. The result has the following characteristics:

filtfilt minimizes start-up and ending transients by matching initial conditions, and you can use it for both real and complex inputs. Do not use filtfilt with differentiator and Hilbert FIR filters, because the operation of these filters depends heavily on their phase response.

Example

Zero-phase filtering helps preserve features in the filtered time waveform exactly where those features occur in the unfiltered waveform. To illustrate the use of filtfilt for zero-phase filtering, consider an electrocardiogram waveform as an example.

plot(ecg(500)); %plot ECG signal

The QRS complex is an important feature in the ECG waveform beginning around time point 160 in this example.

The following sample corrupts the ECG waveform with additive noise, constructs a lowpass FIR equiripple filter, and filters the noisy waveform using both zero-phase and conventional filtering. Because the filter is an all-zero (FIR) filter, the input a equals 1.

x=ecg(500)'+0.25*randn(500,1); %noisy waveform
h=fdesign.lowpass('Fp,Fst,Ap,Ast',0.15,0.2,1,60);
d=design(h,'equiripple'); %Lowpass FIR filter
y=filtfilt(d.Numerator,1,x); %zero-phase filtering
y1=filter(d.Numerator,1,x); %conventional filtering
subplot(211);
plot([y y1]);
title('Filtered Waveforms');
legend('Zero-phase Filtering','Conventional Filtering');
subplot(212);
plot(ecg(500));
title('Original Waveform'); 

Zero-phase filtering reduces noise in the signal and preserves the QRS complex at the same time it occurs in the original signal. Conventional filtering reduces noise in the signal, but delays the QRS complex.

Algorithm

filtfilt is an M-file that uses the filter function. filtfilt attempts to minimize start-up transients by adjusting the initial conditions to match the DC component of the signal. The algorithm also prepends several filter lengths of a flipped, reflected copy of the input signal.

References

[1] Oppenheim, A.V., and R.W. Schafer, Discrete-Time Signal Processing, Prentice-Hall, 1989, pp.284–285.

[2] Mitra, S.K., Digital Signal Processing, 2nd ed., McGraw-Hill, 2001, Sections 4.4.2 and 8.2.5.

[3] Gustafsson, F., Determining the initial states in forward-backward filtering, IEEE Transactions on Signal Processing, April 1996, Volume 44, Issue 4, pp.988–992.

See Also

fftfilt, filter, filter2

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS