bafoontecha.com

theory meets application.

11 Dec, 2008

A Visual Guide to Fourier Transforms

Posted by: peddamat In: Articles

Sinusoids As Notes

Sinusoids As Notes

Introduction

My studies as an engineer and scientist have led me to the following conclusion: all that is beautiful and worth observing in the physical world is the result of the movement of electrons. It is a secondary source of pleasure that the preferred motion of electrons is sinusoidal in nature.

This may seem a dry, robotic statement; something not unexpected from the lips of an engineer. However, I submit the following evidence:

The sounds that bring you pleasure are in part caused by the sinusoidal motion of electrons in a wire, which in turn induce the sinusoidal displacement of a cone in your speaker, pressing and pulling against molecules of gas, which rhythmically jostle each other until gyrating against the drums of your ears. The movement of electrons, torturously expressed through space and time, brings a tap to your step, and a bob to your head.

The light that brings sight to your eyes is caused by the sinusoidal vibration of electrons in a tube above your head, or a curved bit of tungsten, or many moments ago, on the photosphere of the sun.

In fact, the very machine that you are reading this on (or in?) is merely a massive conduit for electrons, which mindlessly cascade through an untold multitude of channels, to and from your battery pack.

I could go on, but hopefully I have increased your appreciation for electrons from a ground state.

So, what does all this baroque exposition have to do with Fourier Analysis? I am glad you asked.

Motion, especially the motion of electrons, is the source of all signals. Without motion, without movement, the universe would be cold and gray. A curious fact about signals, specifically ones in the real-world, is that they are all made of the same thing. From the most beautiful of arias, to the screech of nails against blackboard; from the matrix of colors composing your screen, to the motion of a photon to your eye; all of these things can be represented by signals, and all of these signals are created from sinusoids.

If atoms are the building blocks of matter, then sinusoids are the building blocks of signals, and this is where Fourier Analysis plays a part.

Fourier Analysis is akin to a solvent for signals. It allows one to reverse engineer a signal; decompose it into a string of sinusoids. It then allows one to take these multitudes of sinusoids and precisely recreate the original signal. All in one deft stroke.

And in an ode to the potency of mathematical notation, the entire process can be described by a single expression:

Eq. 1: Fourier Transform

To the mathematically averse, the above equation may seem a bit overwhelming, however, using Euler’s relation, we may unfurl it into a more manageable and understandable form.

Eq. 2: Fourier Transform (long form)

Eq. 2: Fourier Transform (long form)

Remember, f(x) is any real-world signal, which as previously stated, can be decomposed into a series of sinusoids, sines and cosines, added together.

With that in mind, what equation 1 and 2 say is the following:

We have a function f(w), with a single real-number input variable, w, which represents frequency. The output of this function is two numbers, one real and one imaginary, which tell us how much, if any, of f(x) is composed of a cosine and sine of frequency w.

Things still may be a bit hazy, so I made the following videos to help bring the point home. Click on the poster frame to get the video to play. Feel free to download a copy, or watch them in HD on Youtube.

An overview of sinusoids

It’s critical to have an intuitive understanding of sinusoids. As an audio-enthusiast, I prefer to think of sinusoids in the context of audio; as auditory tones or notes. Out of the three parameters which allow a sinusoid to be manipulated, two of them, frequency and amplitude, have immediately understandable connotations.

Frequency is the “pitch” that you hear. Low frequencies are deep rumbles, and high frequencies are tinny squeaks. Amplitude is the “loudness” or “volume” of the sinusoid. Interestingly, human ears are fairly insensitive to differences in phase. However, phase differences between ears plays an important part in signal localization.

Due to the properties of linearity and time-invariance, sinusoids can be added to create more complex waveforms. In fact, they can be added together to create any real-world signal, which you will soon see.




Download: [Low Quality] [Youtube (HD)]

A look at how sinusoids interact

The entirety of Fourier Analysis relies on a singular property of sinusoids: how they behave when you multiply (or mix) them. More specifically, what happens when a sinusoid of a given phase and frequency is multiplied by another sinusoid of identical phase and frequency.

To illustrate this behavior, we create two plots. The plot on the left shows two sinusoids, a fixed-frequency “reference” signal and a variable-frequency “probe” signal, to be mixed. The plot on the right shows the product of the two sinusoids. By sweeping the frequency of the “probe” signal, we can observe how the product waveform responds as the probe frequency approaches and matches the frequency of the reference signal.

We see that when the probe signal frequency matches the reference signal frequency, the product waveform moves completely above the x-axis, i.e. becomes completely positive. This behavior, and the fact that it occurs only when the two signals match, is the reason Fourier Analysis works so beautifully.




Download: [Low Quality] [Youtube (HD)]

The magnitude plot

