MATLAB Programming/Advanced Topics/Applications and Examples/Filtering

Filtering is a broad subject. For the MATlab wiki I will focus on how to implement filters. For more on the theory of filtering the reader should reference the Digital Signal Processing wiki book.

The Moving Average Filter
Formula:

$$y[n] = \frac{1}{h} \sum_{p=0}^{h-1} x[n-p] $$

MATLAB implementation(All the code here was intended to be put in an M-file): The moving average filter is simple and effective. One of the things that is a problem is the lag associated with the moving average filter. The more samples used the longer the lag experienced(All filters have lag). How much lag can be tolerated is up to the individual.

The Kalman Filter
The Kalman filter is a recursive method of combining two estimates to determine the truth. A few parameters that are widely used are the initial conditions or current value and measured data.

Equation:

Example: All this code does is take a constant value R and adds noise to it. Then it filters the new signal in an effort to separate the noise from the original signal.