Faster way to median filter 3 values in PASM?
Hi, All.
I'm thinking of adding a simple median-of-3 filter to EasyADC to get rid of some noise spikes. What I have so far sums the 3 values, and tracks the max and min values, as the median would be sum - max - min. I would appreciate it if anyone has a faster way, as I'm trying to keep the sampling speed up.
Here's the code to date:
Jonathan
I'm thinking of adding a simple median-of-3 filter to EasyADC to get rid of some noise spikes. What I have so far sums the 3 values, and tracks the max and min values, as the median would be sum - max - min. I would appreciate it if anyone has a faster way, as I'm trying to keep the sampling speed up.
Here's the code to date:
' median filter
mov filter_max, A
max filter_max, oldA1
max filter_max, oldA2
mov filter_min, A
min filter_min, oldA1
min filter_min, oldA2
mov medA, A
add medA, oldA1
add medA, oldA2
sub medA, filter_max
sub medA, filter_min
mov oldA2, oldA1
mov oldA1, A
mov A, medA
Thanks,Jonathan

Comments
mov temp0, A mov temp1, oldA1 max temp0, oldA1 max temp1, oldA2 max oldA2, A min temp0, oldA2 min temp0, temp1 mov oldA2, oldA1 mov oldA1, A mov A, temp0Thanks!
Jonathan
mov medA, A cmp maxA, A wc, wz if_b mov medA, maxA if_b mov maxA, A if_ae cmp minA, A wc, wz if_a mov medA, minA if_a mov minA, A mov A, medA@ Dave: You are the man! Thanks for the explanation!
Jonathan
P.S. To make this a real challenge, might be nice to have a 5-point median filter as well....just saying [8^)
' Store the original value of A mov filter0, A ' Get the minimum of each of the 3 possible pairs ( A & oldA1, A & oldA2, oldA1 & oldA2 ) mov filter1, oldA2 max oldA2, A ' this modifies oldA2, but it will be overwritten soon anyway max filter1, oldA1 max A, oldA1 ' A is modified (will be the median filtered value) ' find the maximum of those 3 minima min A, oldA2 min A, filter1 ' update my tracking variables mov oldA2, oldA1 mov oldA1, filter0Anyone see a way to minimize this further?Jonathan