Lab 2
Analog Circuitry & FFTs
Read the Report


Lab 2


Test and familiarize yourself with the sensors and signal processing needed for your robot to detect acoustic and optical signals and interface with the Arduino Uno. The Acoustic sub-team will work on the microphone circuit, which will detect a 660 Hz whistle blow, signifying the start of the maze mapping competition. The Optical sub-team will work on the IR sensor circuit, which will detect nearby robots emitting IR at 6.08 kHz and distinguish them from decoys emitting at 18 kHz.

To begin, we split into two groups of two. Each group progressed through the lab individually, as described below.

Both the Acoustic and Optical parts of this lab used Fast Fourier Transforms (FFT) to determine the frequency components of the sampled input signal from the sensors. For pure sinusoids, this is not so difficult, as one can simply read off the period in the time domain. However, for more complicated signals, it is not necessarily clear what frequencies are present, and certainly not clear if a given frequency is present. To make this process easier, a signal can be inspected in the frequency domain.

In the frequency domain, we can observe a signals “spectrum”. A spectrum is an interpretation of a signal which assigns a magnitude (an importance) to a given frequency. The standard way to compute this is with a Discrete Fourier Transform (DFT):

The DFT equation

The DFT computes a change of basis, assigning the weight X(k) to a given radial frequency (2*pi*k/N) by computing the inner product of the original signal with the complex exponential at that frequency.

Note that to compute one X(k) value, we need N multiplications, and N - 1 additions. To get useful information about a signal of size N, you generally need N values of k. This makes the DFT computation an O(n^2) operation, which can get very slow for large values of N.

To speed this process up, the Fast Fourier Transform (FFT) is used. The FFT is an algorithm for computing the DFT efficiently—the best speed up is achieved when N is a power of 2. The algorithm uses a “divide-and-conquer” method to compute the DFT. It first isolates the even and odd terms of the original DFT sum. Then it evaluates these sums as two independent FFTs of length N/2.

The FFT divide-and-conquer approach

FFT Butterfly diagram

A key to this process is that the odd sum gets transformed into a N/2 FFT by pulling out an overall constant phase. This process of splitting up into two FFTs can continue down all the way until you have reached a series of FFTs, each acting on only two values. This splitting action occurs log2(N) - 1 times. At each stage, there are N multiplications and additions, so our computational complexity has decreased to O(N * log2(N)).

The FFT algorithm was implemented using Open Music Labs Arduino FFT Library. By default, the library takes in an analog signal from Arduino pin A0, samples it at 256 equally spaced intervals, and returns an array with 128 values, which represent the magnitude of the frequency content for frequenices up to half of the samping frequency. Since the FFT of a real signal is symmetric over zero, only half of the outputs are unique, and thus 128 bins are returned (not 256).
The FFT code can be modified to alter the performance of the ADC (information from the ADC section of the ATmega328 datasheet [page 305]). The important ADC characteristics are:

To test and visualize the data, we used the example code "fft_adc_serial," which prints the FFT magnitude data to the serial monitor. We then copied the data into Excel, and wrote a simple MATLAB script to read in and plot the data.


GOAL: use an Arduino and the FFT library to detect a 660 Hz whistle blow

  • Circuit testing
    • To make sure the microphone amplifier circuit was working properly, we ran it through the following tests:
      • 660 Hz tone
      • 680 Hz tone
      • 640 Hz tone
      • 660+760 Hz tone
      • 660+560 Hz tone
    • For each test, we played one or more distinct tones from device(s) 5 cm away from the microphone
    • With the audio playing, we ran the FFT code and recorded the data
    • Once we finished, we graphed the results
    • The data shows that we are successfully able to differentiate between various tones

Microphone amplifier circuit FFT test results

Demo:



GOAL: use an Arduino and the FFT library to detect another robot emitting IR at 6.08 kHz and ignore decoys (18 kHz)

Band-pass filter schematic (from Professor Shealy, ECE2100 course notes)

IR filter bode plot

Silence

  • Spectrum is pretty sparse
  • There are some small peaks around 8 kHz and 13 kHz

IR Hat

  • There is a large peak at 6160 Hz
  • Bins 41 and 42 correspond to the 6 kHz IR hat signal
  • When the peaks in these bins are above a threshold, then the IR hat signal is detected

IR Decoy

  • There is a peak corresponding to 18 kHz on the spectrum
  • No frequencies are aliased to the bins around 6 kHz
  • Thus, we can ignore the 18 kHz peak and only observe bins 41 and 42 for IR hat detection

IR Hat + IR Decoy

  • There are peaks at 6 kHz and 18 kHz
  • Ignore the 18 kHz bins
  • Observe bins 41 and 42 for IR hat detection

Our concurrent testing software works as follows