Professional Documents
Culture Documents
2008-An Introduction To FFT and Time Domain Windows
2008-An Introduction To FFT and Time Domain Windows
actuators,
Sensor Input Processing Output signals,
control
An Introduction
to FFT andTime
Domain Windows
Part 11 in a series of tutorials in
instrumentation and measurement
Sergio Rapuano and Fred J. Harris
A
student in a digital signal processing class soid. No other wave shape can make that claim! The
once asked an insightful set of questions. sinusoids preserve their identity in a linear system; the
They went something like this: “Professor, system can change the sinusoid’s amplitude and phase
can you explain why we spend so much of our time but it cannot change its basic structure. Sinusoids are
describing signals in the frequency domain? We first ex- eigenfunctions of linear, constant-coefficient, differ-
amined circuits in terms of their sinusoidal steady-state ential equations. As such, the sinusoids can be used to
response. We then went on to study Fouri- analyze and characterize the linear system.
er series and Fourier transforms, and The collection of amplitude and phase
we are now studying sampled changes experienced by sinusoids
data Fourier transforms, and of different frequencies passing
the Discrete Fourier trans- through the system compactly
form, all based on sinusoids describes the system. We call
and sampled data sinu- this description its frequency
soids. Why not use other response. The frequency re-
basis functions? What is so sponse is intimately tied to
special about sinusoids?” the system’s transfer function
Great questions! We wish and its differential equation.
we had thought to ask them! The Fourier transform is also
The answers are simple. used to describe signals in the time
Many of the dynamic systems we or spatial domains. We limit our dis-
analyze, synthesize, design, develop, cussion here to time domain descriptions.
and operate can be approximated by linear Signals of interest are decomposed into a set of
time invariant systems modeled by linear, constant- complete orthonormal basis functions, the real sines and
coefficient, differential equations. So now the question cosines, or, equivalently, the set of complex exponentials
is, “What does that mean?” It means this: if we dif- [3]. The classic Fourier transform is the mechanism that
ferentiate a sinusoid, it is still a sinusoid. If we form a performs this decomposition, leading to a frequency
weighted sum of derivatives of a sinusoid, the sum is domain description of the signal. There are several ad-
still a sinusoid. The sinusoid never stops being a sinu- vantages to analyzing signals in the frequency domain.
(1)
with an inverse transform integral as shown in Equation 2:
(6)
(2)
When xa(t) is periodic in T0 s, the spectral components are
harmonics located at multiples of the fundamental frequency, (7)
1/T0 Hz. The signal xa(t) can be represented, in the mean square
sense, with a countable sum of sine waves by the Fourier Series The inverse SDFT (of Equation 6 or Equation 7) is shown in
(FS) [1] integral shown in Equation 3. The resulting magnitude Equation 8 and is seen to be the sampled data counterpart of
and phase spectra reside only at the integer multiples of the Equation 3:
frequency 1/T0, or k/T0.
(8)
◗ Sampling the periodic spectrum of the input sequence unity, . The projections are performed as N-point inner
at multiples of FS/N induces periodicity of the input se- products, with each projection requiring N complex multiply
quence with period N. and add operations. Thus, N2 complex multiplications are re-
◗ The samples in the frequency domain are equally spaced quired for the direct computation of the DFT. FFT algorithms
at multiples of FS/N; therefore, spectral values differ- exist for any composite length N DFT. By composite we mean
ent from kFS/N are not available from the N-length N is factorable into a product of factors: i.e., N = N1 × N2. For
transform. The frequency interval FS/N defines the instance, consider the factors of N = 800 with one possible
transform frequency resolution, and the frequencies factoring of 32 and 25.
kFS/N are denoted frequency bins. Many FFT algorithms operate by the divide-and-
◗ Additional frequency resolution can be conquer method. In this process, the transform is
obtained for a sequence of length N by partitioned into a sequence of reduced-length
performing a 2N or 4N-point transform The transforms that are collectively performed with
on the zero-extended versions of the main reduced workload. For instance, a data vector
sequence. of length N = N1 × N2 is mapped to a two-di-
advantage mensional intermediate array of dimen-
Applications of the DFT sion N1-rows by N2-columns. We per-
By using the DFT and its properties, it of the DFT form a two-dimensional transform
is possible to do the following: over the FT is that by N1 transforms over the row vec-
◗ Compute the spectrum of a tors of length N2, which requires
sampled data signal. it permits machine N1N22 operations followed by
◗ Perform circular con- N2 transforms over the col-
volution of two sam- computation of spectra. umn vectors of length N1,
pled signals as the which requires N 2 N 12
N-point IDFT of operations. Depend-
ing on the details of the one-dimensional to two-dimensional in successive 50% workload savings. The radix-2 transform
mapping, there may be a set of phase rotations, called twiddle requires twiddle factors between successive partitions. The
factors, applied to the output of the first set of transforms prior iterative partitioning operation can be repeated until the proc-
to application of the second set. The total workload for the ess performs 512 two-point transforms, which are combined to
two-dimensional transform is seen to be N1N22 + N2N12 = (N1N2) obtain 256 four-point transforms, which in turn are combined
(N1 + N2), which, simply stated, is the sum of the factors times to obtain 128 eight-point transforms, continuing until two
the product of the factors. The workload for the original, un- 512-point transforms are combined to form the 1,024-point
factored DFT is N2 = (N1N2)(N1N2). The ratio of the workloads transform [1]. Each successive combining operation requires
is seen to be the sum of the factors divided by the product of N/2 complex multiplications. The number of combining steps
the factors, R = [(N1N2)(N1 + N2)/(N1N2)(N1N2)] or R = (N1 + is equal to the number of times the array length can be parti-
N2)/(N1N2). With the factors for N = 1,000 of 32 and 25, this tioned 1 to 2 (or halved), which is log2(N). Consequently, the
ratio is seen to be (32 + 25)/(32 × 25) = 0.071. Here we see that total number of complex multiplications required to calculate
the factored form requires only 7.1% of the workload of the a radix-2 FFT is N/2 log2(N).
unfactored form, a savings of nearly 93%. The factoring pro- To give an idea of the computational efficiency of the FFT
cess is nested, with the 25-point transforms performed as two- algorithm over the direct DFT calculation, consider the DFT
dimensional transforms over 5-by-5 arrays and the 32-point of length 1,024. The savings ratio is [N/2 log2(N)]/[N2] or
transforms performed as 2-D transforms over 4 × 8 arrays. log2(N)/(2N) = 10/2,048 or 0.0049, a savings of 99.5%. The
A common-length FFT is known as the radix-2 DFT, which actual numbers are 5,120 operations for the FFT, compared to
performs successive halving of the length N DFT, with N being 1,048,576 operations for the direct DFT computation.
a power of 2, such as 210 = 1,024. The partition described above The output of an FFT is a vector of length N, obtained by
starts with a two-dimensional array of length N/2 by 2, which sampling the periodic spectrum of the sampled data signal at
results in a savings ratio of (512 + 2)/(512 × 2) = 0.502, a sav- the frequencies kFs/N. It is common to call these spectral lo-
ings of nearly 50%. Each successive iterated partition results cations frequency bins. The periodic spectrum is visualized on
Fig. 2. Top; analog 2 kHz sine wave and spectrum; middle: 3 ms rectangular window and spectrum; bottom: windowed sine wave and spectrum.
a circle of circumference Fs or in normalized units of 2pf/Fs. As frequency bins from 0 to N − 1. In the redefined spectral cut
we unwrap the circle to map it to a line, we traditionally cut the indices are mapped to –N/2 to +N/2 − 1, or in normal-
the circle at angle 0 so that the line extends over the interval ized coordinates, (−0.5 to +0.5). For complex signals the DFT
[0 to 2p), closed on the left, open on the right. The spectrum is asymmetrical and the entire span (−0.5 to +0.5) is pre-
obtained by this cut has frequency 0 at the far left, positive sented, and for real input signals, the DFT is Hermetian sym-
frequencies extending to the right until the mid-point, at metric, so a reduced span of (0 to +0.5) is presented, since the
which point we have the half sample rate, beyond which we positive frequencies, the first N/2 + 1 samples, are sufficient
have the negative frequencies. The FFT computes samples of to represent the signal spectrum. Figure 1 presents the log
the spectrum at increments of 2p/N, indexing the samples magnitude spectrum formed by an FFT of a complex and of a
from 0 to N − 1. Sample N is congruent to sample 0 and is, in real 1.7 kHz sine wave with AWGN (Additive White Gauss-
fact, the start of the next spectral period. Thus, sample −k is ian Noise) sampled at 10 kHz. Here we see the spectra with
the same as sample N − k and the frequencies with negative and without the redefined spectral cuts. As can be seen, the
index; the negative frequencies are located in the second half spectrum of the complex signal is asymmetric and the spec-
of the interval. It is common in spectral displays to redefine trum of the real signal is symmetric about both Fs/2 and 0.
the cut on the circle to be located at angle p to redefine the
interval as (−p to p). In this form the center of the display is 0 Spectral Leakage
frequency, with negative frequencies located to the left and As described earlier, the DFT computes samples of the pe-
positive frequencies located to the right. MATLAB uses the riodic spectrum X(q) associated with the N-point sampled
command fftshift to redefine the spectral cut. The result of data sequence {x(n)}. Sampling in the time domain causes
FFT calculation is a double-sided spectrum mapped to the replication (or periodic extension) of the spectrum, with rep-
(12)
(13)
the FFT will have the appear-
ance shown in Figure 3. In this
(b) example, the sampled signal is
a 2 kHz sine wave with a period
equal to 0.5 ms that is sampled
at a 20 kHz rate. The sampling
period is 50 μs and covers a 3
ms time interval spanning six
cycles of the sine wave to col-
lect a total of N = 60 samples.
The FFT values will be zero
for all frequency bins except
(c) for the one corresponding to 2
kHz, because a sample is taken
Fig. 3. Top: sampled and windowed 2 kHz sine wave; middle: mid: single-sided spectrum of signal; bottom: DFT
at the peak of the main lobe of
samples of sampled sine wave. Xa(f) *WR(f), while all the others
Fig. 6. Time and spectral response of common window functions: rectangular, Hann, Kaiser-Bessel, and Harris Flat-Top. The width of the rectangular window
main lobe is overlapped to the other window spectra as dashed red lines to easily compare them.
the detectability of low-level nearby spectral terms is reduced in characteristics of the window frequency response. In [3], [7], and
comparison with other windows. The uncertainty of the ampli- [8], a complete description of them is given in mathematical and
tude measurement is greater than for windows designed for low practical terms. Here some parameters are recalled and briefly
scallop loss, such as the harris Flat Top window. As a result of the introduced in order to give some indications on how to interpret
wide flat spectral response, the Flat Top has small scallop loss and them for finding the right trade-off for a given application.
hence exhibits small amplitude errors, but the same flatness leads
to significant frequency uncertainty, which must be resolved by Minimum Resolution Bandwidth
one of the spectral interpolation options. As described above, as a result of the convolution of the sig-
The Flat Top window, on the other hand, has a flat but very nal and the window spectra, the windowed signal spectrum
wide main lobe and lower side lobes. The Kaiser-Bessel win- includes a replica of the window frequency response located
dow, with a time-bandwidth parameter, β, offers a selectable at each frequency component of the signal, resulting in an
trade between side lobe levels and main lobe width. Some
digital signal processing systems offer the option to select a
window from a set to give the user more degrees of freedom
in the analysis. In all cases the user should be aware of the ef-
fect of the windows on the measurement results. A complete
introduction to the windowing techniques as well as a review
of more window characteristics can be found in [3].
Windows Characterization
There are several figures of merit used for classifying the win- Fig. 7. Overlapped components that cannot be distinguished (one peak) and
dows used in digital spectrum analysis. All parameters refer to that can be distinguished (two peaks) [3].
Processing Gain/Processing
Loss
The amplitude estimation
of a frequency component
is affected by the broad-
band noise passed by the
bandwidth of its spectral
main lobe. In this sense, the
window behaves as a filter,
gathering contributions for
its estimate over its band-
width [3]. Remember, to re-
duce side lobes we increase
main lobe width, which
permits more noise into the
spectral measurement and
at the same time reduces
the amplitude of the main
Fig. 8. Scalloping loss is 3.9 dB for a rectangular window and 1.2 dB for a Kaiser-Bessel window measuring a spectral lobe, which reduces the
peak at position 4.5 cycles per interval, midway between bins 4 and 5.
amplitude of the desired
sine wave measurement.
overlap of the main lobes corresponding to the nearest compo- The window reduces the signal-to-noise ratio (SNR) relative
nents. As a consequence, even if the frequency resolution of the to the SNR of the default rectangle window. A measure of how
DFT is very high, it isn’t possible to resolve near components much SNR improvement obtained from a windowed FFT can
with similar amplitude whose distance is lower than the width be found as the ratio between the SNR before and after the
of the window main lobe (Figure 7). To this aim, the width of calculation, called Processing Gain (PG):
each lobe is defined to be the frequency interval correspond-
ing to a 6-dB attenuation to the DC gain and is called minimum
Resolution Bandwidth (RBW) [3], [6]. As indicated in [3], the
minimum RBW goes from 1.2 to 2.6 bins, depending on the
specific window. (14)
Side Lobes where, So/No is the output SNR, Si/Ni is the input SNR, and w(k)
The detectability of weak components is mainly affected by is the window sample. The PG of a rectangle window is N (sum
two characteristics of the window frequency response: the squared/sum of squares), the PG of a Hann window is N/1.5
highest side lobe level and the rate of side lobe roll-off. The lev- and the PG for a 60-dB Kaiser Window is N/1.7. Usually the PG is
el of the highest side lobe is given as a ratio in dB normalized normalized to the PG of a rectangle of the same length N. Interest-
to the main lobe level. The maximum side lobe level usually ingly, the reciprocal of the PG is the equivalent noise bandwidth
falls inversely with the main lobe width. The side lobe roll-off ENBW, the width of a spectral rectangle of unit amplitude that
is usually given in terms of the frequency response decrease in passes the same noise power as the window being described.
dB per frequency octave or decade. This rate is1/f (m+1), where m Thus, the ENBW of a rectangle is 1/N and of a Hann window is
is the order of the derivative of the window envelope in which 1.5/N. The Hann window’s equivalent filter passes half again
the first discontinuity resides. For instance, a rectangle is dis- as much noise as does the rectangle window’s equivalent filter.
continuous in the zero-th derivative, and its rate of spectral Incidentally, the reduction in SNR or PG due to use of a good
decay is 1/f 1 or 6 dB/octave, and a Hann window is discon- window is exactly cancelled by the variance reduction obtained
tinuous in the second derivative and its rate of spectral decay when averaging overlapped windowed transforms [8], [9].
is 1/f 3 [1], [3]. Note that the Hann window has a discontinuity
in its zero-th derivative, and its rate of spectral decay is also Scalloping Loss
1/f, but it has lower side lobes than the rectangle because it has When the frequency being analyzed by the DFT is bin-cen-
a smaller discontinuity. Similarly, the Kaiser-Bessel window tered, the DFT sample coincides with the peak of the window’s
also has a discontinuity in its zero-th derivative, and its rate main lobe response. When the frequency is positioned offset
Fig. 9. Time domain and spectra of windows with −90-dB side lobes and main lobe width of Fs /N.
from the bin center, the DFT sample is offset on the main ◗ A paraphrase of the Nyquist criterion tells us that the
lobe, and the measurement is less than the peak value. The sample rate should exceed the two-sided bandwidth of
worst-case reduction in measurement value occurs when the the signal. For real baseband signals this is interpreted as
signal frequency resides midway between two bin centers. such: the sample rate must be at least twice the highest
An example would be a sine wave with 4.5 cycles per interval frequency component in the signal. This is a very restric-
of length N, its spectral peak residing midway between bins 4 tive interpretation and should not limit your options. The
and 5. Here both adjacent bins offer a reduced-level sample of transform of a real signal exhibits Hermetian symmetry,
the offset main lobe spectral response. Windows with wider H(k) = H*(−k). As such, without loss of information, the
main lobe width have smaller loss as a result of the frequency FFT can be computed and displayed for positive frequen-
offset. As seen in Figure 8, the amplitude error, called scalloping cies only. Complex signals, on the other hand, formed, for
loss, depends on the window’s main lobe bandwidth. Usually instance, by a quadrature downconversion of a span of
the scalloping loss is reported in dB and goes from 0.1 to 3.92, positive frequencies, does not exhibit spectral symmetry.
depending on the window [3]. As such, the FFT must be computed and displayed for
both positive and negative frequencies. Bear in mind that
Misconceptions the analog anti-aliasing filters have a transition band-
Common misconceptions to keep in mind when estimating the width, and not all spectral components are alias free. It is
spectrum of a signal with an FFT are the following: typical, for instance, to allow the aliased transition band
◗ The transform length N does not have to be a power of 2. to corrupt 10–20% of the spectrum so that a 1,024-point
FFTs come in all sizes, and any (non-prime) length FFT is FFT can present 400 spectral lines for real signals, or 800
available. A 500-point transform is as efficient as a 512 - lines for complex signals [2].
point transform. Transforms with lengths that are powers ◗ A number of pre- and post-processing algorithms aid
of 2 have very simple coding structure, which influences the FFT in the spectral estimation task. We discuss one
hardware implementations but has little bearing on soft- here to catch the reader’s interest. The spectral resolu-
ware-based spectral estimation. tion of an FFT is initially defined by the spacing between