FFT Algorithms - Mathcad |
Using the FFT Algorithm(s)
in Mathcad
If you use Mathcad to get
the FFT you could use a workspace like the one below. Here is a
link to the complete workspace. This workspace does the following:
Points to note:
Mathcad indices start at
0, and we start with a coefficient, ao. The first
coefficient is ao and it will be stored in the first
element of the array (SigFFT in the example m-file), i.e, SigFFT(0).
Unlike Matlab, the indices work out in Mathcad. For example, SigFFT(11)
will contain the 11th harmonic.
The calculation will be
done in terms of the harmonics of the fundamental frequency of the data
set. If you have a square wave that shows two periods in the data set,
the first harmonic of the square wave will be the second harmonic of the
fundamental frequency of the data set, and - given the first point just
above - will appear in the third element of the FFT array.
When you do the
calculation, you will often have data that has many periods in one
data set. Those frequencies - in the periodice signal - will be at
exact multiples of the fundamental frequency of the data set (a
sharp line in the computed FFT) or near a multiple (a spread-out
line). You shouldn't expect the fundamental of a periodice signal
to be the fundamental frequency of the data set unless you have
exactly one period of your periodic signal in the data set.
Example: You have a
data set that is 2 milliseconds long. The fundamental frequency of
the data set is 0.5 kHz (= 500 Hz). If you have a one kHz signal
embedded in that data, it will be at the second harmonic of the 500
Hz. (In Mathcad, that will be at the index = 2.)
The calculations
includes a 1/N term. You have to compensate for that since you will
probably want it to be 2/N. In a five volt square wave with 4000 data
points, the first harmonic of the square wave will calculate out at a
magnitude of 3.2 or thereabouts. The actual first harmonic (i.e., the
fundamental) of a square wave of amplitude A is 4A/p ,
and that would calculate out to about 6.4. To get from 3.2 to 6.4 you
need to multiply 3.2 by 2.
There are other options
in Mathcad. They include the following - which have different
normalizing factors and other peculiarities:
FFT
- if you have exactly 2m data points, where m is
an integer.
cfft
- which gives results that need to be multiplied by 2*SQRT(N).
fft
- which gives results that need to be multiplied by 2*SQRT(N) - if
you have exactly 2m data points, where m is an
integer.
Note that there are also
inverse transform functions available if you need to go from FFT data
back to time data.
|