Friday, April 2, 2010

Fourier analysis - Sines and integrals (part 3)

We're almost there. Let's talk about two more features of integrals and sine curves. First, (and mom, remember the symbol for "integral" is an s-shaped thing):

∫sin2(x)dx > 0

The integral of the square of the sine function is always positive. This makes sense sort of by definition, because anything squared is always positive, so the negative parts of the sine curve become positive when squared. To illustrate this graphically, I'll show the integral of the sine function:

followed by the integral of the sine squared:

So the integral of the sine times itself is always greater than 0.

Now, the key: the integral of the sine times a sine with a different frequency over an entire period is always equal to 0. Let's slow down and read that one more time, since it's hard to say in a small number of words. The integral of two sine functions with different periods is always 0. To take a specific example, let the second sine function be sin(3x), or one with 3 times the frequency like the green curve here:


The statement I'm making can be expressed symbolically,

∫sin(x)*sin(3x)dx = 0 (integrated over a full period)

How about graphically? Well, here is a plot of sin(x)*sin(3x), and if you look, the green regions are equal in area to the yellow regions, for a total integral of 0.


How about if I show another example, with a sine of four times the frequency.

∫sin(x)*sin(4x)dx = 0 (integrated over a full period)



Again, the areas of the green and yellow regions are equal, and the total integral is 0. Now I haven't proven this is true for all frequencies, but it can be done rigorously (or rigourously); I suppose you might have to take my word on it, but it clearly works for the two examples given.

There's one more theorem that I need to state before finally explaining Fourier analysis, although I hope it won't be too difficult to understand. This is an associative statement, that the integral of the sum of two functions (any functions, let's just call them f(x) and g(x); for example, they could be sin(x) and sin(3x)) is equal to the sum of the integrals done separately:

∫ (f(x) + g(x) )dx = ∫ f(x)dx + ∫ g(x)dx

Let me know if that is not clear, because I'm so excited about the punch line, I'm inclined to skip past some of this stuff.

Finally...


To recap, so far we know the following things:

1. Any periodic shape can be expressed as the sum of sine functions with different frequencies.

2. The integral of a curve is the area under the curve.

3. The integral of a sine times itself is greater than 0.

4. The integral of a sine times a sine with a different frequency is equal to 0.

5. The integral of a sum of functions is equal to the sum of the integrals done independently.

Who can guess what the next step is?

Suppose I have an unknown function (like the A chord from the November post).

By Rule 1, I know that this function can be expressed as the sum of many sine curves of different frequencies. Now, suppose I want to understand what the signal actually is - I want to break it down into the frequencies that went into its construction.

What if I multiplied the unknown function by a sine curve of a given frequency that I know and integrated the result over an entire period? From Rule 4 above, if the frequency I control does not match one of the frequencies that make up the unknown function, the integral will be 0. But if I do find a match, all of a sudden, the integral is positive (by Rule 3) and I've identified one of the component frequencies in my unknown function!

Now, I scan my known frequency over all frequencies, and at the end of the scan, I've found all of the elements that went into making the unknown signal, producing a plot like this:

In this graph, I'm basically plotting the value I get when I integrate the product of the A chord function times a sine with a frequency given by the value on the x-axis. In most situations, I get 0, but when I find a match, the integral (or "power") is positive and I see a spike!

Isn't this exciting? And I'm being completely serious here, none of the vaguely self-mocking tone you might find elsewhere in this blog - I find Fourier analysis completely awesome and elegant and beautiful. Simply using mathematical formalism, we can completely deconstruct a complicated and unknown signal into its individual constituents and understand exactly what is going on. It's stuff like this that makes me love physics and math. If I didn't quite manage to get the beauty and simplicity across in the last few posts, let me know and I'll do what I can to fix it.

Fourier analysis - Sines and Integrals (part 2)

In the last post, I attempted to remind the reader of the definition of a sine curve. I particularly wanted to highlight that the sine function is the mathematical representation of a wave, and since waves are representations of musical notes, a sine curve is also a mathematical representation of a musical note. Those who are familiar with music (or perhaps with my post on the guitar back in November) will be aware that different musical notes are simply waves with different frequencies. That is easily related to the sine curve by multiplying the variable by some number. For example, I've been showing plots of just the basic sine function, y = sin(x) or y = sin(θ). If, however, I decided to plot y = sin(3x), then all of a sudden the frequency of the wave would be tripled, as in this figure:

It is pretty clear that during the time it takes the standard sine function (the red curve) to undergo a full oscillation, the higher frequency curve (the green curve) represented by y = sin(3x) has undergone three full oscillations. Thus, I can represent any of the musical notes using the sine function, simply by changing the multiplication factor. This is essentially what I did in the graphical representations from the November post, by just adding different functions together to produce the sounds I wanted.

We are now ready to talk about the two fundamental keys to Fourier analysis. The first is that any periodic signal can be obtained simply by adding sine curves of different frequencies. To illustrate this, I'm going to draw on everyone's friend, Wikipedia, which has a great entry on Fourier analysis and Fourier series (which does raise the question, "why am I bothering to do this when so many other people have already done it before?" but then this is my blog and I can do it again if I want to. In general, for those who are interested, Wikipedia is really good at mathematical concepts, and I use it as a reference all the time). In the Fourier series article, the unnamed Wikipedia author is exactly illustrating the point I'm making here, that any periodic function can be expressed as the sum of sine curves with different frequencies.

The first example is the square wave. This is a wave that alternates between two values, for example either 1 or -1, so that it looks like a box. The sine function is very smooth, so it may seem hard to believe that you can get a square wave from sines. But, as in the following picture, it doesn't take very many iterations before the sines do a pretty good job at imitating the square wave:


A second example, featuring our favorite gimmick animation, is the the sawtooth wave. Assuming I get this to work right, the animation should show a sawtooth wave along with the sum of sines as each additional sine is added to the total. As with the square wave, the approximation gets pretty good without too many steps:


From here, it should be easy to imagine creating the shapes from my guitar post simply by adding different notes together. The second key will be the subject of the next post.