Design of discrete time second order all pass filter I want to design a second order  digital all pass filter with the transfer function given by
$$H(z)=\frac{a_2 +a_1 z^{-1}+z^{-2}}{1+a_1 z^{-1}+a_2 z^{-2}}$$
The input to this filter has frequencies ranging from $1$ to $8\ \rm kHz$. The sampling frequency is $20\ \rm kHz$.
How to design the filter coefficients $a_1, a_2$ such that for a particular input frequency, I have to apply 180 degree phase shift? The frequency which is given a 180 degree phase shift will vary. So, how to vary the filter coefficients based on which frequency has to be phase shifted by 180 degree?
HINTS:

What value does $H(z_0)$ have if there's a phase shift of $180$ degrees (for $|z_0|=1$)?
Equate $H(z_0)$ to that value and write down the resulting equation for $a_1$ and $a_2$ and $z_0$.
You want a stable all-pass filter, so choose $a_2$ such that a given desired pole radius $r$, $0&lt;r&lt;1$, is achieved if you assume two complex conjugate poles.
With that value of $a_2$, and with a given frequency $\omega_0$ for which the phase shift is $180$ degrees, solve the equation you got in 2. for $a_1$. The result will have the form $$a_1=f(a_2)\cos(\omega_0)$$ where $f(\cdot)$ is a simple affine function. Note that $\omega_0$ is normalized by the sampling frequency.