# Lab 8 – Frequency Response with MATLAB

```Copyright 2003 – Oregon State University
1 of 4
Lab 8 – Frequency Response with MATLAB
Idea
In this lab, using two AVR boards, you will create a network analyzer. This
analyzer will be used to plot the amplitude versus frequency response of an LC network.
Objectives
•
•
•
•
Learn how to interface C board to MATLAB via the serial port.
Learn how to use the A/D converter on the AVR Board.
Learn to synchronize two AVR boards.
Learn to drive a speaker with a sine wave.
Procedure
Disclaimer
1.
Before you start, read the lab carefully. This is a two person lab. Find
someone to work with and share ideas with. You will need two functioning
boards to successfully complete this lab.
2.
You will write software which will automatically adjust the gain of the rx
board as it interprets the signal received. You will run this software on your
board and produce results in MATLAB.
3.
You will then modify the circuit attached to the drain of your microphone.
4.
You will then run the software again and compare the difference between the
software runs.
Writing and Running the Software the First Time
1.
For the tx board, write a program which will sweep the audible frequency
range with the speaker being driven by either PWM or a square wave. For
example you can choose to increment from 500 Hz to 13 KHz in set increments
(~50Hz). The frequency being produced can be displayed on the LCD screen for
troubleshooting purposes. The tx board will increment frequencies when it
receives a signal from the rx board telling it to do so.
2.
For the rx board, write a program which will listen to the frequencies being
produced by the tx board. The rx board will here a particular frequency being
produced and ratchet its microphone gain until it is at a value of 2.0 Volts. The rx
and tx board should perform this step until the desired value of 2.0 Volts is
reached. Once the value has been obtained for that particular frequency, the rx
board will send an “increment bit” to the tx board via IR to tell the tx board to
increment to the next frequency. If, for example, the range of 500 Hz to 13 KHz
is used with frequency increments of 50 Hz that would be
(13KHz − 500 Hz )
= 250 total readings that need to be made. Once/as the data is
50 Hz
ECE 473 – Lab 8 – Frequency Response with MATLAB
Copyright 2003 – Oregon State University
2 of 4
received, the rx board will need to transmit the information to a computer via the
DB9 serial port on the AVR board. The frequency being received and/or the
amplitude can be displayed on the LCD screen for troubleshooting purposes. You
should keep track of the adjustments made because they will be needed in the
second part of this lab.
3.
Once the data is at the computer, you should use MATLAB to display the
frequency response of your circuit (e.g. frequency v. amplitude). MATLAB's
serial interface works as follows: After the channel to the port has been opened,
you can freely write to the port any number of bytes. Any data coming in through
the serial channel is automatically stored in a buffer. You can read from this
buffer at any time as long as it is not empty. Even though the buffer holds more
than 512 bytes you can only read a maximum of 512 bytes from the buffer at a
time. The variable s.BytesAvailable holds the number of bytes that can be read
from the buffer. If there is more than 512 bytes in the buffer s.BytesAvailable
will only show 512. After the serial channel is open you need to write at least one
byte to the port before reading from it. Useful MATLAB code is included on the
website for this lab. You are welcome to use this or try to write your own.
4.
Demonstrate the working program to the TA. Do not forget to print out your
plot(s).
5.
Save.
1.
The 5.1K network that comes off the positive lead of the microphone, on the
rx board, (currently comprised of a 5.1k resistor, a 1k resistor and a 10 F
capacitor) is to be replaced. This will be replaced with the hardware described in
the schematic shown in Figure 1. The specific function of this new LC network is
something you will discuss in the post lab. Replacing this hardware will require
reorienting the 5.1k resistor and the 10 F capacitor. The network is being placed
here because the positive lead of the microphone is the drain off of the FET
contained within the microphone package.
2.
Replace the old network with the new LC network as delineated in the
schematic shown in Figure 1
Running the Software the Second Time
1.
The hard stuff should now be done. You now need to run a program similar
to the one that you have previously written for the new LC network. The program
should make the same adjustments to the gain as it did to produce the flat
response for the old network. The program should not be the same program
insofar as ratcheting the gain for the new LC network to 2.0 volts for the
various frequencies. The program should make the same adjustments for the
new LC network as it did for the old. For example, if for 1.65KHz on the old
ECE 473 – Lab 8 – Frequency Response with MATLAB
Copyright 2003 – Oregon State University
3 of 4
program you had to ratchet the gain ‘twenty-three units’ to get the amplitude
to read 2.0 Volts, then when the new LC network is hearing 1.65KHz, you
again ratchet the gain ‘twenty-three units’ no matter what the amplitude
same amplitude. If this does not make sense, consult your TA.
2.
Plot the information again in MATLAB. Then, plot the difference between
this new plot and the flat-line plot from the first part of the lab, you should see the
frequency response to the new LC circuit.
3.
Demonstrate the working program to the TA along with the frequency
response to the new LC network. Do not forget to print out your plot(s).
4.
Save.
Schematics
Figure 1: Old and New Networks for Lab 8
Help
You may need to consult the class on this one. If you have questions, send out
emails; send them to the class, the TAs and Roger Traylor. You may want to consult
midterm question four for some advice.
Post Lab
This post lab will be different than previous post labs; it will not be submitted via
email. The post lab should include the following:
•
A brief description of this lab.
•
o What is the frequency response of the new LC network?
ECE 473 – Lab 8 – Frequency Response with MATLAB
Copyright 2003 – Oregon State University
•
•
•
•
•
•
•
4 of 4
o Why do you need to write at least one byte to the port before reading from
it, after the serial channel is opened?
o Based on the plots, what can be said about the speaker used?
Printout of the frequency response for the broadband circuit with the