A moving-average filter can address white noise in the time domain but performs poorly in the frequency domain.
In part 1 of this series, we defined convolution, denoted by the * symbol, and looked at a simple geometrical example of how it operates to produce a new function y(t) from two given functions, f(t) and g(t).
Q: What’s a practical application of convolution?
A: In electrical engineering, we often have an input signal f(t) that we want to apply to a filter with the impulse response g(t). We can calculate the filter’s output y(t) = f(t) * g(t).
Q: Can you provide a specific numerical example?
A: The moving-average filter is a commonly used form of convolution filter. It averages m data samples to create a new y(tn). For a 5-point moving-average filter:
Note that this equation represents the symmetrical form of a moving-average filter: to calculate y(tn), we average f(tn) with the two values to its left and the two values to its right. Alternatively, we can average f(tn) with the four preceding or following samples. Figure 1a shows how the symmetrical form works. The convolution engine calculates y(t6) as one-fifth of the sum of f(t4) through f(t8). When that calculation completes, the engine increments n, shifting one sample to the right, and calculates y(t7) as one-fifth of the sum of f(t5) through f(t9), as shown in Figure 1b. The process continues until the entire dataset has been processed.

Q: After the processing in Figure 1, what does the complete y(t) look like?
A: Figure 2a shows an unfiltered 4-Hz sawtooth wave (blue) and the output of our 5-point moving-average filter (red). The fall time of the filtered version is noticeably longer, as you would expect with a low-pass filter. If you look at the Fourier transform of the filtered signal (Figure 2b), you see that the higher frequency components are noticeably attenuated.

Q: Can I use the moving-average filter the same way I would a first-order low-pass analog filter?
A: No. The moving-average filter does not have the first-order analog filter’s smooth 20-dB per decade slope following a clean 3-dB cutoff frequency. One 15-point moving-average filter has the response shown in Figure 3. As you can see, this filter is not well-behaved in the frequency domain; the response periodically goes to zero and then rebounds.

Q: What is it good for?
A: Look at the black trace in Figure 4, representing a simulated signal with considerable Gaussian white noise. The signal appears periodic, but whether it’s a sine wave, a triangle wave, or something else is hard to tell. The moving-average filter is very effective at removing such noise. A 5-point (orange trace), 15-point (blue trace), and 21-point (red trace) moving-average filter provide successively better approximations of the original sine wave.

Q: What’s the overall conclusion here?
A: In general, if you can most easily express a problem in the frequency domain—that is, you want to remove specific frequencies, above a cutoff frequency or within a stopband, for example—the moving-average filter is a poor choice. But if you want to smooth a signal — for example, remove wideband noise — in the time domain, then the moving-average filter is a good, simple choice.
Q: What else should I know about convolution?
A: There are many different types of convolution filters. We’ll discuss some in upcoming parts of this series. For example, we have looked at 1-dimensional filters, but 2-dimensional convolution filters are particularly applicable to image processing.
References
Moving Average Filters, Analog Devices
Related EE World Online content
Subtleties of math functions in digital storage oscilloscopes
Single-sideband modulation and its measurement
The practical magical first-order analog filter: Part 1
Why does the Fourier transform provide apparently inaccurate results, and what can I do about it? part 2
Types of waves in an oscilloscope
Measuring the behavior of electronic filters
Leave a Reply
You must be logged in to post a comment.