HomeOnline StoreContact UsSite MapSearch
 


KnowledgeBase

Fourier Analysis and FFT

Introduction
Fourier Analysis is based on the concept that real world signals can be approximated by a sum of sinusoids, each at a different frequency. The more sinusoids included in the sum, the better the approximation.

The first trace in the above figure is the sum of 2 sine waves with amplitudes chosen to approximate a 3 Hz square wave (time base is msec). One sine wave has a frequency of 3 Hz and the other has a frequency of 9 Hz. The second trace starts with the first but adds a 15 Hz sine wave and a 21 Hz sine wave. It is clearly a better approximation.

Such a sum of sinusoids is called a Trigonometric Fourier Series. The terms of the Fourier series for simple waveforms can be found using calculus and many have been published in standard textbooks.

The frequency of each sinusoid in the series is an integer multiple of the frequency of the signal being approximated. These are referred to as the harmonics of the original waveform. In the example above, the basic frequency is 3 Hz so we would expect harmonics at 3 Hz, 6 Hz, 9 Hz, 12 Hz, 15 Hz, etc. It turns out that for this particular waveform, all the even harmonics have amplitudes of zero. This is not true for all waveforms.

The Frequency Spectrum
Each of the harmonic frequencies is defined by a magnitude (amplitude) and a phase. The phase indicates how to shift the harmonic before adding it to the sum. The phase information can be difficult to interpret and its use is restricted to a few specialized applications. The rest of this document is concerned only with harmonic magnitudes.

Plotting the harmonic magnitudes on the y-axis and the frequency of the harmonic on the x-axis generates a Frequency Spectrum. The spectrum is a set of vertical lines or bars because harmonics can only have frequencies that are integer multiples of the original signal frequency. In theory, the spectrum includes frequencies up to infinity but in practice the magnitude of very high frequency harmonics are usually insignificant.

The plot shown here includes the first 20 harmonics of a square wave. The x-axis shows the harmonic number. In order to convert harmonic number to Hz, simply multiply by the frequency of the original signal. For example, if the original signal had a frequency of 2 kHz, the third harmonic would be at 6 kHz.

Note that because the original signal was a square wave, the even harmonics are zero. This is not always the case.

If the input had been a pure tone, we would expect a single bar with an amplitude equal to the amplitude of the input tone.

Fourier Analysis with Computers - FFT
Several techniques have been developed that enable a computer to calculate the Frequency Spectrum of a signal. The first step in all cases is to convert the signal to a set of numbers for the computer to use. This is done by sampling the signal at a regular interval so that a table of values is created. Each sample value is separated from the next by a fixed period of time.

The number of points obtained and the time between samples combine to determine the length of time we look at the signal. The following definitions apply:

fs = sample rate in Hz
dT = 1/fs = interval between samples
N = number of samples taken
T = N x dT = total time period

f1 = 1/T = frequency of the first harmonic in Hz

As an example, if we were interested in the AC power line, we might choose a sample rate (fs) of 6000 Hz and collect 100 samples (n=100). The result would be dT = 0.1167 msec and T = 16.667 msec. The first harmonic would then be f1 = 60 Hz.

The traditional mathematical approach to Fourier analysis was based on approximating continuous waveforms but computer techniques can only deal with a set of samples. This does not change the basic idea of harmonic analysis but now we have to keep in mind the following:

1. The spectrums based on sampled waveforms can generate only N/2 harmonics.

2. If the original signal contains more than N/2 harmonics, the higher frequency harmonics will cause errors in the magnitude spectrum.

This type of error is referred to as Aliasing. Aliasing can be prevented by filtering the input signal before performing the Fourier analysis so that there are no frequency components above f1 and N/2.

The most popular computer algorithm for generating a frequency spectrum is the FFT or Fast Fourier Transform. As the name implies, the FFT is very efficient but it does have one quirk that affects the way it is used. The FFT can only process a sampled waveform where N (number of samples) is a power of 2. Acceptable values of N include 128, 256, 512 and 1024. The full significance of this is discussed later in this note.

Note: The FFT, like most computer algorithms, generates an Exponential Fourier Series, instead of a Trigonometric Fourier Series. The two series are identical except that the magnitude generated by the exponential series are half the value of the trigonometric series. Most application software automatically compensates for this and presents the magnitude spectrum as a Trigonometric series.


Analyzing More Complicated Waveforms
Up to now we have assumed that the input signal is periodic with a constant frequency. We set up the spectrum so that the first harmonic was the same as the basic input frequency. This straight forward approach is useful when we know something about the signal ahead of time such as in the case when analyzing AC voltage.

In many situations, we are faced with a more complicated signal that may not have an obvious single period. An example is the following:

The x-axis is time in seconds. If we sample this signal at a rate of 4096 Hz, collect 1024 samples and put them through our FFT we get the following spectrum:

The spectrum tells us that the original signal is a composite of 3 pure tones. In fact, these tones are at 60 Hz, 300 Hz and 1200 Hz.

It is useful at this point to make a few observations.

1. Since N=1024, the FFT generated 512 harmonics. To simplify scaling the x-axis, the plot shows only the first 400.
2. The magnitudes are corrected for the trigonometric series and therefore use the same units as the input signal.
3. The length of the sample period is 0.25 seconds, so the first harmonic (f1) is 4 Hz. The spectrum looks nice and clean because all of the tones are multiples of 4 Hz (f1).

Unfortunately, this is not often the case.

Leakage
The previous example looked great because all the tones making up the original signal were multiples of f1 (1/T). Following is the same arrangement but the 300 Hz tone has moved to 302 Hz.

Although the 302 Hz tone has not actually changed amplitude, the spectrum looks very different. This effect is called Leakage and occurs when a frequency component of the original signal is not an integer multiple of the sampling period (T). The amplitude of the tone appears to leak into other harmonics. The effect can be made more obvious by expanding the x-axis.

This is the same spectrum, but we now show only the first 100 harmonics. The steps of 4 Hz become obvious. Note that the tone amplitude should be 90 (equal to the 60 Hz tone).

Leakage is a direct result of using a limited set of sampled data. If we could collect and process an infinite amount of samples, the frequency increment (x-axis) becomes very small and all possible frequencies would be valid harmonics.

The FFT algorithm does not add anymore leakage than other algorithms but it makes correcting the problem more difficult by limiting our choices for N to powers of 2.

There are two approaches to improving the accuracy of the spectrum when leakage is a problem.

1. Change the sample set to line up with the harmonic content.

2. Modify the sampled values with a weighted window.

Using Weighted Windows to Minimize Leakage
The term window has a specific meaning when applied to samples used to create a Fourier spectrum. Consider the signal in the first figure. In order to analyze the signal for harmonics we have to sample it for some fixed period (T).

Mathematically, this amount to multiplying one set of values by 1.0 and all other values of the waveform by zero. In effect, we create a set of sampled data by blocking out all other parts of the waveform with a Rectangular Window with an amplitude 1.0. The result is shown in the next figure.

Most computer algorithms, including the FFT, process this set of samples as if it were a continuous loop. If N=256 (samples 0 to 255), then it assumes that the value after 255 is the same as the value at sample 0. This assumption is true when the window (T) includes an integer multiple of a repeating cycle. When it is not true, as in this example, the discontinuity between the value of the first and last samples looks like a step change to the FFT and causes leakage.

Using a non-rectangular window can reduce leakage. In practice, this is done after the sample set is collected by scaling each sample in the set. The scaled values are than used as the input to the FFT.

Many windows have been developed and each has its own set of costs and benefits.

Window Example- Rectangular
The first figure is a plot of 1024 samples that will be used to generate a Fourier magnitude spectrum. The x-axis is time in seconds. The sampling process is defined by the following parameters:

fs = 1024 Hz (sample rate)
N = 1024 (number of samples)
T = 1 second (window length)

The FFT produces 512 harmonics (N/2) from this set of samples. The spacing between harmonics is 1 Hz, equal to the frequency of the first harmonic (f1 = 1/T). The second figure plots magnitudes of the first 100 harmonics. Note that the term harmonic can be confusing because it id derived from the window length T and may have no obvious relationship to the signal.

The spectrum indicates that the original signal is composed of 2 basic components but leakage makes it difficult to determine the magnitudes. The original signal was actually composed of 2 tones. One is an 11.6 Hz tone with an amplitude of 75 while the second is 55.4 Hz with an amplitude of 90.

