To be applied to discrete audio data, the Fourier transform must be rendered in a discrete form. This is given in the equation for the discrete Fourier transform below.

**Aside:**

The second form of the discrete Fourier transform given in Equation 2.1, , uses the constant *e*. It is derivable from the first by application of Euler’s identify, . To see the derivation, see (Burg 2008).

Notice that we’ve switched from the function notation used in Equation 2.12 ( and F\left ( k \right )) to array index notation in Equation 2.13 ( F_{n} and f_{k}) to emphasize that we are dealing with an array of discrete audio sample points in the time domain. Casting this equation as an algorithm (Algorithm 2.1) helps us to see how we could turn it into a computer program where the summation becomes a loop nested inside the outer *for* loop.

/*Input:

f, an array of digitized audio samples

N, the number of samples in the array

Note:

Output:

*F*, an array of complex numbers which give the frequency components of the sound given by *f* */

for (*n = 0 to N - 1* )

Each time through the loop, the magnitude and phase of the *n ^{th}* frequency component are computed, . Each is a complex number with a cosine and sine term, the sine term having the factor

*i*in it.

We assume that you're familiar with complex numbers, but if not, a short introduction should be enough so that you can work with the Fourier algorithm.

A complex number takes the form , where . Thus, is a complex number. In this case, *a* is replaced with and *b *with . Handling the complex numbers in an implementation of the Fourier transform is not difficult. Although *i* is an imaginary number, , and you might wonder how you’re supposed to do computation with it, you really don’t have to do anything with it at all except assume it’s there. The summation in the formula can be replaced by a loop that goes from *0 *through *N-1*. Each time through that loop, you add another term from the summation into an accumulating total. You can do this separately for the cosine and sine parts, setting aside *i*. Also, in object-oriented programming languages, you may have a Complex number class to do complex number calculations for you.

The result of the Fourier transform is a list of complex numbers *F*, each of the form , where the magnitude of the frequency component is equal to .

The **inverse Fourier transform** transforms audio data from the frequency domain to the time domain. The inverse discrete Fourier transform is given in Algorithm 6.2.

/*Input:

*F*, an array of complex numbers representing audio data in the frequency domain, the elements represented by the coefficients of their real and imaginary parts, a and b respectively *N*, the number of samples in the array

Note:

Output: *f*, an array of audio samples in the time domain*/

for