math.fourierTransforms
Class SigProc

java.lang.Object
  extended by math.fourierTransforms.SigProc

public final class SigProc
extends java.lang.Object

Class SigProc contains methods to perform basic signal processing tasks, such as FFTs, convolutions, correlations, etc.

Version:
1.00, 08/15/99
Author:
S. J. Chapman

Field Summary
static boolean NO_NORM
          Constant to specify no cross-correlation normalization.
static boolean NORM
          Constant to specify that cross-correlations should be normalized so that the coefficients at zero lag are exactly 1.0.
 
Constructor Summary
SigProc()
           
 
Method Summary
static double[] calcFreq(double fs, int fftSize)
          This method calculates the frequency associated with each element of the output array from an FFT, taking into account the ambiguities above the Nyquist frequency.
static double[] calcLags(ComplexBusted[] za, ComplexBusted[] zb)
          This method calculates the lags associated with each position in the output of a cross correlation.
static double[] calcLags(double[] xa, double[] xb)
          This method calculates the lags associated with each position in the output of a cross correlation.
static ComplexBusted[] conv(ComplexBusted[] za, ComplexBusted[] zb)
          This method calculates the convolution of two arrays of arbitrary length, returning the result in an array of length za.length + zb.length - 1.
static ComplexBusted[] correl(ComplexBusted[] za, ComplexBusted[] zb)
          This method calculates the cross-correlation between two Complex arrays.
static ComplexBusted[] correl(ComplexBusted[] za, ComplexBusted[] zb, boolean norm)
          This method calculates the cross-correlation between two Complex arrays.
static double[] correl(double[] xa, double[] xb)
          This method calculates the cross-correlation between two double arrays.
static double[] correl(double[] xa, double[] xb, boolean normalize)
          This method calculates the cross-correlation between two double arrays.
static ComplexBusted[] fft(ComplexBusted[] z)
          This method calculates the Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2.
static ComplexBusted[] fft(ComplexBusted[] z, int size)
          This method calculates the Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2.
static ComplexBusted[] fftswap(ComplexBusted[] z)
          This method shifts the output of an FFT so that the dc component appears in the middle of the spectrum.
static double[] fftswap(double[] d)
          This method shifts the output of an FFT so that the dc component appears in the middle of the spectrum.
static ComplexBusted[] ifft(ComplexBusted[] z)
          This method calculates the inverse Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2.
static ComplexBusted[] ifft(ComplexBusted[] z, int size)
          This method calculates the inverse Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2.
static int nextMul(int arraySize)
          This method calculates the power of two greater than or equal to a given input size.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NO_NORM

public static final boolean NO_NORM
Constant to specify no cross-correlation normalization.

See Also:
Constant Field Values

NORM

public static final boolean NORM
Constant to specify that cross-correlations should be normalized so that the coefficients at zero lag are exactly 1.0.

See Also:
Constant Field Values
Constructor Detail

SigProc

public SigProc()
Method Detail

calcFreq

public static double[] calcFreq(double fs,
                                int fftSize)
This method calculates the frequency associated with each element of the output array from an FFT, taking into account the ambiguities above the Nyquist frequency.

Parameters:
fs - The sampling frequency of the input data to the FFT
fftSize - The size of the FFT.
Returns:
an array containing the frequency of each bin (element) in the output from the FFT.

correl

public static ComplexBusted[] correl(ComplexBusted[] za,
                                     ComplexBusted[] zb)
This method calculates the cross-correlation between two Complex arrays. It can also be used to generate the autocorrelation by simply using the same array for both arguments. Note that this algorithm returns the auto- or cross-correlations for all possible lags. It is possible to reduce the computational load if fewer lags are required. For that case, you should consider using a different algorithm.

This algorithm accepts input arrays za and zb of arbitrary length. It returns an array whose length za.length + zb.length - 1. The resulting array has zero lag in the element with index za.length/2 - 1.

This algorithm is designed so that if zb lags za, (is shifted to the right of it), then the peak of the cross correlation function will appear at indices greater than za.length/2 - 1. If zb leads za, then the peak of the cross correlation function will appear at indices less than za.length/2 - 1.

