# How can I prove stability of a biquad filter with non-zero initial conditions

Ok, so the situation is that I have a DFII biquad with some filter coefficients:

\begin{align} w[n] &= x[n] - a_1*w[n-1] - a_2*w[n-2]\\ y[n] &= b_0*w[n] + b_1*w[n-1] + b_2*w[n-2] \end{align}

While the filter is running, I change the coefficients and I believe my filter is going unstable. I want to build in a check that it is going to be stable. Currently, I simply check that the poles lie inside the unit circle by checking my $a_n$ coefficients. But it doesn't work. I believe that the problem is that I have non-zero values in my states (i.e. $w[-1]$ and $w[-2]$) and my stability check doesn't even consider this. I cannot reset my states while the filter is running without producing an audible click.

The questions: How do I check for stability of a filter with non-zero initial conditions?

I have a couple thoughts for solutions:

1. Simply take the $\mathcal Z$-tranform of the impulse response (of the feedback portion), which looks something like this: $$h[n] = \begin{cases} 0 & n < 0\\ 1 - a_1*K_1 - a_2*K_2 & n = 0\\ 0 - a_1*h[0] - a_2*K_1 & n = 1\\ - a_1*h[n-1] - a_2*h[n-2] & n \ge 2 \end{cases}$$

2. Solve the difference equation à la differential equations: $$h[n] + a_1*h[n-1] + a_2*h[n-2] = 0, n \ge 2$$

3. Or prove that the sequence $h[n]$ (from above) converges $$\sum_{n=0}^{\infty}\lvert h[n]\rvert < \infty$$

Am I on the right track? I can't seem to figure out the solution for any of these methods.

• Good question. Here's a "devil's advocate" type of question: if you did determine that your new coefficients could cause instability with the current filter state, what would you do as a result? Clear the state? It might be easier to just do that and live with the effects. Or, as Hilmar suggested, running both filters in parallel for a short period of time and cross-fading between their outputs could be a good compromise. – Jason R Oct 23 '13 at 12:14

Tricky problem. Not sure I can answer this but here are a few pointers:

1. Direct Form II is the worst biquad for audio processing. The transfer function between the input and the state is given just by the poles. The gain can be really large, I have seen gains of in excess of a 100 dB for reasonable audio filters.
2. This makes real time switching of Direct Form II very tricky. The magnitude of your state can change 10s of dB with seemingly small overall filter changes. This creates massive clicks and pops and occasionally unstable filters.
3. Much better choices are Direct Form I or transposed Form II. For these filter types the state variables are always in the same order of magnitude than input and output. Much less potential for loud pops and clicks or instability
4. There is not "sure fire" way of updating an IIR filter in real time without the potential for audible artifacts. Some potential methods are running two filters in parallel and slowly cross fading the output or updating pole and zero locations really slowly with very small steps at the time
5. If you must update in real time, make sure that you don't update one coefficient at a time but ideally both poles and zeros in one go. At least do the poles all at ones (i.e. always update a1 and a2 at the same time)
6. Update lower gain first. If the pole section of the new filter has lower gain, update the poles first and then the zeros. If the pole section of the filter has higher gain, update zeros first and then poles
7. If you need to stick with Direct Form II, it's probably best to zero out the state during update. This will still create an artifact but it's probably less than if you don't and at least it guarantees stability.
• I completely agree with you about DFII being a bad topology. In fact I think it is precisely these very large intermediate states that make switching the filter real-time so problematic. I would prefer DFII Transposed, but our DSP hardware engineers are insistent on not changing the topology :-/ – xaviersjs Oct 24 '13 at 8:01

I found a solution that I believe is the proper math I was looking for. Although Hilmar's answer is also quite accurate and helpful. I found information in my old DSP textbook about the "Unilateral Z-Transform", which is briefly defined here: https://ccrma.stanford.edu/~jos/filters/Z_Transform.html. The important part is the properties some of which are described here: http://web.eecs.umich.edu/~aey/eecs451/lectures/zir.pdf. The important property is the delay property: $$x[n-1] \overset{\mathcal{UZ}}{\iff} z^{-1}\mathcal{X}^+(z)+x[-1]$$

This was critical for my needs because it can be used to serve initial conditions. The next thing the book shows me is the application of this property for a two-sample delay: $$w[n] = y[n-1] = x[n-2] \\ \mathcal{W}^+(z) = x[-2] + x[-1]z^{-1} + z^{-2}\mathcal{X^+(z)}$$

Applying this to the general form a 2nd order feedback filter I get $$y[n] - a_1y[n-1] - a_2y[n-2] = x[n] \\ h[n] - a_1h[n-1] - a_2h[n-2] = \delta[n] \\ \mathcal{H}^+(z) - a_1 \left( z^{-1}\mathcal{H}^+(z) + h[-1] \right) - a_2\left( z^{-2}\mathcal{H}^+(z) + z^{-1}h[-1] + h[-2] \right) = 1 \\ \mathcal{H}^+(z) \left(1 - a_1z^{-1} - a_2z^{-2} \right) = 1 - \left(a_1h[-1] + a_2h[-2] + a_2h[-1]z^{-1} \right)$$

This gives me a formula with two parts, which my textbook refers to as the zero-state response + zero-input response

$$\mathcal{H}^+(z) = \frac{1}{1 - a_1z^{-1} - a_2z^{-2}} - \frac{a_1h[-1] + a_2h[-2] + a_2h[-1]z^{-1}}{1 - a_1z^{-1} - a_2z^{-2}}$$

I guess that means the general equation for for any causal biquad with initial conditions is

$$\mathcal{H}^+(z) = \frac{b_0 + b_1z^{-1} + b_2z^{-2}}{ 1 - a_1z^{-1} - a_2z^{-2}} - \frac{a_1h[-1] + a_2h[-2] + a_2h[-1]z^{-1}}{1 - a_1z^{-1} - a_2z^{-2}}$$

The result is that the feedback coefficients are the only things that can cause instability. However, maybe the initial conditions cause audio to go outside of a (stable) bound.

• If the initial conditions come close to causing a pole-zero cancellation, you might get strange things happening in a finite-precision implementation. – Peter K. Oct 24 '13 at 11:44

As Hilmar says in 4., reloading will cause clicks. An output sample is basically the inner product between a vector of previous samples and a vector of filter coefficients. An abrupt change in the filter vector causes just as much clicks as an abrupt change in the sample vector. A possibly simpler solution, that is equivalent to cross fading two filter channels, is to over time reload interpolated versions of the old and new filter vectors.