Understanding and Using the FFT in Reaktor
In this tutorial, I’ll explain what the FFT (Fast Fourier Transform) is, and how to use it properly in Reaktor. We’ll finish up by designing a simple novel filter with a fully adjustable spectrum.
WHAT IS THE FFT?
The FFT is a mathematical process that transforms a signal into it’s spectral components. In our case, this means an audio signal but there are other uses as well. You may have heard it said that any periodic signal can be made by adding together sine waves – see, for example, our series on Additive Synthesis.
What the FFT does, then is take a sound, and return to the user information about the sine waves that make up that sound. Those sine waves can be manipulated however the programmer likes, then sent through an inverse FFT (iFFT) to get back the original signal. If none of the data is changed between the FFT and the iFFT, the output will be identical to the input, just delayed (since both the FFT and iFFT add latency to a signal).
The math to implement the FFT is not actually as tough as many people make it out to be, but the algorithm is tedious to program in Reaktor due to the precense of many iterative processes. Fortunately, we can save ourselves the trouble, as there are already two packages out there for using FFT in Reaktor. The first is FFT Macros by Robin Davies, and the second is EzFFT by Gabriel Mulzer. For the purpose of this tutorial, I’ll be using the EzFFT package.
HOW DOES IT WORK?
To work properly, the FFT takes a number of samples from an audio signal – a 256 point FFT will require 256 data points from the signal (the number of samples will always be a power of 2 – 256 equals 2 to the 8th power).
What gets returned for the user is a stream of complex numbers called bins. In EzFFT, the number of bins you get back is a part of the name of each FFT macro (IE, EzFFT 256 returns 256 bins, with an index from 0 to 255 – these are output in incrementing order). It’s interesting to note that these are actually 512 point FFTs, as I’ll explain below.
The bins returned by FFT are spread evenly across the frequency spectrum, from 0Hz up to the sampling frequency (44.1KHz by default in most applications). However, a digital audio signal can only accurately depict a signal up to half of it’s sampling frequency, called the Nyquist Limit. This means the second half of the bins returned actually ends up mirroring the first half, containing no information that the user does not already have.
Robin Davies’ FFT package outputs these redundant values, EzFFT does not, which is why I prefer EzFFT.
USING THE DATA
Okay, so we have a stream of complex numbers coming at us:
Here, Idx is the index, or bin number, and the ‘r’ and ‘i’ outputs stand for the Real, and Imaginary components of the complex number.
In case the concept of imaginary or complex numbers are doing your head in, don’t worry, we rarely need to actually use them. Instead, we can translate them using the Vec2Pol macro (part of the FFT package):
This converts from vector (cartesian) coordinates to polar coordinates. The polar coordinates leave us with two values, amplitude and phase, that describe the component sine waves of our original audio signal.
Now, we can use any means we want to manipulate the sine wave data, then we take that data and convert it back to a complex number, and run it thru the iFFT to convert back to an audio stream.
MAKING A SIMPLE FILTER
FFT can be used for a variety of tasks from convolution reverb, to vocoding and more. The easiest thing however, is to create a filter. There are very simple examples available in the EzFFT package, so let’s get a little (but not much) more complicated.
The first thing I’m going to do is make an Audio Table that can hold 256 values. The values range from -96 to 0 and represent the decibels to reduce the amplitude by for each FFT bin. When you set the Table to draw mode (by right-clicking on the Table in Panel view and selecting the Table Draw Mode option), you can draw in a frequency response for the filter using your mouse.
When we receive a new bin Idx from our FFT, we can read out that index from the Audio Table, and use the data there to shape the amplitude of the FFT bins:
Next, all we need to do is translate back to an audio signal using the iFFT:
And done! Note that FFT can cause distortion of lower frequency elements. The more bins you use, the less chance there is of this problem.
I know that FFT can be an intimidating subject, often surrounded by an unnecessary amount of jargon, like the rest of DSP. Hopefully this tutorial makes it seem a little bit easier to understand. If there is interest in more material on the FFT, please let me know, there’s a lot to cover!