Signal Processing Toolbox Previous page   Next Page

Anti-Causal, Zero-Phase Filter Implementation

In the case of FIR filters, it is possible to design linear phase filters that, when applied to data (using filter or conv), simply delay the output by a fixed number of samples. For IIR filters, however, the phase distortion is usually highly nonlinear. The filtfilt function uses the information in the signal at points before and after the current point, in essence "looking into the future," to eliminate phase distortion.

To see how filtfilt does this, recall that if the z-transform of a real sequence x(n) is X(z), the z-transform of the time reversed sequence x(n) is X(1/z). Consider the processing scheme.

The signal X(z) is fed into a filter H(z) producing X(z)H(z) output. This output is then time reversed producing X(1?/z)H(1/z) which is then fed into another filter H(z) producing X(1/z)H(1/z)H(z). This output is then time reversed producing X(z)H(1/z)H(z).

When |z| = 1, that is z = ej, the output reduces to X(ej)|H(ej)|2. Given all the samples of the sequence x(n), a doubly filtered version of x that has zero-phase distortion is possible.

For example, a 1-second duration signal sampled at 100 Hz, composed of two sinusoidal components at 3 Hz and 40 Hz, is

Now create a 10-point averaging FIR filter, and filter x using both filter and filtfilt for comparison:

Both filtered versions eliminate the 40 Hz sinusoid evident in the original, solid line. The plot also shows how filter and filtfilt differ; the dashed (filtfilt) line is in phase with the original 3 Hz sinusoid, while the dotted (filter) line is delayed by about five samples. Also, the amplitude of the dashed line is smaller due to the magnitude squared effects of filtfilt.

filtfilt reduces filter startup transients by carefully choosing initial conditions, and by prepending onto the input sequence a short, reflected piece of the input sequence. For best results, make sure the sequence you are filtering has length at least three times the filter order and tapers to zero on both edges.


Previous page  Other Functions for Filtering Frequency Domain Filter Implementation Next page

© 1994-2005 The MathWorks, Inc.