The FFT: Real, Imaginary, Magnitude, Phase
Weve mentioned that most FFTs return their information in the form of a complex pair: a real part and an imaginary part. Theres obviously a lot more to say about that, but it gets pretty mathematical, and well let you explore that on your own.
But we've been talking about the data that an FFT returns more in terms of the amplitude (or magnitude) and phase of a given frequency bin. What is important in this discussion is that you understand more or less how to get from the complex number pair to the magnitude/phase pair, which is generally, for computer music, more useful. Youll probably want to manipulate amplitudes and phases, not complex numbers.
It turns out not to be so hard. Remember that an imaginary number, written in the form:
can be represented in a two-dimensional space as follows:
The length of the line from the origin to the point (a, b) is the magnitude specific to the spectral bin. That is, it's the amount of energy at that frequency. Its just the hypotenuse of the right triangle drawn to the x axis. The equation for it is very simple:
(NEED TO PUT IN THE EQUATION HERE)
M = sqrt(a^^2 : b^^2)
which you will recognize as the equation for the length of the hypotenuse of a right triangle (called the Pythagorean Theorem. One of our authors, who has a morbid side to him or her, points out that one of Pythagoras's students, Hippasus,was drowned (!) for proposing that this theorem led to the existence of irrational numbers like the square root of 2).
That was pretty easy, right? Deriving the phase from the complex pair is a little trickier. What we want to find is the angle made by that point to the x-axis. Remember that phases are expressed in radians, 0 - 2 , and that a complete circle is 2 . We call that angle THETA. So, if we can find THETA in radians, were done (we have the phase of that bin).
It turns out that were looking for an angle which is the ratio of the opposite side to the adjacent side (remember: SOH CAH TOA: sin, opposite over hypotenuse; cosine, adjacent over hypotenuse; tangent, opposite over adjacent). We want the angle whose tangent is the y-value (opposite) over the x-value (adjacent), or b/a. Thats called the arctangent, and is written as tan-1. So the equation for calculating phase is:
(DAN NEEDS TO PUT IN EQUATION HERE)
theta = tan- 1 (b/a)
There, that wasnt so painful, was it. And knowing this will make you really popular.
|