Method calcLags may be used to calculate the lag associated with each position in the output array.

Parameters:
za - Input array 1.
zb - Input array 2.
Returns:
the cross-correlation of za and zb.
See Also:
calcLags(math.complex.ComplexBusted[], math.complex.ComplexBusted[])

correl

public static double[] correl(double[] xa,
                              double[] xb)
This method calculates the cross-correlation between two double arrays. It can also be used to generate the autocorrelation by simply using the same array for both arguments. Note that this algorithm returns the auto- or cross-correlations for all possible lags. It is possible to reduce the computational load if fewer lags are required. For that case, you should consider using a different algorithm.

This algorithm accepts input arrays xa and xb of arbitrary length. It returns an array whose length xa.length + xb.length - 1. The resulting array has zero lag in the element with index xa.length/2 - 1.

This algorithm is designed so that if xb lags xa, (is shifted to the right of it), then the peak of the cross correlation function will appear at indices greater than xa.length/2 - 1. If xb leads xa, then the peak of the cross correlation function will appear at indices less than xa.length/2 - 1.

Method calcLags may be used to calculate the lag associated with each position in the output array.

Parameters:
xa - Input array 1.
xb - Input array 2.
Returns:
the cross-correlation of xa and xb.
See Also:
calcLags(double[],double[])

correl

public static ComplexBusted[] correl(ComplexBusted[] za,
                                     ComplexBusted[] zb,
                                     boolean norm)
This method calculates the cross-correlation between two Complex arrays. It can also be used to generate the autocorrelation by simply using the same array for both arguments. Note that this algorithm returns the auto- or cross-correlations for all possible lags. It is possible to reduce the computational load if fewer lags are required. For that case, you should consider using a different algorithm.

The third input parameter specifies the type of normalization to be applied to the cross correlation. The value NONORM specifies that no normalization should be performed. The value NORM specifies that the output cross correlation should be divided by the constant

     constant = 1 / sqrt( sum(abs(za)^2) * sum(abs(zb)^2) );
 
With this normalization, the peak of the cross correlation function will be 1.0 if and only if the two arrays are identical except for lag. If the two arrays differ, the cross-correlation will be less than 1.0, and the size of the value will be a measure of the similarity between the two arrays.

This algorithm accepts input arrays za and zb of arbitrary length. It returns an array whose length za.length + zb.length - 1. The resulting array has zero lag in the element with index za.length/2 - 1.

This algorithm is designed so that if zb lags za, (is shifted to the right of it), then the peak of the cross correlation function will appear at indices greater than za.length/2 - 1. If zb leads za, then the peak of the cross correlation function will appear at indices less than za.length/2 - 1.

Method calcLags may be used to calculate the lag associated with each position in the output array.

Parameters:
za - Input array 1.
zb - Input array 2.
Returns:
the cross-correlation of za and zb.
See Also:
calcLags(math.complex.ComplexBusted[], math.complex.ComplexBusted[])

correl

public static double[] correl(double[] xa,
                              double[] xb,
                              boolean normalize)
This method calculates the cross-correlation between two double arrays. It can also be used to generate the autocorrelation by simply using the same array for both arguments. Note that this algorithm returns the auto- or cross-correlations for all possible lags. It is possible to reduce the computational load if fewer lags are required. For that case, you should consider using a different algorithm.

The third input parameter specifies the type of normalixation to be applied to the cross correlation. The value NONORM specifies that no normalixation should be performed. The value NORM specifies that the output cross correlation should be divided by the constant

     constant = 1 / sqrt( sum(abs(xa)^2) * sum(abs(xb)^2) );
 
With this normalixation, the peak of the cross correlation function will be 1.0 if and only if the two arrays are identical except for lag. If the two arrays differ, the cross-correlation will be less than 1.0, and the size of the value will be a measure of the similarity between the two arrays.

This algorithm accepts input arrays xa and xb of arbitrary length. It returns an array whose length xa.length + xb.length - 1. The resulting array has zero lag in the element with index xa.length/2 - 1.

