News:

  • November 27, 2026, 02:34:24 AM

Login with username, password and session length

Author Topic: Math in FILTERB  (Read 9575 times)

Controls Guy

  • Internal Dev
  • Hero Member
  • ****
  • Posts: 3628
  • Darth Ladder
Math in FILTERB
« on: September 05, 2014, 02:56:22 PM »
It just struck me the math in a FILTERB must be integer.  I'm using one to smooth a [usually] noisy analog input. Yesterday the input happened pretty stable, and I noticed that the filtered value asymptotically approached the unfiltered value, but stopped at (Filter Count / 2) counts away from the unfiltered value, the /2 due obviously to rounding.

This could be almost totally avoided by doing the math in floating point, but then you'd have to convert to real and then convert the result back to integer, which would make the instruction much slower, and is also unnecessary because in those cases where we need that, we can either decide to use those values as reals, or do the convert and convert-back explicitly in ladder.  It was just something interesting that I noticed and thought worthy of note for people applying FILTERB.  I never stopped to think about it.

I retract my earlier statement that half of all politicians are crooks.  Half of all politicians are NOT crooks.  There.

franji1

  • Bit Weenie
  • Host Moderator
  • Hero Member
  • *****
  • Posts: 3858
    • Host Engineering
Re: Math in FILTERB
« Reply #1 on: September 05, 2014, 03:16:10 PM »
It just struck me the math in a FILTERB must be integer.  I'm using one to smooth a [usually] noisy analog input. Yesterday the input happened pretty stable, and I noticed that the filtered value asymptotically approached the unfiltered value, but stopped at (Filter Count / 2) counts away from the unfiltered value, the /2 due obviously to rounding.

This could be almost totally avoided by doing the math in floating point, but then you'd have to convert to real and then convert the result back to integer, which would make the instruction much slower, and is also unnecessary because in those cases where we need that, we can either decide to use those values as reals, or do the convert and convert-back explicitly in ladder.  It was just something interesting that I noticed and thought worthy of note for people applying FILTERB.  I never stopped to think about it.

Your observation, analysis, and conclusions are just as we designed!  Other tidbits:
  • 05 does NOT support REAL, but does support FILTERB IBox, yet another reason for doing it all in integer math 
  • The algorithm for FILTER IBox (BCD version) is similar.