Pages

Friday, March 16, 2012

Using Discrete Fourier Transform in Real Life

Wondering where to use discrete Fourier transform (DFT) in real life?

I guess this is the dilemma every graduate in Malaysia is facing. I guess there is a flaw in the system where they only let students learn without exposure to real life application. Quite a shame.

In this post, the infrared transmitter and receiver will be used as example of real application of the DFT. The application of floor line sensing will be discussed (either the line is dark or light). This link serves as a little introduction to IR transmitter and receiver.

Comparator
To use the data from a IR transmitter and receiver, one can connect the IR to a comparator for dark and light detection. This is the most common and simplest method to use. The programming is super simple because the sensing for dark and light is just '1's and '0's.



The main disadvantage of this dark and light sensing with comparator is the mechanical tuning. Somehow the signal from the IR receiver has to be compared with a variable voltage from a potentiometer. And to set the threshold, involves the turning of the potentiometer.

This type of system can be used in a fixed surrounding ambient, and to use it in other place, the potentiometer has to be tuned again. In other words, the threshold is not flexible in programming sense.

Analog to Digital Converter
By sending the signal from the IR received to an ADC will solve the mechanical tuning problem. The dark and light threshold can be changed easily via programming. And changing from one location to another with different ambient is easy.

But still, this sensing system is vulnerable to change in ambient. For example, in a sudden, the light in the room brightens up, the actual threshold will be shifted, causing the reading to be wrong.



The situation is depicted in the graph above. The ambient will cause the programmed threshold to be unusable. Therefore, this system of sensing is not robust enough. Of course some programming can be done to detect the ambient before setting the threshold, but this does not guarantee the performance of the line sensing.

Introduction to the Discrete Fourier Transform
DFT is actually a mathematical tool to analyze the spectrum in a signal, in function of time (or space). By taking N samples from a series of signal with sampling rate of Fs, the frequency spectrum of the signal can be extracted up to Fs/2. Therefore, if I would like to detect the frequency of Fc, I need to sample using a sampling frequency of 2 * Fc.

More detail on DFT and sampling theorem can be found in Wikipedia.

Moving on, from the graph above, if only one sample were used for the dark and light sensing, this also means only the dc value was sampled (in DFT sense). Depending on the ambient, the dc value can vary a lot.


Solving Ambient Problem with DFT
To solve this problem, the dark and light sensing has to be shifted out of the dc range. The sensing can be placed at any frequency as long as it does not rests in the dc position.



As shown in this picture above, we have to move the sensing frequency elsewhere to prevent misleading data from the ambient (dc value).

To be able to do this, the IR transmitter has to transmit signal at a frequency of Fc. And the IR receiver has to sample N samples with the frequency of 2*Fc. Thereafter, the DFT formula is used to extract the amplitude of Fc from the N samples, which is also the line reading. By setting a threshold, the light and dark can be distinguished easily without the interference of the ambient.

No comments: