Digital Sound & Music: Concepts, Applications, & Science, Chapter 2, last updated 6/25/2013
44
sound(a, sr);
When you play the sound file and listen carefully, you can hear that it has three tones.
MATLAB's Fourier transform (fft) returns an array of double complex values (double-
precision complex numbers) that represent the magnitudes and phases of the frequency
components.
fftdata = fft(a);
In MATLAB's workspace window, fftdata values are labeled as type double, giving the
impression that they are real numbers, but this is not the case. In fact, the Fourier transform
produces complex numbers, which you can verify by trying to plot them in MATLAB. The
magnitudes of the complex numbers are given in the Min and Max fields, which is computed by
the abs function. For a complex number , the magnitude is computed as

.
Figure 2.46 Workspace in MATLAB showing values and types of variables currently in memory
To plot the results of the fft function such that the values represent the magnitudes of the
frequency components, we first apply the abs function to fftdata.
fftmag = abs(fftdata);
Let's plot the frequency components to be sure we have what we think we have.
For a sampling rate of sr on an array of sample values of size N, the Fourier transform
returns the magnitudes of frequency components evenly spaced between 0 and sr/2 Hz.
(We'll explain this completely in Chapter 5.) Thus, we want to display frequencies between 0
and sr/2 on the horizontal axis, and only the first sr/2 values from the fftmag vector.
Previous Page Next Page