2
$\begingroup$

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

(thanks to http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt)

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.

$\endgroup$
5
$\begingroup$

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.

$\endgroup$
  • 4
    $\begingroup$ 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. $\endgroup$ – Jazzmaniac Oct 23 '13 at 15:43
  • $\begingroup$ 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). $\endgroup$ – Peter K. Oct 23 '13 at 15:57
  • $\begingroup$ 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. $\endgroup$ – Jason R Oct 23 '13 at 16:10
  • 4
    $\begingroup$ 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. $\endgroup$ – Hilmar Oct 23 '13 at 16:47
  • $\begingroup$ @Hilmar: Agreed. $\endgroup$ – Jason R Oct 23 '13 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.