Class FFT


public class FFT extends Analyzer
This is a Fast Fourier Transform (FFT) analyzer. It calculates the normalized power spectrum of an audio stream the moment it is queried with the analyze() method.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    float[]
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    FFT(PApplet parent)
     
    FFT(PApplet parent, int bands)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    float[]
     
    float[]
    analyze(float[] target)
    Calculates the current frequency spectrum of the input signal.
    static float[]
    analyzeSample(float[] sample, float[] target)
    Calculates the frequency spectrum of a given audio sample and returns an array of magnitudes, one for each frequency band.
    static float[]
    analyzeSample(float[] sample, int numBands)
     

    Methods inherited from class processing.sound.Analyzer

    input

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • spectrum

      public float[] spectrum
  • Constructor Details

    • FFT

      public FFT(PApplet parent)
    • FFT

      public FFT(PApplet parent, int bands)
      Parameters:
      parent - typically use "this"
      bands - number of frequency bands for the FFT. This parameter needs to be a power of 2 (e.g. 16, 32, 64, 128, ...). The default is 512.
  • Method Details

    • analyze

      public float[] analyze()
    • analyze

      public float[] analyze(float[] target)
      Calculates the current frequency spectrum of the input signal. Returns an array with as many elements as this FFT analyzer's number of frequency bands. The frequency associated with each band of the spectrum is frequency = binIndex * sampleRate / (2*numBands).
      The values of the resulting array show the amplitudes of pure tone components contained in the signal. If the signal is a sine with an amplitude of 1, the spectrum will have an absolute value of 1 (0 dB) at the frequency of the sine. For complex real-world signals the spectrum values will be much lower and usually don't exceed 0.05.
      Parameters:
      target - if provided, writes the frequency spectrum into the given array. The array needs to have as many elements as this FFT analyzer's number of frequency bands.
    • analyzeSample

      public static float[] analyzeSample(float[] sample, float[] target)
      Calculates the frequency spectrum of a given audio sample and returns an array of magnitudes, one for each frequency band. The frequency associated with each band of the spectrum is frequency = binIndex * sampleRate / (2*numBands).
      This version is intended to be used in non-real time processing, particularly when you are creating an animation in non-real time and want to get the FFT for a particular chunk of an audio sample. For stereo samples, you can call this function once for each channel, so you can display the left and right fft values separately.
      The values of the resulting array show the amplitudes of pure tone components contained in the signal. If the signal is a sine with an amplitude of 1, the spectrum will have an absolute value of 1 (0 dB) at the frequency of the sine. For complex real-world signals the spectrum values will be much lower and usually don't exceed 0.05.
      Parameters:
      sample - an array of numbers that describe the waveform to be analyzed
      numBands - the number of fft bands requested. Must be a power of 2 (one of 2, 4, 8, 16 etc.)
      target - array that the computed spectrum will be written to. The FFT will compute as many frequency bands as the length of this array, which must be a power of 2 (2, 4, 8, 16 etc.)
      Returns:
      The frequency spectrum of the given audio sample. The array has as many elements as this FFT analyzer's number of frequency bands.
    • analyzeSample

      public static float[] analyzeSample(float[] sample, int numBands)