Problem with Tracy Allen digital low pass filter?


Closed Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2006
    Posts
    7

    Default Problem with Tracy Allen digital low pass filter?

    I would like to do an RC digital low pass filter on some 16 bit adc data with an RC time constant of about 1000 samples.

    Guru Tracy Allen seems to have some code for just such a filter:

    ---- from http://www.emesystems.com/BS2math5.htm

    Here is a filter that works for larger numbers, such as barometer data that has to be filtered for altimetry. This filter uses a double precision accumulator, it too converges well without numerical problems. This can be used for small numbers too.

    example with time constant kR=8:
    Y0 = X0*65536 initial accumulator =216* initial datum
    Yn = Yn-1 * 7/8 + Xn*65536/8 iteration adds new value to accumulator
    Zn = Yn/65536 filter output ' Double precision filter for input numbers up to 65535
    kR con 3 ' the filter time constant is 23=8, done a shift right kR
    kL con 16-kR ' for the computation shift lefts
    X var word ' current value, filter input
    Y0 var word ' smoothed value, accumulator low word
    Y1 var word ' smoothed value, accumulator high word
    Z var word ' scratch variable for calculations
    ' also final filter output
    inititalize:
    gosub getX ' get current value, not shown
    Y1=X 'initialize, note effective multipication *65536
    loop:
    gosub getX ' get current value, not shown
    Z=(Y0>>kR)|(Y1<<kL) ' form low word of accumulator, divided by (2^kR).
    Y0=Y0-Z ' subtract it from low word of accumulator
    ' next do the same for high word, minus borrow from low word
    Y1=Y1-(Y1>>kR)+(Y0 max -Z +Z max 1 -1)
    Z=X<<kL ' form input data times divided by (2^kR), part to low word
    Y0= Y0 + Z ' add it to low word of the accumulator
    Y1= Y1+(X>>kR)+(Y0 max Z -Z max 1) ' do the same for the high word, plus carry
    Z = Y1 + (X0 max 1) ' filter output, high word of accumulator with adjustment.
    debug dec X, tab, dec Z, CR ' show the raw value and the filtered value
    goto loop

    ------------ end of http://www.emesystems.com/BS2math5.htm code

    However, when I try to compile this code, there is an undefined variable X0 in the next to last
    line. It seems like the "adjustment" this line refers to is rounding, but I am having trouble
    understanding all the neat tricks in this code.

    I have not been able to contact Tracy

    Has anyone else ever got this code working?

    TIA

    Dave

  2. #2
    Join Date
    Sep 2006
    Posts
    7


    Did you find this post helpful? Yes | No

    Default Re: Problem with Tracy Allen digital low pass filter?

    It figures, as soon as I posted my question, I heard back from Tracy:

    Hi Dave,

    That is as puzzling to me too! My first reaction is that it should say
    Z = Y1 + (Y0.bit15)
    the purpose being to round off the value to output. That should be done based on the
    high bit of the low word of the accumulation. It is not usually going to be
    important to round it off. With Z = Y1, it is always rounding down.

    -- best regards,
    Tracy

Similar Threads

  1. Low pass filter help - pure sine wave inverter
    By George in forum Off Topic
    Replies: 1
    Last Post: - 9th April 2011, 05:24
  2. 2nd order Low-pass passive RC filter on PWM
    By munromh in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th January 2009, 19:03
  3. Atod Digital Filter
    By GeoJoe in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd April 2008, 17:04
  4. 2nd Order Digital Filter for 24-bit
    By sefayil in forum mel PIC BASIC
    Replies: 0
    Last Post: - 2nd December 2005, 21:55
  5. digital filter
    By yasser hassani in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th September 2004, 01:28

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts