Saturday, November 7, 2009

Fourier analysis 2 - More complicated sound waves

I imagine the discussion in the previous entry seems pretty boring. It was really easy to tell apart the A note from the white noise, both by sound and by looking at the graphical representation. Things get more complicated however when we add more notes to make a chord or a complicated piece of music. For example, a simple A chord consists of three notes - A, C# and E. The nearest C# to the standard A has a frequency of 523.25 Hz while the nearest E has a frequency of 659.26. Here's what that sounds like on my guitar (it's sort of fun posting videos of my guitar online), followed by the graphical image:


One can still see the oscillatory behavior, but things aren't quite as clean as they were when I was plotting just the simple A note.

Now, what happens if I play a full A chord by adding A notes from the next two octaves up and another C# as well?

You can still see a few clear features, but overall it doesn't look nearly as obvious that this is an actual chord. In reality, no sound wave is perfectly free of noise either. We are all familiar with static in our speakers and acoustic reflections tend to add noise to the wave as well. In general, external sources of static add white noise on top of the underlying wave. In such a situation, it can be impossible to see the wave underneath the noise just by eye.

This is where Fourier analysis comes in. Fourier analysis is a mathematical method that can decompose signals like the ones shown in the various pictures into their constituent waves. By Fourier analyzing a pulse, we can find out how much of each pulse is contributed by a wave of a particular frequency. For example, returning to the simple A note, the entire pulse is a wave of 440 Hz. Therefore, the Fourier transform of that plot should provide us with a peak at 440 Hz, and nothing else. Here's what the Fourier transform of the A note looks like:

The Fourier transform has picked out the signal at 440 Hz, and shown that it is the only component there. What about white noise, where there is no dominant frequency component? Fourier analysis can find that as well.

And finally, where Fourier analysis really shines is when the signal is so complicated that one couldn't possibly tell apart all its constituents by eye. For example, look at the Fourier decomposition of the full A chord - all of the 6 notes are clearly broken out in the decomposition and we can understand exactly what went into the making of that sound.

I have one last example, just because I think this is so cool. I made a signal of 12 semi-random frequencies, with a little white noise added. The first plot is what they look like in the time domain (i.e. when you plot the amplitude of the sound as a function of time). There's no real pattern there that I can see. But when I plot the Fourier transform, there they all are. It's like magic. But it's not, it's just math, and I'll try to explain it qualitatively in the next post.

Fourier analysis 1 - Sound waves

First, I need to apologize for the lack of activity on this blog, and regretfully state that the relative dearth of new posts will likely continue for another few months. I'm at the point of my career when I try to graduate and get a job for next year, and between these two activities I don't have much time for posting to this blog. I do plan on continuing it, but it will of necessity be sporadic for a few more months.

Now that that is out of the way, I want to discuss Fourier analysis, which I mentioned at the end of the last post (over two months ago). One theme that may have come through to someone reading this blog since the beginning is the ubiquity of "waves" in physics. When discussing the Doppler effect back in March, I used sound as an example (the police siren) before moving to light. I want to do the same thing now. Sound is a pressure wave that moves through the air and is interpreted by our ears. Just as the color of light is determined by its frequency, the pitch of sound is also determined by the frequency of the sound wave. People who play music will be very familiar with this - the root A note, for example, is a sound wave with a frequency of 440 Hz (if I haven't used this unit before, a Hz is just inverse seconds. So 440 Hz means that the wave oscillates 440 times per second). Let's use the power of modern computers to show a video of me playing the A on my guitar:

The idea here is fairly simple. The guitar is tuned so that plucking the string makes it oscillate at 440 Hz, creating the note that we hear.

On the opposite end of the spectrum from a perfectly pitched musical note is "white noise." We all know what white noise is, it's static, something with no discernable pattern. It's called white because the color white is a combination of all colors. White noise is a combination of all frequencies. For a lovely example of white noise, one can go to

The point of this is that waves are very well understood mathematically. Therefore, we can very easily represent these sounds with a mathematical expression. For example, the A note I played in the video can be represented as an oscillating wave with frequency 440 Hz, and it would look something like the drawing to the right. There's clearly a pattern in there of the appropriate frequency (I also added an overall envelope to describe the starting and stopping of the pulse, but that's not really important for this discussion).

White noise looks like the next plot, and there is no pattern there.

In part 2, I'll talk about what happens when you add more tones to form a chord (or an orchestra) or what happens when you add noise to a tone.