Introduction

Authors: Bjørnar Moe Remmen, Lloyd Clark, Phillip Olk, Microchip Technology Inc.

This application note implements four different filter algorithms on MCUs of the AVR® EA Family. The filters are based either on original code or libraries. Code examples are publicly available.

In the code examples, a set of static sample data is fed into the filters, and the performance is analyzed. The actual filter speed can be of secondary importance when the overall processing speed is limited by the duration of the data acquisition. On the other hand, effective filtering reduces the number of CPU cycles and hence, power consumption.

Median Filter

The median filter is based on comparisons, which do not require CPU-intensive operations such as multiplications or divisions. The center value of an odd number of samples is determined by a sequence of comparisons.

Median filters are excellent for removing spikes in signals like gaussian-, burst- or impulse noise.

Fourier Transform

The Fast Fourier Transform (FFT) is a method to decompose a signal into its frequency components, where each component has a frequency, an amplitude, and a phase.

The FFT creates a rather intensive CPU load, but it also produces a large set of information about the input signal. A single FFT operation can identify frequencies and amplitudes of peaks and hence help isolate/reject higher harmonics and side-bands and can be the core algorithm of a digital equalizer.

Infinite Impulse Response Filters

Infinite Impulse Response (IIR) filters are a class of filters that are feedback-based, i.e., the previous output plays a role in the current output. The implementation is simple but versatile: High and low-pass filters, notches and band-pass filters, even gain can be implemented with a rather small set of coefficients.

Due to the feedback principle, these filters lose the phase information and might be unstable - nonetheless, they are good for filtering sensor readings.

Kalman Filter

The Kalman filter is based on weighted averaging. The weight factors are determined by uncertainty calculations, where measurements with higher certainty are weighted heavier. From the weighted average, a prediction of the following measurement is created. The “correctness” of that prediction, i.e., how much the next measurement is off of the prediction, is used for weighting that measurement.

This filter is well-suited for noisy sensor data in systems with continuous, stepless behavior.