This is a little testing & debug suite of the FFT tools I'd written for Amit Pitaru's SONIA library. The actual FFT code is based on C implementations of Nullsoft's VMS and a paper by ProSoniq founder Stephan M. Sprenger.

This code does not actually use SONIA nor does it perform the FFT on a real audio signal (ie. your sound input). Instead it synthesizes a sine wave made of 4 oscillators all linked to a common base frequency which can be controlled by the mouse position: X position changes the overall pitch, Y controls the amplitude of the signal.

The original signal is shown in shades of red. Before the FFT is computed, we apply a low pass filter to the signal. Its cutoff frequency is currently set at 18.6kHz with a strength of 60dB and a bandwidth of 3.6kHz. The filtered signal is shown as orange overlay and you can see that the filter manipulated the beginning of the sound buffer and caused a general delay of the waveform.

The filter is used to ensure ultrasonic frequencies and their distortions are being removed from the spectrum. Frequencies higher than the Nyquist threshold can unfortunately not be filtered out and will appear in the spectrum mirrored. For example, a frequency of 25kHz cannot be replicated when using the standard sampling frequency of 44.1kHz. According to Nyquist's law the highest possible frequency in this case is 22.05kHz (equals 1/2 of 44.1kHz). When computing the FFT of this 25kHz signal the result will be distorted and a peak actually appears at:

22.05 - 25 + 22.05 = 19.1 kHz

You can see this distortion effect happening by slowing moving the mouse to the far right. First the highest (rightmost) of the four peaks will slowly lose on gain and disappear from the spectrum (shown as the yellow bars at the bottom). This is the result of the low pass filter in action. Moving the mouse further to the right, the same peak suddenly re-appears but is now actually moving to the left, lower frequencies again.

The spectrum itself represents the distribution of the energy potential of all frequencies in the analysed signal. The resolution of the spectrum is variable and depends on the size of the time window used. In this example the window size is 1024 samples long and results in 512 frequency bands in the spectrum. This has to do with the fact that we only make use of the first half of the spectrum, which represents the range between 0 and the Nyquist frequency (here 22.05kHz). The 2nd half of the spectral data is discarded as it represents the so called "imaginary" part which is a mirrored version of the data contained in the lower half. As this example is using a fairly simple waveform, you can clearly see the four peaks of the contributing frequencies.

The white bell curve overlay shows the graph of an amplification function which is applied to the 1024 samples before they're sent to the FFT function. Again, this works similar to a filter and is used to avoid potential distortions caused by ultra-high frequencies which are introduced by only analysing a tiny chunk of the signal. By reducing the impact of samples on both sides of the time window (at the beginning and end) the resulting spectrum will be more accurate in the low and mid range parts.

Naturally lower frequencies tend to be more energetic than higher ones, so to balance the resulting spectrum values and to help their further analysis, you can choose to apply an Equalizer function which slightly amplifies spectral values at higher frequencies. This amplification factor is shown as the turquoise curve at the bottom of the applet.

Source code
Built with Processing