Any slope filter

Discussion in 'Effects and the DSP' started by boris81, Jan 26, 2011.

  1. boris81

    boris81 New Member

    Joined:
    Dec 17, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Any slope filter can be realized by cascading a bunch of 1st and 2nd order filters and punching in the correct Q factor.

    For Butterworth:
    1st order -> 1st order real pole filter
    2nd order -> 2nd order with Q = 0.707
    3rd order -> 1st + 2nd with Q = 1.
    4th order -> 2nd with Q = 1.31 + 2nd with Q = 0.54
    and so on..
    A complete Q-factor look-up table for most common filters can be found at the end of this datasheet (p.56)

    http://focus.ti.com/lit/ml/sloa088/sloa088.pdf



    The KX package currently has just 2nd order filters which limits such implementations only to even order slopes. I have successfully implemented odd orders but I haven't compiled an Effects-Plugin yet.

    This screenshot shows how to realize a 6th order Butterworth slope (36dB/oct) with 3 cascaded EQ Lowpass plugins.

    6th order Butterworth is shown in green. 4th in red and 2nd in blue are there for reference.
     

    Attached Files:

  2. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    There is a formula by RBJ (of the Audio EQ Cookbook) in the MusicDSP mailing list for calculating the Q values for each biquad section (for Butterworth LP/HP):

    Q = 1 / ( 2*sin( (pi/N)*(n + 1/2) ) )
    where N is the filter order, n is the section number and 0 <= n < floor(N/2)

    It gives the same results as shown in that table (in reverse order).
     
  3. boris81

    boris81 New Member

    Joined:
    Dec 17, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Cool! I haven't seen this formula before.
     
  4. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    Hehe, actually I just noticed that the same formula is given in one of the links that you referenced (the thread at DSPRelated.com) in your other thread... :rofl:
     
  5. boris81

    boris81 New Member

    Joined:
    Dec 17, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    I compiled a 1st order LowPass and HighPass Plugin Effect. You can cascade this with the EQ Lowpass or EQ Highpass to get any odd order filter slopes. Follow the guide in the first post or to make sure you have the correct Q values.

    Get the Plugin from here:
    Download LP-HP-1st.kxl

    The screenshot shows the routing for 3rd order Butterworth Lowpass at 1kHz. The plots are 1st order Butterworth in blue, 2nd in red and 3rd in green.

    Here is the source code if someone wants to optimize it.
    http://www.datafilehost.com/download-ed8bd96e.html
     

    Attached Files:

    Last edited: Jan 26, 2011
  6. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    I do not have kX installed (or Windows for that matter) at the moment, so I cannot compile anything for kX or test anything out, etc.

    Looking at your source code, it seems that your microcode is using same biquad code, with a2 and b2 just set to 0.
    You can save some GPRs by using code specifically for 1st order filter.

    Maybe something like this:
    Code:
    ; Difference equation
    ; y[n] = b0*x[n] + b1*x[n-1] - a1*y[n-1]
    
    ; LP ( b1 = b0 )
    ; y[n] = b0*x[n] + b0*x[n-1] - a1*y[n-1]
    
    ; HP ( b1 = (-b0) )
    ; y[n] = b0*x[n] - b0*x[n-1] - a1*y[n-1]
    
    input in;
    output out;
    static x, b, a; ( x = previous input, b = b0, a = (-a1) )
    
    ; LP
    macs 0, 0, x, b;
    macmv x, in, a, out;
    macs out, accum, x, b;
    
    ; HP
    macsn 0, 0, x, b;
    macmv x, in, a, out;
    macs out, accum, x, b;
    
    The above does not include any scaling, but that can be added (if needed) with an additional macints instruction..
    I think the above should work, but again, I am not able to test (I threw it together quickly, and it is possible that I made a mistake).

    [edit: oops, I swapped b0 and b1 in HP: corrected]
     
    Last edited: Jan 27, 2011
  7. boris81

    boris81 New Member

    Joined:
    Dec 17, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    Awesome! Thanks, Russ!!

    I pretty much slapped the Demo and EQ Lowpass code together. I'm just happy it works at all. I will definitely try your optimization when I get a chance.
     
  8. Russ

    Russ Well-Known Member

    Joined:
    Jan 17, 2005
    Messages:
    5,722
    Likes Received:
    13
    Trophy Points:
    48
    BTW: I forgot to mention, you should also remove those presets since they are for the demo plugin. ...And congratulations on making your first plugin. :cool:
     
  9. boris81

    boris81 New Member

    Joined:
    Dec 17, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    It's a version 2 of this plugin with the optimization from Russ. This is compiled for KX-3550 x86.

    macs 0, 0, x, b1;
    macmv x, in, a, out;
    macs out, accum, x, b0;

    I'm using an extra register 'b1' to keep the Dane code the same for LP and HP. I don't plan on messing with this Plugin further unless there's a bug.
    Enjoy!


    If you are using the first version you might have to unregister it first. Instructions on how to do that are here:
    http://www.hardwareheaven.com/effects-dsp/206708-unregistering-dsp-plugins-i-made-how.html#post1393296


    The Plugin is here:
    Download LP-HP-1st.kxl

    And the source code:
    Download fx_LP-HP-1st.zip
     
  10. boris81

    boris81 New Member

    Joined:
    Dec 17, 2009
    Messages:
    17
    Likes Received:
    0
    Trophy Points:
    0
    I see the links are dead now so I will upload this Plug-in to the forum for safekeeping. You will need to delete the .TXT extension before using it.

    1st Order LowPass or HighPass filter
    View attachment LP-HP-1st.kxl.TXT

    I also made a 2nd order Allpass filter which might be useful to someone
    View attachment allpass.kxl.TXT

    Enjoy!!
     

Share This Page

visited