Package at.ofai.music.audio
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.
-
-
Field Summary
Fields Modifier and Type Field and Description static int
BH3
used inmakeWindow(int,int,int)
to specify a 61-dB 3-sample Blackman-Harris window functionstatic int
BH3MIN
used inmakeWindow(int,int,int)
to specify a minimum 3-sample Blackman-Harris window functionstatic int
BH4
used inmakeWindow(int,int,int)
to specify a 74-dB 4-sample Blackman-Harris window functionstatic int
BH4MIN
used inmakeWindow(int,int,int)
to specify a minimum 4-sample Blackman-Harris window functionstatic int
FORWARD
used infft(double[], double[], int)
to specify a forward Fourier transformstatic int
GAUSS
used inmakeWindow(int,int,int)
to specify a Gaussian window functionstatic int
HAMMING
used inmakeWindow(int,int,int)
to specify a Hamming window functionstatic int
RECT
used inmakeWindow(int,int,int)
to specify a rectangular window functionstatic int
REVERSE
used infft(double[], double[], int)
to specify an inverse Fourier transform
-
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.
-
-
-
Field Detail
-
BH3
public static final int BH3
used inmakeWindow(int,int,int)
to specify a 61-dB 3-sample Blackman-Harris window function- See Also:
- Constant Field Values
-
BH3MIN
public static final int BH3MIN
used inmakeWindow(int,int,int)
to specify a minimum 3-sample Blackman-Harris window function- See Also:
- Constant Field Values
-
BH4
public static final int BH4
used inmakeWindow(int,int,int)
to specify a 74-dB 4-sample Blackman-Harris window function- See Also:
- Constant Field Values
-
BH4MIN
public static final int BH4MIN
used inmakeWindow(int,int,int)
to specify a minimum 4-sample Blackman-Harris window function- See Also:
- Constant Field Values
-
FORWARD
public static final int FORWARD
used infft(double[], double[], int)
to specify a forward Fourier transform- See Also:
- Constant Field Values
-
GAUSS
public static final int GAUSS
used inmakeWindow(int,int,int)
to specify a Gaussian window function- See Also:
- Constant Field Values
-
HAMMING
public static final int HAMMING
used inmakeWindow(int,int,int)
to specify a Hamming window function- See Also:
- Constant Field Values
-
RECT
public static final int RECT
used inmakeWindow(int,int,int)
to specify a rectangular window function- See Also:
- Constant Field Values
-
REVERSE
public static final int REVERSE
used infft(double[], double[], int)
to specify an inverse Fourier transform- See Also:
- Constant Field Values
-
-
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 dataim
- the imaginary part of the complex input and output datadirection
- 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 dataim
- 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 dataim
- 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 abovesize
- the size of the returned arraysupport
- 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 outputwindow
- 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
-
-