# Very first values of y[n] in an IIR filter

I use a simple biquad IIR filter :

if (n >= 2)
y[n] = (b0/a0)*x[n] + (b1/a0)*x[n-1] + (b2/a0)*x[n-2]
- (a1/a0)*y[n-1] - (a2/a0)*y[n-2]
else
y[n] = x[n]     // here it probably needs to be modified


It works very well.

My problem is that the filtered signal sometimes explodes in the first milliseconds, and then returns to normal after a few milliseconds.

How should I initiallize the first values of y[n] ? I have done this

y[n] = x[n]


for n=0,1, but probably the problem comes from here ?

The problem (it explodes in the first milliseconds) is important when I do 2, 3, or more passes of the same filter in cascade.

Thanks in advance.

## 1 Answer

Typically, you would initialize the filter state (which in your example includes $x[-1]$, $x[-2]$, $y[-1]$, and $y[-2]$) with zeros. This is equivalent to assuming that the filter is causal.

• Why is this equivalent to assuming the filter is causal? I think it's equivalent to assuming that the signal was 0 before the first sample. The causality of the filter lies in its recursion structure, not in the initial conditions imho. – Jazzmaniac Oct 23 '13 at 15:43
• It seems that it's equivalent to assuming the signal to be filtered is "causal" (i.e. only starts being non-zero after we start watching it). – Peter K. Oct 23 '13 at 15:57
• I apologize for my imprecise language. I believe that it's making a causal assumption on both the signal and the filter's impulse response. If $x[n] = 0 \forall n < 0$, then $x[n]$ is causal. If $y[n] < 0 \forall n < 0$, then $y[n]$ is causal, i.e. the filter doesn't start generating a response before the input gets there. – Jason R Oct 23 '13 at 16:10
• Strictly speaking, causality is only defined in the context of systems, i.e. things that have an input and an output. Causal signals don't make much sense because this only depends on the arbitrary choice for t = 0. – Hilmar Oct 23 '13 at 16:47
• @Hilmar: Agreed. – Jason R Oct 23 '13 at 16:48