Signal Processing ECET 350 Lab
iLab 3 of 7: Moving Average Digital Filters
This iLab uses MathML to make math formulas more readable. Learn more.
Submit your assignment to the Dropbox located on the silver tab at the top of this page.
(See the Syllabus section “Due Dates for Assignments & Exams” for due dates.)
Scenario and Summary
· Design, test, and implement antialiasing and anti-imaging filters to be used with a real-time, digital filtering system using a microcontroller, ADC, and DAC.
· Implement, test, and analyze the performance of a moving average, low-pass filter in conjunction with the filters and real-time system from the first objective.
· Tower system with ADC and DAC board
· Two-channel oscilloscope
· Function generator
· Three BNC to alligator adapters
· Lab3 MA FIR.zip, available in Doc Sharing
Appendix A has been provided in case supplemental information is required on how to set up and connect the Tower board and ADC and DAC data acquisition board for the two filter experiments in this lab.
Answer all questions, complete all tables, and paste all figures and graphs in the Week 3 iLab Cover Sheet here .
Submit your Week 3 iLab Cover Sheet report to the Dropbox for grading.
You can also download the iLab Cover Sheet for the Week 3 iLab in Doc Sharing.
Access the software at https://lab.devry.edu .
STEP 1: Introduction
Back to Top
Introduction to Moving Average Filters
Moving averages are the simplest of all nonrecursive or finite impulse response (FIR), low-pass filters. The term moving means that the average is taken over a moving or changing with time set of input samples. Also, in a moving average filter, the filter coefficients are all the same, meaning they are the reciprocal of the number of input terms to be averaged.
The difference equation for a FIR filter is y[n]=∑k=0Mbkx[n−k] .
For example, if a moving average of length 5 is to be performed, the difference equation summation may be expanded into the following form.
All the b k coefficients are equal to the reciprocal of the length, which in this case, is equal to one fifth, or 0.2.
As with all FIR filters, this also introduces the need for storing not only the current input sample but previous or delayed samples, as well. This is usually implemented in a buffer referred to as a circular buffer. The circular designation means that when a new sample input is available, the oldest sample in the buffer is always overwritten by the newest one.
Again, if the moving average filter length is 5, that means the average is taken of the latest five samples of the input signal. To illustrate this, suppose we have the following input sample sequence shown in Table 1.
Table 1: Input Sample Sequence
Assuming that all sampling and antialiasing filtering requirements have been met for the system and assuming that the sampling frequency equals F s , a new digital sample is provided as an input to the filter once every sampling period, which is the reciprocal of F s , which is 1/F s = T s , where T s is the sampling period. In addition, all input samples prior to the start of the filtering process have been set to a value of 0.
Table 2 shows the moving average filter inputs and the calculated results after each new sample is received. Please note that until the fifth sample is received, the input signal buffer is in what is called a boundary condition, meaning that not enough samples have been received to calculate an accurate average yet.
Table 2: Moving Average Samples and Filter Calculations
When sample 1 is received, it is stored in the x[n] element of the input buffer while the remaining elements still contain their initialized values of zero. When sample 2 is received, it is stored in the x[n-1] element. When sample 3 is received, it is stored in the x[n-2] element, and so on until the sixth sample is received. At this point, the buffer is completely filled with the five latest samples when the sixth arrives; the oldest sample in the buffer, which at this time is the x[n] sample, is overwritten with the newest sample.
When sample 7 is received, it is used to overwrite the next oldest sample, which is the x[n-1] element. This process continues with the newest sample overwriting the oldest until the filter is turned off. The calculated moving average value for each of the input sequences is shown in the last row of Table 2.
This simplified version works because all the filter coefficients in a moving average filter are the same. In most digital filters, the coefficients are not identical and a more sophisticated scheme is required to match the input sample sequence with the proper filter coefficient, but that will be covered in a later lecture and lab.
STEP 2: Moving Average Filter Frequency Response Characteristics
Back to Top
Moving average filters have a frequency response with two particular characteristics that may be easily calculated simply from knowing the sampling frequency and the number of terms in the moving average.
For a moving average filter of length M, two distinct points on the response curve may be calculated.
· The first zero gain (linear) frequency point occurs at 2π/M or F s /M, where F s is the sampling frequency of the system.
· The cutoff frequency, where the gain of the filter drops to 0.707 of its DC value occurs at π/M or 0.5F s /M, again where F s is the sampling frequency of the system.
Figure 1 shows the moving average filter frequency response for a 7-point filter. The horizontal axis is the normalized frequency with respect to the sampling frequency. For example, if F s = 1000 Hz, then the frequency at a particular point of the graph would be the x-axis value multiplied by F s .
For example, the first zero gain point can be calculated from the above definition to be
F s /M = 1000Hz/7 = 143 Hz
Examining the graph, you can see that the first zero gain point is at the normalized sampling frequency of approximately 0.292.
To see if our graph measurements are correct, multiply 0.292 times one half of the sampling frequency, Fs , to get
0.292 * 0.5 * Fs = 0.292 * 0.5 * 1000 = 146 Hz
This is a pretty close match, especially considering the accuracy of reading from a graph. The same process can be done to verify the 0.707 amplitude cutoff frequency point of the filter.
STEP 3: Input and Output Signal Conditioning Filters Lab Procedure
Back to Top
In the next section of the lab, you are going to implement a real-time, moving average filter and measure its frequency response, but first, both input antialiasing and output anti-imaging low-pass filters need to be designed, built, and tested to ensure proper operation of the moving average filter.
Please note that both the antialiasing and the anti-imaging filters will be used in all the remaining labs in this course. Construct and test them carefully and do NOT dismantle them after this lab is completed as you will need them for the rest of the session.
The real-time filter will be implemented on the Tower microcontroller system that you already have from the previous microcontroller classes and will include the use of the analog-to-digital (ADC) and digital-to-analog (DAC) converter module board that is part of the total Tower system. However, the ADC will require an antialiasing, low-pass filter to condition its input, and the DAC will require an anti-imaging, low-pass filter to condition its output.
As a result, you are to design and test two identical, active, second-order, Sallen-Key low-pass filters per the following schematic shown in Figure 2.
You may refer to iLab 2 as a reference because this design was simulated there. However, now you are to actually design, build, and test the filters. The antialiasing and the anti-imaging filters may be identical, so once you build and test one, you may duplicate your design for the second. An LM741 op amp is used in the above schematic, so if you choose to use a different op amp, please verify the pinouts and connections prior to building. Please create and include a schematic of the filter design with the lab materials if you’re using a different op amp than the LM741.
The sampling frequency of the software provided for this lab is set at 2.0 kHz. Therefore, the filter specifications for the filters are as follows.
Low-Pass Cutoff (-3 dB) Frequency: 1,000.0 Hz
Pass Band Gain: 1.0 or 0 dB (Unity Gain)
R1 and R2 values should be the same, and C1 and C2 values should be the same. Please note that there are numerous combinations of resistor and capacitor values that could provide the same cutoff frequency calculations, but try to keep the resistor values between 1.0k Ohms and 10.0k Ohms.
Calculate the design values of the resistors and capacitors and record all values in Table 1 in the Week 3 iLab cover report.
Because it is highly likely that you will not be able to find actual resistor and capacitor components that match your calculated values, try to find values as close as possible to the calculated values for use in your circuit construction, and record them in Table 1 in the iLab cover report. If you cannot find close enough values, you will need to redo the design calculations.
Calculate the -3dB frequency from the actual component values used for the circuit. Please keep in mind that all components have a tolerance factor and that your test measurements will reflect this.
Once the filters have been designed and constructed, you are to test and record the frequency response of the filters to ensure their proper operation using a signal generator, power supply, and oscilloscope. The initial settings of the signal generator should be the following.
Frequency = 200 Hz
Vin (p-p) (amplitude) = 2.0 Vpp = 1.414 Vrms,
DC offset = 1 volt
Connect the signal generator to the input of the low-pass filter, and measure the peak-to-peak voltage of the output using one channel of the oscilloscope. It is also highly recommended that you monitor the peak-to-peak voltage of the input signal with a second channel of the oscilloscope to verify both its frequency and amplitude.
Open a new Excel spreadsheet, and create a data entry table similar to what is shown in Table 1. Using frequency increments of 100 Hz, measure the low-pass filter output for each input frequency and record it in your spreadsheet and calculate the 20 log10 magnitude in the third column. Copy the information into the Week 3 iLab cover report.
Input Freq (Hz)
Filter Output Vout (p-p) (Vin = 2.0Vpp)
20 Log10 (Vout/Vin) (dB)
Table 1: Data Table for Second Order, Salley-Key, Low-Pass Filter
STEP 4: Analysis of the Low-Pass Filter
Back to Top
In Excel and using the measured filter response recorded data, create a graph showing all of the information similar to what is shown in Figure 3 below. Copy and paste your graph into the Week 3 iLab cover report. Please remember that graph, axes, and titles are part of the documentation and are part of the requirements to be met for grading.
Figure 3: Sample Low-Pass Filter dB/Linear Frequency Response Graph
STEP 5: Applied, Real-Time Moving Average Filters
Back to Top
In this portion of the lab, you will use the MA FIR CodeWarrior project for the Tower board and ADC and DAC board in order to implement and test a moving average filter of length 9.
First, you are to add your two, second-order, Sallen-Key, low-pass filters into your lab setup per Figure 4.
Figure 4: Anti-Aliasing and Anti-Imaging Filters in Moving Average Filter Setup” at the bottom center
Set up the analog-to-digital and digital-to-analog converter connections. You may refer to Appendix A for instructions on setting up the ADC to DAC board.
Channel 0 (LTC 1859)
Filter input from antialiasing filter
Channel A (LTC 2704)
Moving average filter output and input to anti-imaging filter
Channel B (LTC 2704)
Channel C (LTC 2704)
Channel D (LTC 2704)
Channel A (LTC 2600)
Set up the function generator to output a sine wave with the following settings.
Vin (p-p) Amplitude
Connect the output of the function generator into the oscilloscope, time domain, Channel 0, input, and verify the sine wave frequency and amplitude of the starting signal generator settings.
Make a second connection from the signal generator to the input of the antialiasing filter. Leave the oscilloscope connection so that the input signal may be monitored for consistency.
Connect the output of the antialiasing filter to Channel 0 of the LTC1859. Connect Channel A, the moving average filter output from the LTC 2704, to the input of the anti-imaging filter, and connect the output of the anti-imaging filter into the oscilloscope, time domain, Channel 1 input.
Download a copy of Lab3 MA FIR.zip from the course shell onto the desktop of your computer and unzip the project to the desktop. Double click on MA FIR.mcp to open the project with CodeWarrior, and then load it into the Tower system. Compile, load, and run the program on the Tower system before proceeding to the next step. This loads and runs the 9-point, moving average filter using the input ADC and output DAC channels that you have just connected.
With the moving average filter program running on the Tower system, verify that the output shown on Channel 1 of the oscilloscope is a sine wave and that the frequency is the same as the input signal from the signal generator.
Open a new Excel spreadsheet, and create a data entry table similar to what is shown in Table 2. Measure and record the filter output amplitude for the Vin = 2.0 Vpp at 10 Hz. Record this measurement as the 0 Hz measurement due to filter restraints.
Without changing any other settings, increase the frequency to 50 Hz, and record this measurement as the 50 Hz measurement.