Hi All

I am trying to create a cascaded BiQuad filter using nyquist. I have created this code. I have also provided (as an example) the coefficients required for a 10th order low-pass filter with Fc = 1412.54 Hz at 44100 Hz sampling rate… (FYI this is the upper cut-off frequency of the 1kHz octave band). But my question is, why doesn’t my code work…

Here is my cascade code

```
(defun cascade (s1 i n coeffs)
;s1 = sound to be filtered
;i = current filter (0 to (n/2 - 1))
;n = order of filter (integer multiple of 2)
;coeffs = (a0_0 a1_0 a2_0 b0_0 b1_0 b2_0 a0_1 ...)
;this filter will call itself so that the filters are
;cascaded, each step will implement the next set of
;biquad coefficients until i = 0 when this function will
;stop recursion and return only the last biquaded sound.
(setf a0 (aref coeffs (+ (* 6 i) 0)))
(setf a1 (aref coeffs (+ (* 6 i) 1)))
(setf a2 (aref coeffs (+ (* 6 i) 2)))
(setf b0 (aref coeffs (+ (* 6 i) 3)))
(setf b1 (aref coeffs (+ (* 6 i) 4)))
(setf b2 (aref coeffs (+ (* 6 i) 5)))
(if (<= i 0)
(biquad s1 b0 b1 b2 a0 a1 a2)
(biquad (cascade s1 (- i 1) n coeffs) b0 b1 b2 a0 a1 a2)
)
)
```

If I run this like this

```
(setf coeffs (vector 1.000000 1.636525 -0.670236 0.008428 0.016855 0.008428 1.000000 1.663372 -0.697635 0.008566 0.017132 0.008566 1.000000 1.716946 -0.752313 0.008842 0.017683 0.008842 1.000000 1.796591 -0.833599 0.009252 0.018504 0.009252 1.000000 1.900213 -0.939355 0.009786 0.019571 0.009786))
(cascade s 4 10 coeffs)
```

I should get a 10th order low-pass filter with fc=1412.54 Hz. But I don’t I only get something that looks about 4th order and the cutoff frequency is all wrong (presumably because the whole set of filters have not worked).

Compare the “plot spectrum…” frequency response of some white noise from the above to the result from the following

```
(biquad (biquad (biquad (biquad (biquad s 0.008428 0.016855 0.008428 1.000000 1.636525 -0.670236) 0.008566 0.017132 0.008566 1.000000 1.663372 -0.697635) 0.008842 0.017683 0.008842 1.000000 1.716946 -0.752313) 0.009252 0.018504 0.009252 1.000000 1.796591 -0.833599) 0.009786 0.019571 0.009786 1.000000 1.900213 -0.939355)
```

This second bit of code is what I am trying to achieve, and as far as I can tell my cascade filter should output exactly this. The coefficients are identical (and I know these coefficients are correct). But my cascade function only seems to spit out about half of the filtering it should… is this a syntax problem? a problem with recursion or am I doing something strange?

Any help would be appreciated.