Go To:
Home Page
Lab 3

Lab 2: Analog Circuitry and FFT’s


For this lab, we divided our team into two subgroups. An Acoustic team and an Optical/Treasure team

Acoustic Subteam

For this section, we used the following materials:

Software:

Hardware:

We first installed the Open Music Labs FFT Library onto Trisha’s computer, as she was the one actually writing the code for this lab. You can download it here

We looked at the fft_adc_serial file example, which collects data from A0, performs the fft, and then prints to the serial monitor.

Yonghun setup the signal generator with a 660 Hz and 1 Vpp, .5 V offset signal. We decided we would rather use the signal generator at first so that we could be sure that the program was working as expected before we implemented the tone generator on a phone. We checked to make sure the signal generator was working on the oscilloscope.

PICTURE1 As shown in the screen capture above , the signal acted as expected.

PICTURE2. description: This was our circuit with the oscilloscope hooked up. We ran our output into the A0 analog input port on our Uno and fed the circuit 3.3 V.

After getting the Open Music FFT Library installed, we opened up the example fft_adc_serial and began to look through the code and test it out. We we checked the serial output to see what the program was reading we ran into an issue. The output was a bunch of random symbols and gibberish that meant nothing. We double checked the signal generator to make sure it was still working and it was.

We debugged the code and found that the serial monitor was running on a different frequency than our board, so we switched the baud frequencies to match. Then we started getting actual data.

Although we started getting data we didn’t actually see our 660 Hz peak anywhere. We realized that our scale was wrong so we recalculated it. We kept the prescaler at 0xe5, which was the 32 division factor. That means that the bin width is 150 Hz. 16 MHz / 32 division factor / 13 clock cycles = ~38 kHz. Divide this by the 256 samples, gives you 150 Hz/bin. Once updated in our data sheet it gave us the correct peak on our frequency graph.

FREQ RESP PICTURE: We placed all of the outputs into an excel table and used the bin width to graph this frequency response. The two points on the peak are 600 Hz and 750 Hz so our 660 Hz peak is shown.

PICTURE Once we got the code and excel working, we added the microphone into our circuit and began data collection using the oscilloscope to get a feel for the frequencies we heard.

PICTURE PICTURE Shown on the left is the tone generator we used. Shown on the right is the oscilloscope screen capture of the microphone hearing the 660 Hz tone. The oscilloscope was calibrated to 660 Hz so the spike in the middle of the screen represents the 660 Hz tone, the rest is noise.

We decided whether or not to use a an op amp as an active filter by taking data from close and far with the op amp and without it and compared. Our op amp has a 30 dB gain and the circuit is tuned for roughly 660 Hz.

Picture The blue data points are for the system with the op amp active filter and the grey is without it. As you can see the op amp got rid of some of the noise which would make it easier to locate the 660 Hz signal.

PICTURE PICTURE On the left is our completed circuit with the op amp attached. The right picture is a close up of our op amp

Optical/Treasure Subteam

For this section, we used the following materials:
Software:

Hardware:

Like the Acoustic subteam, we first started by downloading the Open Music FFT library and hooking up a basic circuit with a function generator in series with the 330Ω resistor to check the output of the fft_adc_serial example program. We checked the output when we drove the circuit with a sine wave at 7kHz, 12kHz, and 17kHz, 1Vpp and 2.5V offset. We originally tried driving with no DC offset on the function generator and could not distinguish any peaks. This was not an issue, however, when we added a DC offset nor was it an issue later when detecting IR treasures. We collected the data from the serial output and graphed the data in Google charts to get the following graph.

Picture 1

We used the same algorithm as the Acoustic Team for calculating a bin width of approximately 150Hz. With this in mind, we predicted and then verified from our data the bins for the different frequencies, as shown below:

TABLE By looking in these bins, we can clearly distinguish when we detect a treasure and which frequency by thresholding the values above a certain number we are unlikely to find noise, like 50 for example.

We then set up the IR circuit with the phototransistor (below) and tested its ability to detect the treasures at the same frequencies when placing the treasure board approximately 2 inches away. (See note at end on how to use treasures.)

PICTURE While the peaks are smaller than when produced with a function generator, we can still clearly see and distinguish between the different frequencies of the treasures.

We then wanted to test how the filter would function with outside interference, so we redid the same test with the IR sensor next to a window so that it would also be detecting sunlight.

PICTURE It appears as though there may be a little bit more noise in this scenario, but we still have a very good signal-to-noise-ratio (SNR) and the peaks for the necessary frequencies are still easily distinguishable. Our only concern is that the 7kHz signal seems to be producing a substantial peak at 17kHz as well, both in this case and the one without sunlight. Our code for distinguishing between the two frequencies will have to reflect this.

We also tried to implement an analog bandpass filter to see if we could cancel some of the noise at the lower and higher frequencies we don’t care about. For a 7kHz IR signal, we got the following results.

PICTURE Clearly, the filter not only filtered out high and low filters, but also filtered out the desired components as well. Interestingly, however, there is still a very strong DC component that we do not seem to be able to filter out.

Using Treasure:

The treasure looks like the following

Picture

To turn it on, switch the on/off switch. An LED will turn on to indicate that it is on. Turning the magnitude and frequency dials will change the magnitude and frequency of the IR signal. You can store up to two frequencies on the board and switch between them with the switch in the bottom right corner.

Picture

If there is no battery, connect the power pins to a voltage source at 3V. In order to determine the frequency of the output signal, connect the analog output pins to an oscilloscope. The orientation of the pins (flipping +/-) will look differently on the oscilloscope screen, but the frequency is the same for either. It will look like either of the two:

Picture :::: Picture

The three squares in the middle are the components responsible for sending out the IR signal, so be sure that the phototransistor can see them. We also found that the orientation of the phototransistor can determine whether or not it can detect a signal. Make sure the wider side of the phototransistor is parallel to the board in order to pick up data from the treasure.

Other Notes

About FFT Library:

After looking at the fft functions from the Open Music website (linked Here) we noted the following things:

There are two pre-processor functions that must run before running the main fft_run() function:

  1. fft_reorder()
  2. fft_window()

The main function, fft_run(), assumes that all the data it needs is stored in the array fft_input with the real part of the signal at even number values and the imaginary part at odd number values. For example,

The output of fft_run is placed in fft_input in the same organization. Therefore, for a 512 array, there are 256 data points.

About ADC:

After looking at the data sheet for the ATMega328 processor ((Available Here)
we noted the following things:

Common issues: (May want to start a debugging file where we can put a bunch of advice from all the labs/milestones)

Go To:
Home Page
Lab 3