Digital Sound & Music: Concepts, Applications, & Science, Chapter 2, last updated 6/25/2013

45

figure;

freqs = [0: (sr/2)-1];

plot(freqs, fftmag(1:sr/2));

When you do this, you'll see that all the frequency components are way over on the left side of

the graph. Since we know our frequency components

should be 110 Hz, 220 Hz, and 440 Hz, we might as well

look at only the first, say, 600 frequency components so

that we can see the results better. One way to zoom in on

the frequency response graph is to use the zoom tool in the

graph window, or you can reset the axis properties in the

command window, as follows.

axis([0 600 0 8000]);

This yields the frequency response graph for our composite

wave, which shows the three frequency components.

Figure 2.47 Frequency response graph for a 3-component wave

To get the phase response graph, we need to extract the phase information from the

fftdata. This is done with the angle function. We leave that as an exercise.

Let's try the Fourier transform on a more complex sound wave – a sound file that we read

in.

y = wavread('HornsE04Mono.wav');

As before, you can get the Fourier transform with the fft function.

fftdata = fft(y);

You can then get the magnitudes of the frequency components and generate a frequency

response graph from this.

fftmag = abs(fftdata);

Aside: If we would zoom in

more closely at each of these

spikes at frequencies 110, 220,

and 440 Hz, we would see that

they are not perfectly horizontal

lines. The "imperfect" results of

the FFT will be discussed later in

the sections on FFT windows and

windowing functions.