Searching \ for 'Noise filter, averaging' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/logic/dsps.htm?key=filter
Search entire site for: 'Noise filter, averaging'.

Truncated match.
PICList Thread
'Noise filter, averaging'
1998\02\09@095031 by lilel

flavicon
face
John,
Instead of replying offline I decided to reply to the PICLIST because
this is getting interesting.


> .. From this recent post of yours, it looks like you have a
> `ready-made' routine for a median filter.  Are you able to help?

Yes I do.  The key to this is to be able to sort data, and I was
stumped until Bob Fehrenbach posted this routine.  (Thanks, Bob.)

You might designate, say, 5 or 10 locations for your (tiny little)
array of data.  Set up a loop to read analog values into your data
array one at a time.   Use the FSR to index each element of your
array.

You can sort the array two different ways.  You can sort numbers into
the array as they are read, so the zero values you started with
(don't forget to clear them next time) get kicked out the bottom of
the stack as new data is brought in.

Or you can wait till you have ten unsorted numbers, then sort them
all.  You have to sort the entire stack by pairs ten times to insure
that the lowest number really ends up on the end of a ten-member
array.  This seems less time efficient than the other method.


The following snippet of code is the key to this, an algorithm that
sorts a pair of numbers.   To use it, set FSR  register to the first
location in a small bank of RAM.  It decides whether the location
referenced by FSR is greater or less than the next location, FSR+1,
and swaps them if not.  It cleans house by leaving FSR at the same
place it started.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;  ORDER   sorts a pair of numbers indexed by FSR and FSR+1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ORDER   ; SUBROUTINE


MOVF   INDF, W ; RECALL X
INCF   FSR, F  ; SET UP TO RECALL Y
SUBWF  INDF, W ; Y >= X?
BTFSC STATUS, C    ; Y<X C=0, NO SKIP
     ; Y >=X C=1 SKIP
GOTO NOSWAP
SUBWF  INDF, F  ; Y=Y-(Y-X) = X
DECF   FSR, F   ; SET UP TO RECALL X
ADDWF  INDF, F  ; X=X+(Y-X) = Y
RETLW 0
NOSWAP
DECF FSR, F
RETLW 0

Best Regards,

Lawrence Lile

1998\02\09@142429 by Andrew Warren

face
flavicon
face
Lawrence Lile <spam_OUTlilelTakeThisOuTspamtoastmaster.com> wrote:

> Yes I do [have a median-filter routine].  The key to this is to be
> able to sort data, and I was stumped until Bob Fehrenbach posted
> this routine.  (Thanks, Bob.)
>
> You might designate, say, 5 or 10 locations for your (tiny little)
> array of data.

   Lawrence:

   "5 or 11 locations" would be better... It's easiest to pick the
   median value when your array has an odd number of elements.

> You can sort the array two different ways.  You can sort numbers
> into the array as they are read
> ....
> Or you can wait till you have ten unsorted numbers, then sort them
> all .... This seems less time efficient than the other method.

   Correct; INSERTING a value into an already-sorted partial
   list can be done much more quickly than sorting a list.

{Quote hidden}

   Personally, I'd leave out the "house-cleaning" step at the end,
   since a bubble-sort will generally want to call the subroutine
   repeatedly, incrementing the FSR by one at each call.

   And actually... If the array were small, I probably wouldn't use
   the FSR at all; it's much faster to use a macro like the
   following, which I first posted to the list two years ago:

       ; THIS MACRO COMPARES THE VALUES IN REGISTERS X AND Y.
       ; IF Y < X, IT SWAPS THEM.

       ORDER   MACRO   X,Y

           MOVF    X,W             ;GRAB X.
           SUBWF   Y,W             ;Y >= X?
           BC      $+3             ;IF SO, JUMP AHEAD.
           ADDWF   X               ;OTHERWISE, X = X + (Y-X) = Y,
           SUBWF   Y               ;       AND Y = Y - (Y-X) = X.

           ENDM

   For a 5-element array, the "sort" subroutine would occupy 28
   words of program space and would look like this:

       ; SORT REG1-REG5 IN ASCENDING ORDER.

       SORTSUB:

               CALL    SORT4
               CALL    SORT3
               CALL    SORT2

       SORT1:  ORDER   REG1,REG2
       SORT2:  ORDER   REG2,REG3
       SORT3:  ORDER   REG3,REG4
       SORT4:  ORDER   REG4,REG5

               RETURN

   -Andy

=== Andrew Warren - .....fastfwdKILLspamspam@spam@ix.netcom.com
=== Fast Forward Engineering - Vista, California
=== http://www.geocities.com/SiliconValley/2499

More... (looser matching)
- Last day of these posts
- In 1998 , 1999 only
- Today
- New search...