This algorithm is designed so that if xb lags xa, (is shifted to the right of it), then the peak of the cross correlation function will appear at indices greater than xa.length/2 - 1. If xb leads xa, then the peak of the cross correlation function will appear at indices less than xa.length/2 - 1.

Method calcLags may be used to calculate the lag associated with each position in the output array.

Parameters:
xa - Input array 1.
xb - Input array 2.
Returns:
the cross-correlation of xa and xb.
See Also:
calcLags(double[],double[])

conv

public static ComplexBusted[] conv(ComplexBusted[] za,
                                   ComplexBusted[] zb)
This method calculates the convolution of two arrays of arbitrary length, returning the result in an array of length za.length + zb.length - 1.

Parameters:
za - Input array 1.
zb - Input array 2.
Returns:
the convolution of za and zb.

fft

public static ComplexBusted[] fft(ComplexBusted[] z)
                           throws math.fourierTransforms.SigProc.InvalidArraySizeException
This method calculates the Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2. If the array length is not a power of two, the method throws an InvalidArraySizeException. This method does not destroy its input data.

Parameters:
z - The input array.
Returns:
the FFT of z.
Throws:
InvalidArraySizeException - if the array length is not a power of 2
math.fourierTransforms.SigProc.InvalidArraySizeException

fft

public static ComplexBusted[] fft(ComplexBusted[] z,
                                  int size)
                           throws math.fourierTransforms.SigProc.InvalidArraySizeException
This method calculates the Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2. If the array length is not a power of two, the method throws an InvalidArraySizeException. This method does not destroy its input data.

Parameters:
z - The input array.
Returns:
the FFT of z.
Throws:
InvalidArraySizeException - if the array length is not a power of 2
math.fourierTransforms.SigProc.InvalidArraySizeException

fftswap

public static ComplexBusted[] fftswap(ComplexBusted[] z)
This method shifts the output of an FFT so that the dc component appears in the middle of the spectrum.

Parameters:
z - The input array.
Returns:
The array with the upper and lower halves of z swapped.

fftswap

public static double[] fftswap(double[] d)
This method shifts the output of an FFT so that the dc component appears in the middle of the spectrum.

Parameters:
d - The input array.
Returns:
The array with the upper and lower halves of d swapped.

ifft

public static ComplexBusted[] ifft(ComplexBusted[] z)
                            throws math.fourierTransforms.SigProc.InvalidArraySizeException
This method calculates the inverse Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2. If the array lengty is not a power of two, the method throws an InvalidArraySizeException. This method does not destroy its input data.

Parameters:
z - The input array.
Returns:
the inverse FFT of z.
Throws:
InvalidArraySizeException - if the array length is not a power of 2
math.fourierTransforms.SigProc.InvalidArraySizeException

ifft

public static ComplexBusted[] ifft(ComplexBusted[] z,
                                   int size)
                            throws math.fourierTransforms.SigProc.InvalidArraySizeException
This method calculates the inverse Fast Fourier Transform of a Complex array, provided that the length of the array is a power of 2. If the array lengty is not a power of two, the method throws an InvalidArraySizeException. This method does not destroy its input data.

Parameters:
z - The input array.
Returns:
the inverse FFT of z.
Throws:
InvalidArraySizeException - if the array length is not a power of 2
math.fourierTransforms.SigProc.InvalidArraySizeException

nextMul

public static int nextMul(int arraySize)
This method calculates the power of two greater than or equal to a given input size.

Parameters:
arraySize - The input size
Returns:
an int containing the required power of two.

calcLags

public static double[] calcLags(double[] xa,
                                double[] xb)
This method calculates the lags associated with each position in the output of a cross correlation.

Parameters:
xa - The input values for array 1
xb - The input values for array 2
Returns:
an array containing the lags associated with each array index in the output of the cross correlation of za and zb

calcLags

public static double[] calcLags(ComplexBusted[] za,
                                ComplexBusted[] zb)
This method calculates the lags associated with each position in the output of a cross correlation.

Parameters:
za - The input values for array 1
zb - The input values for array 2
Returns:
an array containing the lags associated with each array index in the output of the cross correlation of za and zb