The spectrum shows one peak at 12 Hz with a magnitude of 55.1 and another at 55 Hz with a magnitude of 68.2. The relative magnitude of the 2 components is close but the absolute magnitudes are badly distorted.

Window Example - Triangle and Hamming
The next figure shows the waveform from the previous example modified by a Triangle Window. The original waveform was sampled in exactly the same way as before but the sampled points were scaled by the triangular window. Note how the early and the late sample points are now attenuated.

The next plot shows the first 100 harmonics when this modified set of samples is used.

The peaks are at the same frequency but there is clearly less spreading (leakage). The magnitudes are also more accurate (65.7 and 78.8) but still incorrect.

Another popular window is the Hamming Window based on a cosine function. It is also designed to peak in the center of the samples and taper to zero at the ends. Using the Hamming Window on the same set of samples produces the following spectrum. The peaks are located at the same points with amplitudes of 65.7 and 79.1.

Note: The magnitudes have been corrected for a type of amplitude error created by non-rectangular windows. The factor is 0.5 for the Triangle and 0.54 for the Hamming. This is a technical correction based on lobe height.

Notes on Selecting a Window
1. If the input signal is periodic and a multiple of the sampling window, then use a Rectangular window.

2. If the input is a short pulse or burst that starts and ends at the same amplitude, then use a Rectangular window (as long as the sampling window includes the entire transient).

3. If the input is a sections of a continuous waveform that is not periodic then use the Hamming or Triangular windows.

Re-Sampling
As illustrated in the previous examples, the use of weighted windowing can improve the quality of the spectrum when frequency components are not integer multiples of the sampling window. Unfortunately, the examples also indicate that even with a weighted window, there is still some distortion.

In situations where major frequency components are multiples of one another, the best approach is to adjust the sampling process so that a full period of the input signal lines up with the sampling window. If this can be done, the best window is Rectangular. This situation is found in applications like power line monitoring where there is a strong primary frequency driving the signal.

The cleanest approach is to adjust the sample rate until N points are obtained in exactly one period of the input signal. This may not be practical when using the FFT because N must be a power of 2. The required sample rate may not be available or the data may have been collected previously and cannot be duplicated.

The solution to both problems is to re-sample a set of data, interpolating where required to produce the desired set of samples.

Decibels
It is common to present the amplitude of the frequency spectrum in decibels (dB). A decibel (1/10 Bel) is a unit originally used to measure the intensity of a sound with reference to a standard sound. In general, it can be used to indicate the intensity or power of any signal with respect to a reference. The user of a logarithmic scale permits a large range of amplitudes to be presented on a single plot.

As it applies to power, the dB is defined as: dB = 10log(Power/Reference Power)

Note that a negative value indicates power less than the reference. The reference varies with the application and this fact can cause some confusion. A letter is sometimes added to indicate the use of a standard reference. For example, a dBm measures signal power with respect to 1 milliwatt. Assuming power is measured in watts, the following equation applies: dBm =10Log(Mag/.001)

It has become common practice to treat the squared value of certain signals as power. In the case of a voltage waveform and a fixed load, this is valid because power is actually V*V/R. Following this logic, the units of dBm are sometime used when only a voltage signal is available by assuming a standard load of 50 ohms. A sinusoidal voltage with a magnitude of 0.316 V is shown as 0 dBm (1 milliwatt).

The situation gets more confusing because most electrical engineers use the term dB to indicate signal amplitude (not signal power) with respect to a reference. This can be linked mathematically to the standard definition as long as a constant electrical load (R) is assumed because:

P1/P2 = [(V1 x V1)/R]/[V2 x V2)/R] = (V1 x V1)/(V2 x V2)
and
10Log[(V1 x V1)/(V2 x V2)] = 20 Log(V1/V2)

Therefore, when calculating dB from signal amplitude (instead of signal power) user a factor of 20: dB = 20Log(Magnitude/Reference)

The units of dBV are based on a reference of 1V and assume the input signal is in volts. dBV - 10Log(Mag/1V)

The magnitude can also be compared to the peak of the original signal or the RMS of the original signal to derive additional dB scales.

Instruments with a built-in amplifier can use the unit dBVFS. This is obtained by referencing the magnitude to the full scale range setting of the input amplifier (20Log(Mag/FS). This is useful because it does not require that the input signal be in volts or watts.

 



© 2008 Astro-Med, Inc. All Rights Reserved.