Class FFT

  • java.lang.Object
    • at.ofai.music.audio.FFT


  • public class FFT
    extends java.lang.Object
    Class for computing a windowed fast Fourier transform. Implements some of the window functions for the STFT from Harris (1978), Proc. IEEE, 66, 1, 51-83.
    • Constructor Summary

      Constructors 
      Constructor and Description
      FFT() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static void applyWindow(double[] data, double[] window)
      Applies a window function to an array of data, storing the result in the data array.
      static void fft(double[] re, double[] im, int direction)
      The FFT method.
      static void magnitudeFFT(double[] re)
      Computes the magnitude spectrum of a real sequence (in place).
      static void magnitudePhaseFFT(double[] re, double[] im)
      Computes a complex (or real if im[] == {0,...}) FFT and converts the results to polar coordinates (magnitude and phase).
      static void main(java.lang.String[] args)
      Unit test of the FFT class.
      static double[] makeWindow(int choice, int size, int support)
      Returns an array of values of a normalised smooth window function, as used for performing a short time Fourier transform (STFT).
      static void powerFFT(double[] re)
      Computes the power spectrum of a real sequence (in place).
      static void powerPhaseFFT(double[] re, double[] im)
      Computes a complex (or real if im[] == {0,...}) FFT and converts the results to polar coordinates (power and phase).
      static void powerPhaseIFFT(double[] pow, double[] ph)
      Inline computation of the inverse FFT given spectral input data in polar coordinates (power and phase).
      static void toMagnitude(double[] re)
      Converts a real power sequence from to magnitude representation, by computing the square root of each value.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FFT

        public FFT()
    • Method Detail

      • fft

        public static void fft(double[] re,
                               double[] im,
                               int direction)
        The FFT method. Calculation is inline, for complex data stored in 2 separate arrays. Length of input data must be a power of two.
        Parameters:
        re - the real part of the complex input and output data
        im - the imaginary part of the complex input and output data
        direction - the direction of the Fourier transform (FORWARD or REVERSE)
        Throws:
        java.lang.IllegalArgumentException - if the length of the input data is not a power of 2
      • powerFFT

        public static void powerFFT(double[] re)
        Computes the power spectrum of a real sequence (in place).
        Parameters:
        re - the real input and output data; length must be a power of 2
      • toMagnitude

        public static void toMagnitude(double[] re)
        Converts a real power sequence from to magnitude representation, by computing the square root of each value.
        Parameters:
        re - the real input (power) and output (magnitude) data; length must be a power of 2
      • magnitudeFFT

        public static void magnitudeFFT(double[] re)
        Computes the magnitude spectrum of a real sequence (in place).
        Parameters:
        re - the real input and output data; length must be a power of 2
      • powerPhaseFFT

        public static void powerPhaseFFT(double[] re,
                                         double[] im)
        Computes a complex (or real if im[] == {0,...}) FFT and converts the results to polar coordinates (power and phase). Both arrays must be the same length, which is a power of 2.
        Parameters:
        re - the real part of the input data and the power of the output data
        im - the imaginary part of the input data and the phase of the output data
      • powerPhaseIFFT

        public static void powerPhaseIFFT(double[] pow,
                                          double[] ph)
        Inline computation of the inverse FFT given spectral input data in polar coordinates (power and phase). Both arrays must be the same length, which is a power of 2.
        Parameters:
        pow - the power of the spectral input data (and real part of the output data)
        ph - the phase of the spectral input data (and the imaginary part of the output data)
      • magnitudePhaseFFT

        public static void magnitudePhaseFFT(double[] re,
                                             double[] im)
        Computes a complex (or real if im[] == {0,...}) FFT and converts the results to polar coordinates (magnitude and phase). Both arrays must be the same length, which is a power of 2.
        Parameters:
        re - the real part of the input data and the magnitude of the output data
        im - the imaginary part of the input data and the phase of the output data
      • makeWindow

        public static double[] makeWindow(int choice,
                                          int size,
                                          int support)
        Returns an array of values of a normalised smooth window function, as used for performing a short time Fourier transform (STFT). All functions are normalised by length and coherent gain. More information on characteristics of these functions can be found in F.J. Harris (1978), On the Use of Windows for Harmonic Analysis with the Discrete Fourier Transform, Proceedings of the IEEE, 66, 1, 51-83.
        Parameters:
        choice - the choice of window function, one of the constants defined above
        size - the size of the returned array
        support - the number of non-zero values in the array
        Returns:
        the array containing the values of the window function
      • applyWindow

        public static void applyWindow(double[] data,
                                       double[] window)
        Applies a window function to an array of data, storing the result in the data array. Performs a dot product of the data and window arrays.
        Parameters:
        data - the array of input data, also used for output
        window - the values of the window function to be applied to data
      • main

        public static void main(java.lang.String[] args)
        Unit test of the FFT class. Performs a forward and inverse FFT on a 1MB array of random values and checks how closely the values are preserved.
        Parameters:
        args - ignored