# Design of all pass filter with desired phase response

I want to design an all pass filter with a desired phase response in MATLAB. But in MATLAB, all pass filters are designed either by specifying the all pass filter coefficients or from a transfer function of the desired all pass filter. What if we do not know the transfer function of the filter (i.e. we have to estimate the filter), and only want the phase delay at each particular frequencies to be a specific value, say for example at 1kHz, I want a phase shift of 12 degree and at 2kHz ,I want a phase delay of 4 degrees and so on. Assuming sampling frequency to be 40kHz, how to design such type of digital filters.

• Can you be more specific? In radians, you want a phase shift of $\phi(\omega)=-\frac{12}{180}\pi$ at 1 kHz ($\omega = \frac{1}{40}2\pi$) and an apparently lesser phase shift of $\phi(\omega)=-\frac{4}{180}\pi$ at 2 kHz ($\omega = \frac{2}{40}2\pi$)? These causal APFs have more negative phase shift at higher frequencies, not less. So unless you're willing to put in nearly an entire phase wrap around of $2\pi$ (360°), between the two frequencies, you cannot meet your spec with a causal filter. Aug 27, 2021 at 13:42

The Audio EQ Cookbook has the general formulae for all-pass filters (APF). You can maybe cascade four of these APFs together and get 12° at 1 kHz and 360°+4° at 2 kHz. But it's a wild APF and will definitely have some "resonance" (of a sort) around 1.5 kHz.

This is a tricky problem.

First you need to decide whether you need a "true" all pass filter or can do with an approximate one. The difference being

$$|H_\text{trueAP}(\omega) = 1| \\ | |H_\text{apprAP}(\omega)| -1 | < \epsilon, \omega_1 < \omega < \omega_2$$

i.e. do you need the magnitude to be exactly one for all frequencies or do you just need a magnitude "sufficiently close to one" over a certain frequency range?

True all pass filter have some mathematical properties that severely limits the degrees of freedom.

1. They are IIR filters
2. The zeros are inverses of the poles which is equivalent to the transfer function polynomials being mirror of each other.
3. The phase is monotonic decreasing with frequency.
4. The phase DC is 0 and at Nyquist is $$N\pi$$ where $$N$$ is the filter order
That means you need an $$N^\text{th}$$ order all pass to accommodate $$N$$ target points. However, you need to make sure first that the target is decreasing but subtracting multiples of $$2\pi$$. For example