Introduction Moving Average Filters FIR Filters Code and data IIR Filters Transfer Functions

An introductory digital filter

We'll open MicroModeler DSP and select a digital filter from the toolbar at the top and drag it to our application. We'll choose a moving average filter because it's one of the simplest types of filters. After you drop the filter, the displays will be updated automatically. (Click to launch MicroModeler DSP in a new window)

Drag a Moving Average filter to your project. View the frequency response. Adjust the filter length

We all know what an average is - add the numbers together and divide by how many there are. A moving average filter does just that. It stores a history of the last 'N' numbers and outputs their average. Every time a new number comes in, the average is effectively recalculated from the stored samples and a new number is output.

The frequency response of a filter

At the top-right, we see the graph of Magnitude vs Frequency, or how much different frequencies will be amplified or reduced by the moving average filter. As you might expect, averaging the last N samples will apply some type of smoothing to the signal, retaining the low frequencies and removing the high frequencies.

The moving average filter will retain low frequencies and attenuate high frequencies

We can control the number of previous inputs, or samples that it averages by adjusting the filter length, N. By adjusting this, we can see that we have some basic control over which frequencies can pass and which are discarded.

Adjust the filters length
Effect of filter length on frequency response

The inside of a filter

If we look at the structure view, we can see what the inside of a moving average filter might look like. The diagram has been annotated to show what the different symbols mean.

The structure of a moving average filter, implemented using Unit Delay, add and multiply operations

The Z-1 symbols mean delay by one time sample and the + symbols mean add, or combine the signals. The arrows mean multiply (think amplify, reduce or scale) the signal by the amount shown to the right of the arrow.

For an average of 5 samples, we take one fifth (0.2) of the most recent sample, one fifth of the second most recent sample and so on.

The chain of delays is called a delay line with the input signal being delayed by one additional time step as you proceed along the delay line.

The arrows are also called taps, so you could almost imagine them as being taps like the one in your kitchen sink that are all one fifth open. You could imagine the signal flowing in from the left and being progressively delayed as it moves along the delay line, then recombined in different strengths through the taps to form the output.

It should also be easy to see that the output of the filter will be:

Output = 0.2 x Input[t] + 0.2 x Input[t-1] + 0.2 x Input[t-2] + 0.2 x Input[t-3] + 0.2 x Input[t-4]

Which is the equivalent to the average of the last 5 samples. (Input[t-N] means the delayed input from time t-N)

In practice the code generated by MicroModeler DSP will use tricks to do this more efficiently, so that only first and last samples need to be involved, but the diagram is good for illustrative purposes.

If you can understand this then you can get an idea what an FIR filter is. An FIR filter is identical to the moving average filter but instead of all the tap strengths being the same, they can be different.

An FIR filter is similar to a Moving Average filter. The only difference is in the tap strengths

Here we have a moving average filter and an FIR filter. You can see that they are structurally the same, the only difference being the strengths of the taps.

The next section will introduce you to Finite Impulse Response (FIR) filters. By varying the tap strengths, we can create close to any frequency response that we want.

Introduction Moving Average Filters FIR Filters Code and data IIR Filters Transfer Functions