Lab 2 (FFT)
During this lab we worked on designing two circuits and writing the signal processing code needed to detect and make sense of acoustic and IR signals. One circuit involved a microphone that would be used to detect a 950 Hz signal, which is necessary because this will signify to the robot to start moving. The other circuit will be used to detect other robots in the maze, which will be emitting IR signals.
Tone Detection
Designing the Microphone Circuit
First we built the microphone circuit as shown in the handout, using the 1 uF capacitor and 3 kOhm resistor. We connected the output to the oscilloscope, and used a tone generator to generate a 950 Hz acoustic signal as input for the microphone. However, we did not see any noticeable signals on the function generator output using the waveform data and the FFT math function. We then decided that we would build an amplifier using an op-amp to amplify the signal. We decided to use an LM358 because it is compatible with using ground as the negative voltage rail, which is necessary for our arduino. We built an inverting amplifier with a gain of -100 and a DC bias of +2.5V in order to avoid clipping. Then we excited the circuit with sinusoidal signals of various frequencies with the function generator and found that the implementation did indeed amplify the signal. We then tested out the circuit with the microphone and found that now we could see an output signal and FFT peaks at the relevant frequency. We then decided to add a high pass filter with a low frequency cutoff of 795 Hz to filter out noise from lower frequencies.
Then we edited the fft_adc_serial sample code by changing the pre-scalar to narrow the frequency bin width. We also implemented code to turn on an external blue LED when a 950 Hz tone is detected. We connected the circuit to the Arduino and ran the sketch while using the tone generator to generate some frequencies and printed out the data to the serial monitor. Below is a plot with this data. Although there is some noise, there are peaks in the corresponding bins to the frequencies being picked up by the microphone. The plot shown below is from the circuit without the high pass filter, which is why the 400 Hz signal has such a high peak. This plots purpose is mainly to show that the signal was being amplified.
FFT Plot (without high pass filter)
The bins in the graph above span thousands of Hertz. The important range to observe in order to determine that the FFT is working is approximately bins 0-40. The peaks in the bins beyond that are showing the higher order harmonics of the frequency that was played, which has no effect when only the peak in the fundamental 950 Hz bins needs to be monitored
Below is a schematic of the entire circuit used for the microphone. First, the output from the microphone is passed into an op-amp to amplify the voltage of the signal. Following this, as mentioned before, a high pass filter with a cutoff of 795 Hz is used. This filter is useful because it although it passes higher harmonics, it blocks out any peaks at frequencies within the range of human speech.
Microphone Amplifier and Filter Circuits
Below is a plot of the FFT analysis through the Arduino for a 950 Hz tone. There is a peak around bin 25, which correlates to approximately 950 Hz according to the bin width. The rest of the peaks are higher order harmonics.
The video below is a demonstration of the circuit responding to a 950 Hz tone. In the video, you can see the blue LED turning on as the tone is played, and you can also see the peak appearing on the FFT as the tone is started.
You can also see how reactive the circuit is to frequencies above and below 950 Hz in the video below. Once the frequency is outside of a short range containing 950 Hz, the blue LED immediately shuts off, indicating the 950 Hz tone is not being played anymore.
Optical Detection
Phototransistor Circuit
For the additional second circuit in lab 2, we designed the phototransistor circuit used to detect IR emissions from other robots. We used an 800 nm phototransistor along with a BJT to amplify the signal from the phototransistor. We first tried reading the output from the phototransistor while an IR LED was on and directed at it, not using a BJT. The problem with this was that the signal could not be detected from more than 3 or 4 inches away. So, in order to amplify the signal, we used a BJT to increase the voltage at the collector, which the terminal used for the output voltage read by the Arduino.
Below is a schematic of how the phototransistor is wired. On the right, there is also a schematic of the typical configuration of the IR LED.
Phototransistor Circuit
The video below is a demonstration of the phototransistor circuit detecting the infrared emission from the IR LED. The values of the resistors in our circuit are configured so that at approximately 1 foot, the reading from the pin will drop to 0 (a read from the analog pin is used in the demo to show the transient in voltage through the serial output). In the video, the voltage read value remains at 1023 until the phototransistor reaches ~12 inches. After this, the reading drops to below 100.