Hello PIC.ers,
Sorry if this post is a little long, but it seems there's enough interest.
..
{Quote hidden}>Date: Wed, 7 Oct 1998 15:32:58 -0400
>From: Bob Shaver <
.....bobsKILLspam
.....PMDINC.COM>
>Subject: Median Filter Code
>On Friday, October 02, 1998 7:50 AM, Lawrence Lile
>[SMTP:
EraseMElilelspam_OUT
TakeThisOuTTOASTMASTER.COM] wrote:
>> I've loaded a nice median routine on my web page cited below - take a
>> look at it.
>>
>> -- Lawrence Lile
>Lawrence,
>I looked at your median filter code (a very quick look, only a couple of
>minutes) and was wondering how you handle inputting data samples once you
>fill up the filter array. The current code simply overwrites the 1st
>element (i.e. the highest sorted value) with the new data. I believe the
>program needs to keep an un-sorted array that acts as a FIFO (first-in
>first-out) for storing the 16 most-recent data samples. Then sort this
>data into another array to pick the median value.
>Am I missing something in your existing code?
>Bob Shaver
>Practical Micro Design, Inc.
..
Bob's point here was taken up by me @~11pm last night.
i.e. how does Lawrence's code handle the following situation? :-
The filter is trying to track a moving signal, say one which is on a
positive ramp (+dS/dt, for purists), and is already quite clean and
free from jitter.
..
Raw values read in, go only to the upper end of the range,
while the output of the filter keeps returning the median value...
but... the median doesn't change at all, even tho' the signal can be running awa
y.
As it stands, this filter will *depend* on having a guaranteed amount
of noise fed into it.
..
So far, having searched my archives, I've found Andy Warren's post
from 9 Feb 1998 to be a very neat implementation of the same function
- it's good for an array up to 5 or so values- I think it would get
unwieldy at the 15 that Lawrence tackles.
Still, Andy's doesn't address the *stuck median* issue above,
<I can re-post his solution here, but I think I ought to let him do that>
..
Given an n-word array, I think the problem disappears if the new input
value is written over the previously-found output median, in the middle of the
n-word range
Then re-sort, pick the next median, etc., etc.
Would this cover all bases?
..
FWIW. I've modified these codes to accept a 16 bit x 5 word array,
for my own purposes.
So far it's not tested against real, living h/w but if anyone's interested,
mail me separately.
Best regards, John
..
email from John Sanderson at
JS Controls, PO Box 1887, Boksburg 1460, Rep. South Africa
Manufacturer & purveyor of laboratory force testing apparatus
and related products and services.
Tel/fax: Johannesburg 893 4154 Cellphone 082 453 4815