1) Constant step in direction of input

if (input > cur_value) { cur_value += STEP; }

else { cur_value -= STEP; }

There is literature showing steady-state error (quite small).

You can trade convergence time with error through STEP size.

2) Constant step in log domain (positive inputs)

if (input > cur_value) { cur_value *= STEP }

else { cur_value *= INV_STEP }

where INV_STEP = 1/STEP

I haven’t seen an error analysis, but I suspect error is similar with faster convergence. With STEP of 1.01 you should expect a few % steady-state error depending on your input distribution, and <200 iterations for convergence if your initial guess (I use the 3-median of first values) is within an order of magnitude of steady state value. Results very roughly equivalent to a window size of 1/(STEP-1), so 100 in the example.

So small error, very fast and small code. Generalization for all reals left as an exercise for the reader! (tip: use the complex domain; ask if help needed)

]]>If possible, please tell me how to use this median filter (size >3) for multiple ADC. Will your median filter allocate different buffers for different ADC inputs?

Thanks,

Changhe Huang

]]>2) All median filters exhibit a delay of (FILTER_SIZE / 2 + 1) samples before they respond to a step change. When they do respond however, the output is also a step change. By contrast a classic LTI will slew to the stepped value at a rate governed by the time constant of the filter.

3) For a discussion on sorting algorithms, please see https://embeddedgurus.com/stack-overflow/2009/03/sorting-in-embedded-systems/ ]]>

I am not sure if replies to this post are still entertained. Anyhow, to me this is amazing! I have always used linear filters for all of my data acquisition type of applications…. About a decade ago, I came up against a problem, where I had a hunch a median filter would do the job. However, it remained only an idea since I did not know how to implement it and in the end, I simply used a heftier filter to remove the “burst” noise. However I have two questions for you…. I hope you would not mind answering even this late.

Q1. How does one pass the elements to the median filter? Does one pass 3 or 5 elements at a time? since my input is a circular buffer of say size 32 points, Do I perform the algorithm on a set of 3 / 5 elements at a time?

Q2. What happens when there is a step input ? Initially the median filter would discard the step value. How does the filter reach the final step value. Say from {3,4,4,6,3,5,5,3} the values go to {13,11,9,9,10,11,9,10}

I briefly worked with a quick sort algorithm and wonder if it would be a good fit here instead of the other sorting algorithms? What do you think?

Thanks for touching upon this oft neglected topic, for your thoughts and for the efforts of putting the code examples.

regards

Anand Phadnis

When I reach this level, I stop. ]]>

http://www.embedded.com/design/programming-languages-and-tools/4399504/Better-Than-Average ]]>

As always in this field, there is no single “right” answer. It would be boring if there were!

]]>