The magnitude plot is a logical progression from the behavior we witnessed in the previous section. As we sweep the probe signal frequency, we notice that the product waveform transitions from being both positive and negative to strictly positive when probe frequency matches the reference frequency. This implies that the integral of the product waveform, aka the area under the curve, will reflect this behavior.

The magnitude plot is a plot of the integral for the range of frequencies the probe signal sweeps. A peak in the magnitude plot occurs when the probe signal frequency matches the reference signal frequency.




Download: [Low Quality] [Youtube (HD)]

Why the peak occurs

There are a number of ways to explain the behavior of the product waveform. The most straight-forward way is mathematical, however, a visual explanation offers some intuitive insight.

When the phases and frequencies match perfectly, the sinusoids overlay in a way that the positive peaks multiply together and the negative troughs cancel with each other resulting in a waveform that is completely positive. The integral of a waveform that is completely positive will always be a number greater than zero.

Conversely, when the phases and frequencies are mismatched, the product waveform is both positive and negative. The integral of a waveform that is both positive and negative has the potential to be less than, equal to, or greater than zero.




Download: [Low Quality] [Youtube (HD)]

The second parameter

The success of our technique, so far, has depended on the phase of the reference and probe signal being identical, or zero. What happens if the phase of the signals are mismatched?




Download: [Low Quality] [Youtube (HD)]

The effect of phase

Visually, we saw that Fourier Analysis works because the probe and reference signals overlay in a way that troughs “cancel-out” resulting in a waveform that is completely positive. However, a phase offset destroys this symmetry and breaks things.

To illustrate what happens visually, let’s create 5 new magnitude plots, varying the phase of the reference signal from 0 to PI/2 evenly between them. Why only from 0 to PI/2? It has to do with symmetry, but I’ll save that for later.

From the other videos, we know what happens when the phase offset of the reference frequency is 0. The magnitude plot has a peak that occurs where the probe and reference frequencies match. Again, this makes it a powerful heuristic for discovering the frequency composition of the reference signal.

When the phase offset of the reference signal is PI/20, the magnitude plot appears slightly skewed to the right. More importantly, the peak no longer coincides with the reference signal frequency. In fact, using our previous heuristic, we would get an inaccurate measure of the reference signal frequency. Still, things aren’t so bad, let’s see what happens as the phase offset increases.

With a phase offset of PI/10, the magnitude plot continues to skew to the right. With an offset of 3*PI/20, things only get worse, the skewing continues. However, an interesting thing is happening with our product waveform. With a phase offset of 0, the product waveform was positive, but as the offset increases, the product waveform slowly creeps downwards.

With a phase offset of PI/2, things have gotten quite dismal indeed. Our beautiful magnitude plot is badly skewed, our product waveform has centered itself on the x-axis, and even worse, it is symmetric. It seems that Fourier Analysis has failed us, and is only useful for the small subset of reference frequencies with zero phase offsets.

Is there a remedy to this situation? Yes, and for that we require a new way of thinking about sinusoids, and, a bit of linear algebra.




Download: [Low Quality] [Youtube (HD)]

A bit of linear algebra




Download: [Low Quality] [Youtube (HD)]

Another way to represent sinusoids




Download: [Low Quality]

The final stretch




Download: [Low Quality]

An application of Fourier Analysis

This is an illustration of Fourier Analysis in action. I’ve decomposed a guitar loop into its constituent sinusoids and added them up to recreate the original waveform. Listen to how the audio sounds muted at first, as if you’ve turned down the treble. As higher frequency sinusoids are added, the details start to emerge; each iteration forming a consecutively crisper sound. In effect, this is what happens in your stereo when you adjust the equalizer; the analog/digital filters in the signal pathway selectively mask certain frequencies of the input signal.

I find it quite beautiful to observe how large scale structure evolves from pure, sinusoidal tones. Every sound you hear, every song on your iPod, can be created by adding together pure tones with varying amplitudes and phases. Think deeply about that statement. The interface between mathematics and the physical world is an amazing thing.




Download: [Low Quality] [Youtube (HD)]

Project Files

I developed these videos using Adobe After Effects for compositing and Matlab for the plot generation. All the resources to make this tutorial are freely available to you. Feel free to mash them up as you like.

Matlab file: FFT_tutgen.m [20KB]
After Effects Project: coming soon (looking for server space)

Detritus

Before switching to Matlab, I worked out my ideas in Mathematica. Here are a few scraps left over from the brainstorming process.

Observing the behavior of f(?)

Observing the behavior of f(w)

Observing the behavior of f(?) as the phase of the input signal is varied

Observing the behavior of f(w) as the phase of the input signal is varied

No Responses to "A Visual Guide to Fourier Transforms"

Comment Form