# How to keep phase response of IIR filter?

We know that IIR digital filter has nonlinear phase response in general.

How can I linearize the phase response of IIR filter without altering its magnitude response?

• only with an all-pass filter. and the APF will only linearize the phase response for a segment of the frequency response, not all of it. – robert bristow-johnson Mar 5 '17 at 6:12
• if you're willing to re-design all magnitude features of the IIR, so that these features in dB are cut in half, then running the signal through this IIR filter twice will get you back to approximately the original IIR. then you can use a concept called forward-backward filtering or filtfilt() to get zero-phase filtering. is your filter real-time or is it working on a file or buffer of samples? – robert bristow-johnson Mar 5 '17 at 6:14

To my knowledge, you can't linearize it arbitrarily, but that being said, you can obtain approximately linear phase by processing the output through a cascade of all-pass filters.

An all-pass filter used this way is usually called a phase compensator or a phase equalizer. A single pole-zero all-pass IIR filter has the following structure $$H(z) = \frac{p - z^{-1}}{1 - p z^{-1}}$$ where $p$ controls the location of the pole/zero. You can optimize a cascade of filters of this type to equalize your phase response using least squares or some other filter design technique.

Note that this technique reduces the primary advantage of choosing an IIR filter to begin with. Usually, the point in choosing an IIR filter over an FIR filter is to reduce computational complexity, so performing the phase equalization by cascading all-pass sections might result in a situation where using a linear phase FIR filter in the first place would have been more economical.

As described in hops's answer, in principle it's always possible to approximately linearize the phase of a given IIR filter in a specified frequency region by cascading it with an allpass filter, while leaving the magnitude response unchanged. However, this approach is not optimal in the sense that the total required filter order becomes unnecessarily large, and, consequently, the filter is not as computationally efficient as it could be.

Instead of splitting the design process in two phases (first IIR for magnitude approximation, second allpass for phase equalization), an alternative approach can be taken where an IIR filter is designed to directly approximate the specified magnitude and phase responses. There are several algorithms to achieve this. Take a look at this thesis (ch. 5) and the references therein.

The figure below shows a comparison between the first approach (IIR + allpass, dashed curves) and the direct approach (complex approximation, solid curves): The design specifications were taken from this paper by Deczky, where the phase of a $4^{th}$ order Cauer low pass filter is equalized by an $8^{th}$ order allpass filter, resulting in a total filter order of $12$. Deczky's design is shown by the dashed curves in the figure. The alternative design (solid curves) is a direct design of an IIR filter with the desired low pass characteristic and an approximately linear phase in the pass band using the algorithm proposed in the thesis cited above. The order of the numerator polynomial was $12$, just as the cascade in Deczky's design, but the denominator degree was only $6$. Despite this lower order and lower complexity, that filter shows better magnitude, phase, and group delay approximations over a large part of the pass band. Only close to the band edge do the phase and group delay approximation errors become larger. This is a consequence of the least squares design criterion. Note that the total pass band group delay of the filter designed by direct complex approximation is smaller than for the cascade design.