Bi-quad problems?
  • I've been trying to figure out the bi-quad node by using the linked bi-quad cookbook numbers. The first problem I encountered is in the formula. The cookbook shows the normalized formula as:
    y[n] = b0*x[n] + b1*x[n-1] + b2*x[n-2] - a1*y[n-1] - a2*y[n-2] (assuming a0=1)
    but the formula listed for the module in the docs is:
    out[n] = a1 * in[n] + a2 * in[n-1] + a3 * in[n-2] - ( b1 * out[n-1] + b2 * out[n-2] )
    By comparison it would appear that:
    module cookbook
    a1 = b0
    a2 = b1
    a3 = b2
    b1 = a1
    b2 = a2

    Following the formula in the cookbook for a low-pass filter:

    w0 = 2*pi*f0/fs (were fs = sampling frequency f0 = cutoff frequency)
    alpha = sin(w0)/(2*Q)

    for the module
    a1 = (1 - cos(w0))/2
    a2 = 1 - cos(w0)
    a3 = (1 - cos(w0))/2
    b1 = -2*cos(w0)
    b2 = 1 - alpha

    I've built a filter to these specs and I get a white cable output. I'm not sure what I'm doing wrong. Any ideas?
    biquad.audulus
    54K
  • The resonance is causing the white out, but the filter is pretty wacky regardless, causing massive swings in amplitude.
  • OK, I turned the Q down to zero and the filter didn't white out, but it was still resonating. There's obviously still something wrong. It would be nice to get some confirmation from Taylor as to what he actually implemented. It would be nice to have it working since we don't have a second order bandpass filter node. In order to implement this you need z-2 so I don't think you could do it with a z-1 node.
  • @stschoen - Taylor says he thinks the z-1 doesn't stack, but do you have a good idea of how to test that? You might be able to combine them, but he's not sure.
  • I'm not really trying to stack the z-1 node. I figured that it almost certainly wouldn't work. I was just pointing out that the bi-quad algorithm use z-2 so that it would be hard to duplicate using the z-1 node. I would appreciate it if you would show my post to Taylor and get his comments. I've double checked my work and I can't find any error, but the bi-quad node doesn't seem to be working as I would expect. It would be a nice add to the filter arsenal as it should be possible to create a set of efficient filters.
  • @stschoen- Have you tried the filters from this thread?

    http://forum.audulus.com/discussion/874/another-set-of-biquad-filters#Item_10

    I've just checked very quickly and they seem to work.
  • Thanks @SansNom, these are exactly what I had in mind. Now I can work out where I went wrong.
  • Thanks again @SansNom. I located my problem thanks to your modules. I forgot to divide the terms of the equation by the a0 coefficient. I should have checked the forum more closely, seems I was re-inventing the wheel. Interesting comment from Taylor in one of the other threads that the built-in filter node is a bi-quad, optimized by not re-evaluating the co-efficients at the sample rate. I thought that might be the case. It would be nice to have the other variants (HP, BP etc) as built-ins.
  • @stschoen - I agree! You can create a HP filter from the LP filter for now if that suits you:

    Signal->LPF+(-Signal) I believe is how it's done. The Q control might act strangely perhaps...I think @afta8 came up with this ages ago.
  • BTW I tested it and the z-1 node does not chain. I figured that would be the case, but I thought I'd make sure.