# 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.

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.
• 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