Connect with us

fixed point digital low pass filters

Discussion in 'Electronic Design' started by Jamie Morken, Jan 6, 2008.

Scroll to continue with content
  1. Jamie Morken

    Jamie Morken Guest


    I used this digital filter design tool:

    to generate code for a first order Butterworth floating point
    low pass filter with 250kHz sampling frequency, and a 100kHz
    corner frequency.

    This would require a DSP to run on, since I need 6 of these
    filters running in parallel, so is there a way to do the same
    filtering with fixed point code to run on a microcontroller?
    The input values to the filters are fixed point 16bit ADC values.

    Can I convert the floating point code to fixed point?

    Here's the floating point code that mkfilter generates:

    //filter code
    #define NZEROS 1
    #define NPOLES 1
    #define GAIN 1.324919696e+00

    static float xv[NZEROS+1], yv[NPOLES+1];

    static void filterloop()
    { for (;;)
    { xv[0] = xv[1];
    xv[1] = next input value / GAIN;
    yv[0] = yv[1];
    yv[1] = (xv[0] + xv[1])
    + ( -0.5095254495 * yv[0]);
    next output value = yv[1];
    //end of filter code

  2. The first order filter is just the first order filter. It can't be worth
    butter or anything.
    Probably even MSP430 or 68HCS12 could be sufficient.
    The real question is what are you trying to accomplish by this filtering. A
    first order corner at 100kHz at a sample rate of 250kHz doesn't seem to make
    much sense.
    It is certainly possible, however I don't know if you can :)

    What a horrid code.

  3. Tim Wescott

    Tim Wescott Guest

    IIRC both of these processors top out at about 40MHz clock speed. So
    you're saying he can run six second-order, 32-bit precision filters in
    160 clock ticks on a 16-bit processor?

    One can make this conversion with proper guidance; I don't know if anyone
    could with Vladimir as his only source of information.
    And thank you for increasing world knowledge by saying why.

    Tim Wescott
    Control systems and communications consulting

    Need to learn how to apply control theory in your embedded system?
    "Applied Control Theory for Embedded Systems" by Tim Wescott
  4. Tim Wescott

    Tim Wescott Guest

    I find it odd that your corner frequency is only 80% of your Nyquist
    rate. You really aren't going to be achieving much by filtering this

    Perhaps you should go over exactly what you're planning to achieve, and
    with what data.
    This is going to consume a lot of clock ticks on either a microprocessor
    or a DSP chip. Expect to need to use 32-bit arithmetic (or 24, if you
    like old Motorola DSP chips). Plan on benchmarking this, and don't
    expect to do it on a cruddy old PIC.
    Yes you can. Search around on the web, see if you can find an article
    about fixed-point or fractional arithmetic. All the processors that I've
    used support some sort of fractional arithmetic, at least indirectly --
    DSP chips support it directly, and 'regular' processors support it by
    coughing up both (or selectable) parts of the double-precision result you
    get when multiplying two single-precision numbers (I.e. if the processor
    is a 16-bit one, an integer multiply will either fill two registers with
    the high and low parts, or there will be two integer multiplies, one for
    each part).

    Otherwise Really Fast Processors can take multiple clock ticks to do
    multiplication (never mind divide), so remember to benchmark or count
    clock ticks when you investigate doing this in fractional arithmetic.
    This is _not_ the best code, although I presume it works. Here again,
    you could do well to search the web for IIR filter information. I'd
    suggest you think about getting a copy of "Understanding Digital Signal
    Processing" by Rick Lyons as well -- there's a whole chapter on choosing
    which IIR filter is the right one in what circumstance.

    Tim Wescott
    Control systems and communications consulting

    Need to learn how to apply control theory in your embedded system?
    "Applied Control Theory for Embedded Systems" by Tim Wescott
  5. Where did the second order and 32 bit precision come from?
    What I said that it could be possible to fit six first order filters @ 16
    bits @ 250kHz into HCS12 or MSP430.
    "If you give me $1000, I will do it much better and more efficiently" (tm)
    Wasn't that an exact answer to the question asked?
    I certainly kneel before the prophets who can preach about 2 x 2 = 4, and
    who can say a lot without telling anything.

Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day