The examples below give a progression from the most simplistic
analysis up to a proper practical treatment. Careful study of these
examples will teach you a lot about how spectrum analysis is carried
out on real data, and provide opportunities to see the Fourier
theorems in action.

The results are shown in Fig.8.1. The time-domain signal is
shown in the upper plot (Fig.8.1a), both in pseudo-continuous
and sampled form. In the middle plot (Fig.8.1b), we see two
peaks in the magnitude spectrum, each at magnitude on a linear
scale, located at normalized frequencies and
. A spectral peak amplitude of
is what we
expect, since

and when
, this reduces to

For and
, this happens at bin numbers and
. However, recall that array indexes
in matlab start at , so that these peaks will really show up at
indexes and in the magX array.

The spectrum should be exactly zero at the other bin numbers. How
accurately this happens can be seen by looking on a dB scale, as shown in
Fig.8.1c. We see that the spectral magnitude in the other bins is
on the order of dB lower, which is close enough to zero for audio
work
.

The resulting magnitude spectrum is shown in Fig.8.2b and c.
At this frequency, we get extensive ``spectral leakage'' into all the
bins. To get an idea of where this is coming from, let's look at the
periodic extension (§7.1.2) of the time waveform:

Looking back at Fig.8.2c, we see there are no negative dB
values. Could this be right? Could the spectral magnitude at all
frequencies be 1 or greater? The answer is no. To better see the true
spectrum, let's use zero padding in the time domain (§7.2.7)
to give ideal interpolation (§7.4.12) in the frequency domain:

Figure 8.4 shows the zero-padded data (top) and corresponding
interpolated spectrum on linear and dB scales (middle and bottom,
respectively). We now see that the spectrum has a regular
sidelobe structure. On the dB scale in Fig.8.4c,
negative values are now visible. In fact, it was desirable to
clip them at dB to prevent deep nulls from dominating the
display by pushing the negative vertical axis limit to dB or
more, as in Fig.8.1c (page ). This
example shows the importance of using zero padding to interpolate
spectral displays so that the untrained eye will ``fill in'' properly
between the spectral samples.

As Fig.8.4a suggests, the previous example can be interpreted
as using a rectangular window to select a finite segment (of
length ) from a sampled sinusoid that continues for all time.
In practical spectrum analysis, such excerpts are normally
analyzed using a window that is tapered more gracefully to
zero on the left and right. In this section, we will look at using a
Blackman window [70]8.3on our example sinusoid. The Blackman window has good (though
suboptimal) characteristics for audio work.

Figure 8.6 plots the zero-padded, Blackman-windowed sinusoid,
along with its magnitude spectrum on a dB scale. Note that the first
sidelobe (near dB) is nearly 60 dB below the spectral peak (near
dB). This is why the Blackman window is considered adequate for
many audio applications. From the dual of the convolution
theorem discussed in §7.4.6, we know that
windowing in the time domain corresponds to smoothing in
the frequency domain. Specifically, the complex spectrum with
magnitude displayed in Fig.8.4b (p. )
has been convolved with the Blackman window transform (dB
magnitude shown in Fig.8.5c). Thus, the Blackman window
Fourier transform has been applied as a
smoothing kernel to the Fourier transform of the rectangularly
windowed sinusoid to produce the smoothed result in Fig.8.6b. This
topic is pursued in detail at the outset of Book IV in the music
signal processing series [70].

The resulting plot of the Hann window and its use
on sinusoidal data are shown in Fig.8.7.

Figure 8.7:
A length 31 Hann window
(``raised cosine'') overlaid with the real part of the Hann-windowed
complex sinusoid. Zero-padding is also shown. The sampled sinusoid
is plotted using `*' with no connecting interpolation lines. You must
now imagine the continuous real sinusoid (windowed) threading through
the asterisks.

Notice how difficult it would be to correctly interpret the shape of
the ``sidelobes'' without zero padding. The asterisks correspond to a
zero-padding factor of 2, already twice as much as needed to preserve
all spectral information faithfully, but not enough to clearly outline
the sidelobes in a spectral magnitude plot.

As for the phase of the spectrum, what do we expect? We have chosen
the sinusoid phase offset to be zero. The window is causal and
symmetric about its middle. Therefore, we expect a linear phase term
with slope
samples (as discussed in connection with the
shift theorem in §7.4.4).
Also, the window transform has sidelobes which cause a phase of
radians to switch in and out. Thus, we expect to see samples of a
straight line (with slope samples) across the main lobe of the
window transform, together with a switching offset by in every
other sidelobe away from the main lobe, starting with the immediately
adjacent sidelobes.

In Fig.8.9(a), we can see the negatively sloped line
across the main lobe of the window transform, but the sidelobes are
hard to follow. Even the unwrapped phase in Fig.8.9(b)
is not as clear as it could be. This is because a phase jump of
radians and radians are equally valid, as is any odd multiple
of radians. In the case of the unwrapped phase, all phase jumps
are by starting near frequency .
Figure 8.9(c) shows what could be
considered the ``canonical'' unwrapped phase for this example: We see
a linear phase segment across the main lobe as before, and outside the
main lobe, we have a continuation of that linear phase across all of
the positive sidelobes, and only a -radian deviation from that
linear phase across the negative sidelobes. In other words, we see a
straight linear phase at the desired slope interrupted by temporary
jumps of radians. To obtain unwrapped phase of this type, the
unwrap function needs to alternate the sign of successive
phase-jumps by radians; this could be implemented, for example,
by detecting jumps-by- to within some numerical tolerance and
using a bit of state to enforce alternation of with .

To convert the expected phase slope from ``radians per
(rad/sec)'' to ``radians per cycle-per-sample,'' we need to multiply
by ``radians per cycle,'' or . Thus, in
Fig.8.9(c), we expect a slope of radians
per unit normalized frequency, or radians per
cycles-per-sample, and this looks about right, judging from the plot.