FFT Example - Done Using Matlab |
An FFT Example - Done Using
Matlab
In this note we are going
to analyze a triangle signal using the FFT.
Here is the signal.
The signal has 4000 samples,
and the length of the record is 2 milliseconds. (It goes from -.001 seconds
to +.001 seconds.)
Since the length of the
record is 2 milliseconds, if we compute the FFT for the entire record (which
we would normally do), then the fundamental frequency in the computed
results is going to be 1/.002 = 500 Hz. We will refer to this as the
fundamental frequency of the data record.
Within the data record is the
triangle signal, and it has a period of 1 millisecond, so it has a frequency
of 1 KHz.
Now, we need to examine what happens
when we FFT this signal. We will use the m-file below. This basic m-file was
discussed in
another note.
Now, if we look at the plot of the
absolute value of the SigFFT array, we get a plot like the one below.
Now, the fundamental
frequency of the data record is 500 Hz. You need to be able to get from that to
the actual frequency components of the signal. Here is what you need to use.
The fundamental frequency of
the data record is the reciprocal of the length (in seconds) of the data
record.
In Matlab, the indices start
from one. So, ao, is going to be placed in SigFFT(1) in
our m-file above. Here is a short table of frequencies, indices, etc.
Index
|
Harmonic of the
fundamental frequency of the data record |
The actual
frequency |
SigFFT(1)
|
0
|
0 Hz (DC)
|
SigFFT(2)
|
1
|
500 Hz
|
SigFFT(3)
|
2
|
1000 Hz
(1 KHz) |
SigFFT(4)
|
3
|
1500 Hz
|
SigFFT(5)
|
4
|
2000 Hz
|
SigFFT(6)
|
5
|
2500 Hz
|
SigFFT(7)
|
6
|
3000 Hz
|
Now, we can get at the
frequencies in the FFT plot. Notice the following.
The first "spike" in the FFT
plot is at SigFFT(3). That corresponds to 1000 Hz which is the fundamental
of the signal. It is not the fundamental of the data record. It is,
however, related to the fact that there are exactly two cycles of the signal
in the length of the data record.
The second "spike" in the FFT
plot is at SigFFT(7). That corresponds to 3000 Hz which is the third
harmonic of the signal.
and so on. . .
With that, you should be able
to interpret the horizontal scale of the FFT plot - at least the plots that
Matlab produces.
Now, we need to address
the vertical scale. First, you should realize that the vertical plot is the
absolute value of the c's in the Fourier expansion. If you need to understand
what the c's are, check these links.
When we did the calculation,
we found that the third element in the SigFFT array (That's the one that is the
first, large value - somewhere over 8000 on the plot!.) has a value of 8,103.
That's not a number that we would expect from a triangle wave that has an
amplitude of 5 volts.
The explantion for the
seemingly ridiculous value of over 8000 is this:
The calculation
does not include the 2/N term. Type "help FFT" (without the quote
marks!) in the Matlab workspace for the explanation of what it actually
calculates. What is boils down to is that there is a missing 2/N term.
You have to compensate for that. In a five volt triangle wave with 4000
data points, the first harmonic of the triangle wave should be 8A/(p2)
(where A= 5 for our signal). Here are some links to
pages with the expressions for the Fourier Series of a triangle wave
signal. That's where we got that amplitude for the first harmonic.
The actual first
harmonic (i.e., the fundamental) of a triangle wave of amplitude A is
8A/p2,
and that would calculate out to about 4.053. To get from 8,103 to 4.053
you need to multiply 8,103 by 2/4000 (that's 2/N). Try it, and the
result is very close to 4.053
What do you conclude
from this?
From the material above,
you should be able to determine the actual Fourier Series components if you have
a signal in a file. You should be able to distinguish between the fundamental
frequency of the data record and the fundamental frequency of the signal
embedded in the data record - if that signal is periodic. And, you should be
able to determine the frequencies present in the signal, as well as the
amplitudes.
What if the signal
doesn't have an integral number of periods in the data record?
Here is an example of a
signal with 2.5 periods in the data record. In this signal, we only have 2000
points, so we have to factor that in.
You can see that there is not an
integral number of periods in the data record. Now, let's see what happens when
we FFT this data record. That's shown below.
Generally, this can only be
described as a mess. There are no clear-cut lines in this FFT spectrum.
However, note the following table.
Index
|
Harmonic of the
fundamental frequency of the data record |
The actual
frequency |
SigFFT(1)
|
0
|
0 Hz
|
SigFFT(2)
|
1
|
500 Hz
|
SigFFT(3)
|
2
|
1000 Hz
(1 KHz) |
SigFFT(4)
|
3
|
1500 Hz
|
SigFFT(5)
|
4
|
2000 Hz
|
SigFFT(6)
|
5
|
2500 Hz
|
SigFFT(7)
|
6
|
3000 Hz
|
Now, we can get at the
frequencies in the FFT plot. Notice the following.
The fundamental frequency of
the signal embedded in the data record is 1250 Hz. That is not a frequency
found in the table. Rather, the harmonics of the fundamental frequency of
the data record are 1000 Hz and 1500 Hz, and they appear at indices of 2 and
3.
The largest spikes appear at
indices of 2 and 3.
All of that is well and good,
but the third harmonic of the embedded signal is at 3750 Hz and that would
appear between indices 8 and 9.
|