Package ptolemy.math

Class SignalProcessing


  • public class SignalProcessing
    extends java.lang.Object
    This class provides signal processing functions. The algorithms for the FFT and DCT are based on the FFCT algorithm described in: Martin Vetterli and Henri J. Nussbaumer."Simple FFT and DCT Algorithms with Reduced Number of Operations". Signal Processing 6 (1984) 267-278.
    Since:
    Ptolemy II 0.2
    Version:
    $Id$
    Author:
    Albert Chen, William Wu, Edward A. Lee, Jeff Tsay, Elaine Cheong
    Pt.AcceptedRating:
    Red (cxh)
    Pt.ProposedRating:
    Yellow (ctsay)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int DCT_TYPE_NORMALIZED
      To select the forward transform :
      static int DCT_TYPE_ORTHONORMAL
      To select the forward transform : N - 1 X[k] = sqrt(2/N) e[k] sum x[n] * cos ((2n + 1)k * PI / 2N) n = 0 and the inverse transform : N - 1 x[n] = sqrt(2/N) sum e[k] X[k] * cos ((2n + 1)k * PI / 2N) k = 0 use this DCT type.
      static int DCT_TYPE_UNNORMALIZED
      To select the forward transform : N - 1 X[k] = sum x[n] * cos ((2n + 1)k * PI / 2N) n = 0 and the inverse transform : N - 1 x[n] = sum X[k] * cos ((2n + 1)k * PI / 2N) k = 0 use this DCT type.
      static int DCT_TYPES
      The number of DCT types supported.
      static double EPSILON
      A small number ( = 1.0e-9).
      static int WINDOW_TYPE_BARTLETT
      To select the Bartlett (triangular) window,
      static int WINDOW_TYPE_BLACKMAN
      To select the Blackman window,
      static int WINDOW_TYPE_BLACKMAN_HARRIS
      To select the 4-term Blackman-Harris window,
      static int WINDOW_TYPE_HAMMING
      To select the Hamming window,
      static int WINDOW_TYPE_HANNING
      To select the Hanning window,
      static int WINDOW_TYPE_RECTANGULAR
      To select the rectangular window,
      static int WINDOW_TYPES
      The number of window types that can be generated.
    • Method Summary

      All Methods Static Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static boolean close​(double first, double second)
      Return true if the first argument is close to the second (within EPSILON, where EPSILON is a static public variable of this class).
      static double[] convolve​(double[] array1, double[] array2)
      Return a new array that is the convolution of the two argument arrays.
      static Complex[] convolve​(Complex[] array1, Complex[] array2)
      Return a new array that is the convolution of two complex arrays.
      static double[] DCT​(double[] x)
      Return a new array of doubles that is the forward, normalized DCT of the input array of doubles.
      static double[] DCT​(double[] x, int order)
      Return a new array of doubles that is the forward, normalized DCT of the input array of doubles.
      static double[] DCT​(double[] x, int order, int type)
      Return a new array of doubles that is the forward DCT of the input array of doubles.
      static double decibel​(double value)
      Deprecated.
      Use toDecibels() instead.
      static double[] decibel​(double[] values)
      Deprecated.
      Use toDecibels() instead.
      static double[] downsample​(double[] x, int n)
      Return a new array that is formed by taking every nth sample starting with the 0th sample, and discarding the rest.
      static double[] downsample​(double[] x, int n, int startIndex)
      Return a new array that is formed by taking every nth sample starting at startIndex, and discarding the samples in between.
      static Complex[] FFT​(Complex[] x)
      Return a new array of complex numbers which is the FFT of an input array of complex numbers.
      static Complex[] FFT​(Complex[] x, int order)
      Return a new array of complex numbers which is the FFT of an input array of complex numbers.
      static Complex[] FFTComplexOut​(double[] x)
      Return a new array of Complex's which is the forward FFT of a real input array of doubles.
      static Complex[] FFTComplexOut​(double[] x, int order)
      Return a new array of Complex's which is the forward FFT of a real input array of doubles.
      static Complex[] FFTComplexOut​(Complex[] x)
      Return a new array of Complex's which is the forward FFT of an input array of Complex's.
      static Complex[] FFTComplexOut​(Complex[] x, int order)
      Return a new array of Complex's which is the forward FFT of an input array of Complex's.
      static double[] FFTImagOut​(double[] x)
      Return a new array of doubles that is the imaginary part of the FFT of the real input array of doubles.
      static double[] FFTImagOut​(double[] x, int order)
      Return a new array of doubles that is the imaginary part of the FFT of the real input array of doubles.
      static double[] FFTImagOut​(Complex[] x)
      Return a new array of doubles which is the imaginary part of the FFT of an input array of Complex's.
      static double[] FFTImagOut​(Complex[] x, int order)
      Return a new array of doubles which is the imaginary part of the FFT of an input array of Complex's.
      static double[] FFTRealOut​(double[] x)
      Return a new array of doubles that is the real part of the FFT of the real input array of doubles.
      static double[] FFTRealOut​(double[] x, int order)
      Return a new array of doubles that is the real part of the FFT of the real input array of doubles.
      static double[] FFTRealOut​(Complex[] x)
      Return a new array of doubles which is the real part of the forward FFT of an input array of Complex's.
      static double[] FFTRealOut​(Complex[] x, int order)
      Return a new array of doubles which is the real part of the forward FFT of an input array of Complex's.
      static double[] generateBartlettWindow​(int length)
      Return a new array that is filled with samples of a Bartlett window of a specified length.
      static double[] generateBlackmanHarrisWindow​(int length)
      Return a new array that is filled with samples of a Blackman Harris window of a specified length.
      static double[] generateBlackmanWindow​(int length)
      Return a new array that is filled with samples of a Blackman window of a specified length.
      static double[] generateGaussianCurve​(double standardDeviation, double extent, int length)
      Return an array with samples the Gaussian curve (the "bell curve").
      static double[] generateHammingWindow​(int length)
      Return a new array that is filled with samples of a Hamming window of a specified length.
      static double[] generateHanningWindow​(int length)
      Return a new array that is filled with samples of a Hanning window of a specified length.
      static double[] generatePolynomialCurve​(double[] polynomial, double start, double step, int length)
      Return an array with samples a polynomial curve.
      static double[] generateRaisedCosinePulse​(double excessBandwidth, double firstZeroCrossing, int length)
      Return an array containing a symmetric raised-cosine pulse.
      static double[] generateRectangularWindow​(int length)
      Return a new array that is filled with samples of a rectangular window of a specified length.
      static double[] generateSqrtRaisedCosinePulse​(double excessBandwidth, double firstZeroCrossing, int length)
      Return an array containing a symmetric raised-cosine pulse.
      static double[] generateWindow​(int length, int windowType)
      Return a new array that is filled with samples of a window of a specified length and type.
      static double[] IDCT​(double[] x)
      Return a new array of doubles that is the inverse, normalized DCT of the input array of doubles.
      static double[] IDCT​(double[] x, int order)
      Return a new array of doubles that is the inverse, normalized DCT of the input array of doubles, using the specified order.
      static double[] IDCT​(double[] x, int order, int type)
      Return a new array of doubles that is the inverse DCT of the input array of doubles.
      static Complex[] IFFT​(Complex[] x)
      Return a new array of complex numbers which is the inverse FFT of an input array of complex numbers.
      static Complex[] IFFT​(Complex[] x, int order)
      Return a new array of complex numbers which is the inverse FFT of an input array of complex numbers.
      static Complex[] IFFTComplexOut​(Complex[] x)
      Return a new array of Complex's which is the inverse FFT of an input array of Complex's.
      static Complex[] IFFTComplexOut​(Complex[] x, int order)
      Return a new array of Complex's which is the forward FFT of an input array of Complex's.
      static double[] IFFTRealOut​(double[] x)
      Return a new array of doubles which is the real part of the inverse FFT of an input array of doubles.
      static double[] IFFTRealOut​(double[] x, int order)
      Return a new array of doubles which is the real part of the inverse FFT of an input array of doubles.
      static double[] IFFTRealOut​(Complex[] x)
      Return a new array of doubles which is the real part of the inverse FFT of an input array of Complex's.
      static double[] IFFTRealOut​(Complex[] x, int order)
      Return a new array of doubles which is the real part of the inverse FFT of an input array of Complex's.
      static int nextPowerOfTwo​(double x)
      Return the next power of two larger than the argument.
      static int order​(int size)
      Return the "order" of a transform size, i.e.
      static Complex[] poleZeroToFrequency​(Complex[] poles, Complex[] zeros, Complex gain, int numSteps)
      Given an array of pole locations, an array of zero locations, and a gain term, return frequency response specified by these.
      static double[] sampleWave​(int length, double startTime, double interval, DoubleUnaryOperation sampleGen)
      Return a new array that is filled with samples of a waveform of a specified length.
      static double sawtooth​(double period, double phase, double time)
      Return a sample of a sawtooth wave with the specified period and phase at the specified time.
      static double sinc​(double x)
      Return sin(x)/x, the so-called sinc function.
      static double square​(double period, double phase, double time)
      Return a sample of a square wave with the specified period and phase at the specified time.
      static double toDecibels​(double value)
      Return the value of the argument in decibels, which is defined to be 20*log10(z), where z is the argument.
      static double triangle​(double period, double phase, double time)
      Return a sample of a triangle wave with the specified period and phase at the specified time.
      static double[] unwrap​(double[] angles)
      Return a new array that is constructed from the specified array by unwrapping the angles.
      static double[] upsample​(double[] x, int n)
      Return a new array that is the result of inserting (n-1) zeroes between each successive sample in the input array, resulting in an array of length n * L, where L is the length of the original array.
      • Methods inherited from class java.lang.Object

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

      • EPSILON

        public static final double EPSILON
        A small number ( = 1.0e-9). This number is used by algorithms to detect whether a double is close to zero.
        See Also:
        Constant Field Values
      • DCT_TYPE_NORMALIZED

        public static final int DCT_TYPE_NORMALIZED
        To select the forward transform :

        N - 1
        X[k] = e[k] sum x[n] * cos ((2n + 1)k * PI / 2N)
        n = 0

        and the inverse transform : N - 1
        x(n) = (2/N) sum e(k) X[k] * cos ((2n + 1)k * PI / 2N)
        k = 0

        use this DCT type.
        See Also:
        Constant Field Values
      • DCT_TYPE_UNNORMALIZED

        public static final int DCT_TYPE_UNNORMALIZED
        To select the forward transform : N - 1 X[k] = sum x[n] * cos ((2n + 1)k * PI / 2N) n = 0 and the inverse transform : N - 1 x[n] = sum X[k] * cos ((2n + 1)k * PI / 2N) k = 0 use this DCT type. This is the definition of the DCT used by MPEG.
        See Also:
        Constant Field Values
      • DCT_TYPE_ORTHONORMAL

        public static final int DCT_TYPE_ORTHONORMAL
        To select the forward transform : N - 1 X[k] = sqrt(2/N) e[k] sum x[n] * cos ((2n + 1)k * PI / 2N) n = 0 and the inverse transform : N - 1 x[n] = sqrt(2/N) sum e[k] X[k] * cos ((2n + 1)k * PI / 2N) k = 0 use this DCT type. This is the definition of the DCT used in Matlab.
        See Also:
        Constant Field Values
      • DCT_TYPES

        public static final int DCT_TYPES
        The number of DCT types supported.
        See Also:
        Constant Field Values
      • WINDOW_TYPE_RECTANGULAR

        public static final int WINDOW_TYPE_RECTANGULAR
        To select the rectangular window,

        w[n] = 1 for 0 ≤ n ≤ M

        use this window type.
        See Also:
        Constant Field Values
      • WINDOW_TYPE_BARTLETT

        public static final int WINDOW_TYPE_BARTLETT
        To select the Bartlett (triangular) window,

        w[n] = 2n/M for 0 ≤ n ≤ M/2
        w[n] = 2 - 2n/M for M/2 < n ≤ M

        use this window type.
        See Also:
        Constant Field Values
      • WINDOW_TYPE_HANNING

        public static final int WINDOW_TYPE_HANNING
        To select the Hanning window,

        w[n] = 0.5 - 0.5 cos(2 * PI * n / M)
        for 0 ≤ n ≤ M

        use this window type.
        See Also:
        Constant Field Values
      • WINDOW_TYPE_HAMMING

        public static final int WINDOW_TYPE_HAMMING
        To select the Hamming window,

        w[n] = 0.54 - 0.46 cos(2 * PI * n / M)
        for 0 ≤ n ≤ M

        use this window type.
        See Also:
        Constant Field Values
      • WINDOW_TYPE_BLACKMAN

        public static final int WINDOW_TYPE_BLACKMAN
        To select the Blackman window,

        w[n] = 0.42 - 0.5 cos(2 * PI * n /M) +
        0.08 cos (4 * PI * n / M)
        for 0 ≤ n ≤ M

        use this window type.
        See Also:
        Constant Field Values
      • WINDOW_TYPE_BLACKMAN_HARRIS

        public static final int WINDOW_TYPE_BLACKMAN_HARRIS
        To select the 4-term Blackman-Harris window,

        w[n] = 0.35875 - 0.48829 cos(2 * PI * n /M) +
        0.14128 cos (4 * PI * n / M) - 0.01168 cos(6 * PI * n / M)
        for 0 ≤ n ≤ M

        use this window type.
        See Also:
        Constant Field Values
      • WINDOW_TYPES

        public static final int WINDOW_TYPES
        The number of window types that can be generated.
        See Also:
        Constant Field Values
    • Method Detail

      • close

        public static final boolean close​(double first,
                                          double second)
        Return true if the first argument is close to the second (within EPSILON, where EPSILON is a static public variable of this class).
      • convolve

        public static final double[] convolve​(double[] array1,
                                              double[] array2)
        Return a new array that is the convolution of the two argument arrays. The length of the new array is equal to the sum of the lengths of the two argument arrays minus one. Note that convolution is the same as polynomial multiplication. If the two argument arrays represent the coefficients of two polynomials, then the resulting array represents the coefficients of the product polynomial.
        Parameters:
        array1 - The first array.
        array2 - The second array.
        Returns:
        A new array of doubles.
      • convolve

        public static final Complex[] convolve​(Complex[] array1,
                                               Complex[] array2)
        Return a new array that is the convolution of two complex arrays. The length of the new array is equal to the sum of the lengths of the two argument arrays minus one. Note that some authors define complex convolution slightly differently as the convolution of the first array with the conjugate of the second. If you need to use that definition, then conjugate the second array before calling this method. Convolution defined as we do here is the same as polynomial multiplication. If the two argument arrays represent the coefficients of two polynomials, then the resulting array represents the coefficients of the product polynomial.
        Parameters:
        array1 - The first array.
        array2 - The second array.
        Returns:
        A new array of complex numbers.
      • DCT

        public static final double[] DCT​(double[] x)
        Return a new array of doubles that is the forward, normalized DCT of the input array of doubles. This method automatically computes the order of the transform based on the length of the input array. It is equivalent to DCT(x, order, DCT_TYPE_NORMALIZED), where 2^order is the smallest power of two greater than or equal to the length of the specified array. The length of the result is 2^order.
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of doubles, with length 2^order.
      • DCT

        public static final double[] DCT​(double[] x,
                                         int order)
        Return a new array of doubles that is the forward, normalized DCT of the input array of doubles. This method is equivalent to DCT(x, order, DCT_TYPE_NORMALIZED).
        Parameters:
        x - An array of doubles.
        order - Log base 2 of the size of the transform.
        Returns:
        A new array of doubles, with length 2^order.
      • DCT

        public static final double[] DCT​(double[] x,
                                         int order,
                                         int type)
        Return a new array of doubles that is the forward DCT of the input array of doubles. See the DCT_TYPE_XXX constants for documentation of the exact formula, which depends on the type.
        Parameters:
        x - An array of doubles.
        order - Log base 2 of the size of the transform.
        type - The type of DCT, which is one of DCT_TYPE_NORMALIZED, DCT_TYPE_UNNORMALIZED, or DCT_TYPE_ORTHONORMAL.
        Returns:
        A new array of doubles, with length 2^order.
        See Also:
        DCT_TYPE_NORMALIZED, DCT_TYPE_UNNORMALIZED, DCT_TYPE_ORTHONORMAL
      • decibel

        @Deprecated
        public static final double decibel​(double value)
        Deprecated.
        Use toDecibels() instead.
        Return the value of the argument in decibels, which is defined to be 20*log10(z), where z is the argument. Note that if the input represents power, which is proportional to a magnitude squared, then this should be divided by two to get 10*log10(z).
        Parameters:
        value - The value to convert to decibels.
        See Also:
        toDecibels(double)
      • decibel

        @Deprecated
        public static final double[] decibel​(double[] values)
        Deprecated.
        Use toDecibels() instead.
        Return a new array the value of the argument array in decibels, using the previous decibel() method. You may wish to combine this with DoubleArrayMath.limit().
      • downsample

        public static final double[] downsample​(double[] x,
                                                int n)
        Return a new array that is formed by taking every nth sample starting with the 0th sample, and discarding the rest. This method calls : downsample(x, n, 0)
        Parameters:
        x - An array of doubles.
        n - An integer specifying the downsampling factor.
        Returns:
        A new array of doubles of length = floor(L / n), where L is the size of the input array.
      • downsample

        public static final double[] downsample​(double[] x,
                                                int n,
                                                int startIndex)
        Return a new array that is formed by taking every nth sample starting at startIndex, and discarding the samples in between.
        Parameters:
        x - An array of doubles.
        n - An integer specifying the downsampling factor.
        startIndex - An integer specifying the index of sample at which to start downsampling. This integer must be between 0 and L - 1, where L is the size of the input array.
        Returns:
        A new array of doubles of length = floor((L - startIndex) / n), where L is the size of the input array.
      • FFT

        public static final Complex[] FFT​(Complex[] x)
        Return a new array of complex numbers which is the FFT of an input array of complex numbers. The order of the transform is the next power of two greater than the length of the argument. The input is zero-padded if it does not match this length.
        Parameters:
        x - An array of complex numbers.
        Returns:
        The FFT of the argument.
      • FFT

        public static final Complex[] FFT​(Complex[] x,
                                          int order)
        Return a new array of complex numbers which is the FFT of an input array of complex numbers. The input is zero-padded if it does not match the length.
        Parameters:
        x - An array of complex numbers.
        order - The log base 2 of the length of the FFT.
        Returns:
        The FFT of the argument.
      • FFTComplexOut

        public static final Complex[] FFTComplexOut​(Complex[] x)
        Return a new array of Complex's which is the forward FFT of an input array of Complex's. This method automatically computes the order of the transform based on the length of the input array, and calls FFTComplexOut(x, order).
        Parameters:
        x - An array of Complex's.
        Returns:
        A new array of Complex's.
      • FFTComplexOut

        public static final Complex[] FFTComplexOut​(Complex[] x,
                                                    int order)
        Return a new array of Complex's which is the forward FFT of an input array of Complex's.
        Parameters:
        x - An array of Complex's.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of Complex's.
      • FFTComplexOut

        public static final Complex[] FFTComplexOut​(double[] x)
        Return a new array of Complex's which is the forward FFT of a real input array of doubles. This method automatically computes the order of the transform based on the length of the input array, and calls FFTComplexOut(x, order).
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of Complex's.
      • FFTComplexOut

        public static final Complex[] FFTComplexOut​(double[] x,
                                                    int order)
        Return a new array of Complex's which is the forward FFT of a real input array of doubles. This method is half as expensive as computing the FFT of a Complex array.
        Parameters:
        x - An array of doubles.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of Complex's.
      • FFTImagOut

        public static final double[] FFTImagOut​(Complex[] x)
        Return a new array of doubles which is the imaginary part of the FFT of an input array of Complex's. This method automatically computes the order of the transform based on the length of the input array, and calls FFTImagOut(x, order).
        Parameters:
        x - An array of Complex's.
        Returns:
        A new array of doubles.
      • FFTImagOut

        public static final double[] FFTImagOut​(Complex[] x,
                                                int order)
        Return a new array of doubles which is the imaginary part of the FFT of an input array of Complex's. This method is half as expensive as computing both the real and imaginary parts of an FFT on a array of Complex's. It is especially useful when the output is known to be purely imaginary.
        Parameters:
        x - An array of Complex's.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of doubles.
      • FFTImagOut

        public static final double[] FFTImagOut​(double[] x)
        Return a new array of doubles that is the imaginary part of the FFT of the real input array of doubles. This method is half as expensive as computing both the real and imaginary parts of a FFT on a real array. It is especially useful when the output is known to be purely imaginary (input is odd). This method automatically computes the order of the transform based on the length of the input array, and calls: FFTImagOut(x, order)
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of doubles.
      • FFTImagOut

        public static final double[] FFTImagOut​(double[] x,
                                                int order)
        Return a new array of doubles that is the imaginary part of the FFT of the real input array of doubles. This method is half as expensive as computing both the real and imaginary parts of a FFT on a real array. It is especially useful when the output is known to be purely imaginary (input is odd).
        Parameters:
        x - An array of doubles.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of doubles.
      • FFTRealOut

        public static final double[] FFTRealOut​(Complex[] x)
        Return a new array of doubles which is the real part of the forward FFT of an input array of Complex's. This method automatically computes the order of the transform based on the length of the input array, and calls : FFTRealOut(x, order)
        Parameters:
        x - An array of Complex's.
        Returns:
        A new array of doubles.
      • FFTRealOut

        public static final double[] FFTRealOut​(Complex[] x,
                                                int order)
        Return a new array of doubles which is the real part of the forward FFT of an input array of Complex's. This method is half as expensive as computing both the real and imaginary parts of an FFT on a array of Complex's. It is especially useful when the output is known to be purely real.
        Parameters:
        x - An array of Complex's.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of doubles.
      • FFTRealOut

        public static final double[] FFTRealOut​(double[] x)
        Return a new array of doubles that is the real part of the FFT of the real input array of doubles. This method automatically computes the order of the transform based on the length of the input array, and calls : FFTRealOut(x, order).
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of doubles.
      • FFTRealOut

        public static final double[] FFTRealOut​(double[] x,
                                                int order)
        Return a new array of doubles that is the real part of the FFT of the real input array of doubles. This method is half as expensive as computing both the real and imaginary parts of an FFT on a real array. It is especially useful when the output is known to be purely real (input is even).
        Parameters:
        x - An array of doubles.
        order - The base-2 logarithm of the size of the transform
        Returns:
        A new array of doubles.
      • IDCT

        public static final double[] IDCT​(double[] x)
        Return a new array of doubles that is the inverse, normalized DCT of the input array of doubles. This method automatically computes the order of the transform based on the length of the input array. It is equivalent to IDCT(x, order, DCT_TYPE_NORMALIZED), where 2^order is the next power of two larger than or equal to the length of the specified array. The returned array has length 2^order.
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of doubles with length 2^order.
      • IDCT

        public static final double[] IDCT​(double[] x,
                                          int order)
        Return a new array of doubles that is the inverse, normalized DCT of the input array of doubles, using the specified order. The length of the DCT is 2^order. This is equivalent to IDCT(x, order, DCT_TYPE_NORMALIZED).
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of doubles with length 2^order.
      • IDCT

        public static final double[] IDCT​(double[] x,
                                          int order,
                                          int type)
        Return a new array of doubles that is the inverse DCT of the input array of doubles. See the DCT_TYPE_XXX constants for documentation of the exact formula, which depends on the type.
        Parameters:
        x - An array of doubles.
        order - The base-2 logarithm of the size of the transform.
        type - The type of IDCT, which is one of DCT_TYPE_NORMALIZED, DCT_TYPE_UNNORMALIZED, or DCT_TYPE_ORTHONORMAL.
        Returns:
        A new array of doubles with length 2^order.
        See Also:
        DCT_TYPE_NORMALIZED, DCT_TYPE_UNNORMALIZED, DCT_TYPE_ORTHONORMAL
      • IFFT

        public static final Complex[] IFFT​(Complex[] x)
        Return a new array of complex numbers which is the inverse FFT of an input array of complex numbers. The length of the result is the next power of two greater than the length of the argument. The input is zero-padded if it does not match this length.
        Parameters:
        x - An array of complex numbers.
        Returns:
        The inverse FFT of the argument.
      • IFFT

        public static final Complex[] IFFT​(Complex[] x,
                                           int order)
        Return a new array of complex numbers which is the inverse FFT of an input array of complex numbers. The input is zero-padded if it does not match this length.
        Parameters:
        x - An array of complex numbers.
        order - The log base 2 of the length of the FFT.
        Returns:
        The inverse FFT of the argument.
      • IFFTComplexOut

        public static final Complex[] IFFTComplexOut​(Complex[] x)
        Return a new array of Complex's which is the inverse FFT of an input array of Complex's. This method automatically computes the order of the transform based on the length of the input array.
        Parameters:
        x - An array of Complex's.
        Returns:
        A new array of Complex's.
      • IFFTComplexOut

        public static final Complex[] IFFTComplexOut​(Complex[] x,
                                                     int order)
        Return a new array of Complex's which is the forward FFT of an input array of Complex's.
        Parameters:
        x - An array of Complex's.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of Complex's.
      • IFFTRealOut

        public static final double[] IFFTRealOut​(Complex[] x)
        Return a new array of doubles which is the real part of the inverse FFT of an input array of Complex's. This is less than half as expensive as computing both the real and imaginary parts. It is especially useful when it is known that the output is purely real. This method automatically computes the order of the transform based on the length of the input array, and calls : IFFTRealOut(x, order)
        Parameters:
        x - An array of Complex's.
        Returns:
        A new array of doubles.
      • IFFTRealOut

        public static final double[] IFFTRealOut​(Complex[] x,
                                                 int order)
        Return a new array of doubles which is the real part of the inverse FFT of an input array of Complex's. This method is less than half as expensive as computing both the real and imaginary parts of an IFFT of an array of Complex's. It is especially useful when it is known that the output is purely real.
        Parameters:
        x - An array of Complex's.
        Returns:
        A new array of doubles.
      • IFFTRealOut

        public static double[] IFFTRealOut​(double[] x)
        Return a new array of doubles which is the real part of the inverse FFT of an input array of doubles. This method automatically computes the order of the transform based on the length of the input array, and calls : IFFTRealOut(x, order)
        Parameters:
        x - An array of doubles.
        Returns:
        A new array of doubles.
      • IFFTRealOut

        public static double[] IFFTRealOut​(double[] x,
                                           int order)
        Return a new array of doubles which is the real part of the inverse FFT of an input array of doubles. This method is less than half as expensive as computing the real part of an IFFT of an array of Complex's. It is especially useful when both the input and output are known to be purely real.
        Parameters:
        x - An array of doubles.
        order - The base-2 logarithm of the size of the transform.
        Returns:
        A new array of doubles.
      • generateBartlettWindow

        public static final double[] generateBartlettWindow​(int length)
        Return a new array that is filled with samples of a Bartlett window of a specified length. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        Returns:
        A new array of doubles.
      • generateBlackmanWindow

        public static final double[] generateBlackmanWindow​(int length)
        Return a new array that is filled with samples of a Blackman window of a specified length. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        Returns:
        A new array of doubles.
      • generateBlackmanHarrisWindow

        public static final double[] generateBlackmanHarrisWindow​(int length)
        Return a new array that is filled with samples of a Blackman Harris window of a specified length. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        Returns:
        A new array of doubles.
      • generateGaussianCurve

        public static final double[] generateGaussianCurve​(double standardDeviation,
                                                           double extent,
                                                           int length)
        Return an array with samples the Gaussian curve (the "bell curve"). The returned array is symmetric. E.g., to get a Gaussian curve that extends out to "four sigma," then the extent argument should be 4.0.
        Parameters:
        standardDeviation - The standard deviation.
        extent - The multiple of the standard deviation out to which the curve is plotted.
        length - The length of the returned array.
        Returns:
        An array that contains samples of the Gaussian curve.
      • generateHammingWindow

        public static final double[] generateHammingWindow​(int length)
        Return a new array that is filled with samples of a Hamming window of a specified length. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        Returns:
        A new array of doubles.
      • generateHanningWindow

        public static final double[] generateHanningWindow​(int length)
        Return a new array that is filled with samples of a Hanning window of a specified length. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        Returns:
        A new array of doubles.
      • generatePolynomialCurve

        public static final double[] generatePolynomialCurve​(double[] polynomial,
                                                             double start,
                                                             double step,
                                                             int length)
        Return an array with samples a polynomial curve. The first argument is an array giving the coefficients of the polynomial, starting with the constant term, followed by the linear term, followed by the quadratic term, etc. The remaining coefficients determine the points at which the polynomial curve is sampled. That is, they determine the values of the polynomial variable at which the polynomial is evaluated.
        Parameters:
        polynomial - An array with polynomial coefficients.
        start - The point of the first sample.
        step - The step size between samples.
        length - The length of the returned array.
        Returns:
        An array that contains samples of a polynomial curve.
      • generateRaisedCosinePulse

        public static final double[] generateRaisedCosinePulse​(double excessBandwidth,
                                                               double firstZeroCrossing,
                                                               int length)
        Return an array containing a symmetric raised-cosine pulse. This pulse is widely used in communication systems, and is called a "raised cosine pulse" because the magnitude its Fourier transform has a shape that ranges from rectangular (if the excess bandwidth is zero) to a cosine curved that has been raised to be non-negative (for excess bandwidth of 1.0). The elements of the returned array are samples of the function:
                 sin(PI t/T)   cos(x PI t/T)
          h(t) = ----------- * -----------------
                  PI t/T      1-(2 x t/T)2
          
        where x is the excess bandwidth and T is the number of samples from the center of the pulse to the first zero crossing. The samples are taken with a sampling interval of 1.0, and the returned array is symmetric. With an excessBandwidth of 0.0, this pulse is a sinc pulse.
        Parameters:
        excessBandwidth - The excess bandwidth.
        firstZeroCrossing - The number of samples from the center of the pulse to the first zero crossing.
        length - The length of the returned array.
        Returns:
        An array containing a symmetric raised-cosine pulse.
      • generateRectangularWindow

        public static final double[] generateRectangularWindow​(int length)
        Return a new array that is filled with samples of a rectangular window of a specified length. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        Returns:
        A new array of doubles.
      • generateSqrtRaisedCosinePulse

        public static final double[] generateSqrtRaisedCosinePulse​(double excessBandwidth,
                                                                   double firstZeroCrossing,
                                                                   int length)
        Return an array containing a symmetric raised-cosine pulse. This pulse is widely used in communication systems, and is called a "raised cosine pulse" because the magnitude its Fourier transform has a shape that ranges from rectangular (if the excess bandwidth is zero) to a cosine curved that has been raised to be non-negative (for excess bandwidth of 1.0). The elements of the returned array are samples of the function:
                   4 x(cos((1+x)PI t/T) + T sin((1-x)PI t/T)/(4x t/T))
          h(t) =  ---------------------------------------------------
                        PI sqrt(T)(1-(4 x t/T)2)
          

        where x is the the excess bandwidth. This pulse convolved with itself will, in principle, be equal to a raised cosine pulse. However, because the pulse decays rather slowly for low excess bandwidth, this ideal is not closely approximated by short finite approximations of the pulse. The samples are taken with a sampling interval of 1.0, and the returned array is symmetric. With an excessBandwidth of 0.0, this pulse is a scaled sinc pulse.

        Parameters:
        excessBandwidth - The excess bandwidth.
        firstZeroCrossing - The number of samples from the center of the pulse to the first zero crossing.
        length - The length of the returned array.
        Returns:
        A new array containing a square-root raised-cosine pulse.
      • generateWindow

        public static final double[] generateWindow​(int length,
                                                    int windowType)
        Return a new array that is filled with samples of a window of a specified length and type. Throw an IllegalArgumentException if the length is less than 1 or the window type is unknown.
        Parameters:
        length - The length of the window to be generated.
        windowType - The type of window to generate.
        Returns:
        A new array of doubles.
      • nextPowerOfTwo

        public static final int nextPowerOfTwo​(double x)
        Return the next power of two larger than the argument.
        Parameters:
        x - A positive real number.
        Throws:
        java.lang.IllegalArgumentException - If the argument is less than or equal to zero.
      • order

        public static final int order​(int size)
        Return the "order" of a transform size, i.e. the base-2 logarithm of the size. The order will be rounded up to the nearest integer. If the size is zero or negative, throw an IllegalArgumentException.
        Parameters:
        size - The size of the transform.
        Returns:
        The order of the transform.
      • poleZeroToFrequency

        public static final Complex[] poleZeroToFrequency​(Complex[] poles,
                                                          Complex[] zeros,
                                                          Complex gain,
                                                          int numSteps)
        Given an array of pole locations, an array of zero locations, and a gain term, return frequency response specified by these. This is calculated by walking around the unit circle and forming the product of the distances to the zeros, dividing by the product of the distances to the poles, and multiplying by the gain. The length of the returned array is numSteps.
        Parameters:
        poles - An array of pole locations.
        zeros - An array of zero locations.
        gain - A complex gain.
        numSteps - The number of samples in the returned frequency response.
      • sampleWave

        public static final double[] sampleWave​(int length,
                                                double startTime,
                                                double interval,
                                                DoubleUnaryOperation sampleGen)
        Return a new array that is filled with samples of a waveform of a specified length. The waveform is sampled with starting at startTime, at a sampling period of interval.
        Parameters:
        length - The number of samples to generate.
        startTime - The corresponding time for the first sample.
        interval - The time between successive samples. This may be negative if the waveform is to be reversed, or zero if the array is to be filled with a constant.
        sampleGen - A DoubleUnaryOperation.
        Returns:
        A new array of doubles.
        See Also:
        DoubleUnaryOperation
      • sawtooth

        public static double sawtooth​(double period,
                                      double phase,
                                      double time)
        Return a sample of a sawtooth wave with the specified period and phase at the specified time. The returned value ranges between -1.0 and 1.0. The phase is given as a fraction of a cycle, typically ranging from 0.0 to 1.0. If the phase is 0.0 or 1.0, the wave begins at zero with a rising slope. If it is 0.5, it begins at the falling edge with value -1.0. If it is 0.25, it begins at +0.5. Throw an exception if the period is less than or equal to 0.
        Parameters:
        period - The period of the sawtooth wave.
        phase - The phase of the sawtooth wave.
        time - The time of the sample.
        Returns:
        A double in the range -1.0 to +1.0.
      • sinc

        public static final double sinc​(double x)
        Return sin(x)/x, the so-called sinc function. If the argument is very close to zero, significant quantization errors may result (exactly 0.0 is OK, since this just returns 1.0).
        Parameters:
        x - A number.
        Returns:
        The sinc function.
      • square

        public static double square​(double period,
                                    double phase,
                                    double time)
        Return a sample of a square wave with the specified period and phase at the specified time. The returned value is 1 or -1. A sample that falls on the rising edge of the square wave is assigned value +1. A sample that falls on the falling edge is assigned value -1. The phase is given as a fraction of a cycle, typically ranging from 0.0 to 1.0. If the phase is 0.0 or 1.0, the square wave begins at the start of the +1.0 phase. If it is 0.5, it begins at the start of the -1.0 phase. If it is 0.25, it begins halfway through the +1.0 portion of the wave. Throw an exception if the period is less than or equal to 0.
        Parameters:
        period - The period of the square wave.
        phase - The phase of the square wave.
        time - The time of the sample.
        Returns:
        +1.0 or -1.0.
      • triangle

        public static double triangle​(double period,
                                      double phase,
                                      double time)
        Return a sample of a triangle wave with the specified period and phase at the specified time. The returned value ranges between -1.0 and 1.0. The phase is given as a fraction of a cycle, typically ranging from 0.0 to 1.0. If the phase is 0.0 or 1.0, the wave begins at zero with a rising slope. If it is 0.5, it begins at zero with a falling slope. If it is 0.25, it begins at +1.0. Throw an exception if the period is less than or equal to 0.
        Parameters:
        period - The period of the triangle wave.
        phase - The phase of the triangle wave.
        time - The time of the sample.
        Returns:
        A number in the range -1.0 to +1.0.
      • toDecibels

        public static final double toDecibels​(double value)
        Return the value of the argument in decibels, which is defined to be 20*log10(z), where z is the argument. Note that if the input represents power, which is proportional to a magnitude squared, then this should be divided by two to get 10*log10(z).
        Parameters:
        value - The value to convert to decibels.
      • unwrap

        public static final double[] unwrap​(double[] angles)
        Return a new array that is constructed from the specified array by unwrapping the angles. That is, if the difference between successive values is greater than PI in magnitude, then the second value is modified by multiples of 2PI until the difference is less than or equal to PI. In addition, the first element is modified so that its difference from zero is less than or equal to PI in magnitude. This method is used for generating more meaningful phase plots.
        Parameters:
        angles - An array of angles.
        Returns:
        A new array of phase-unwrapped angles.
      • upsample

        public static final double[] upsample​(double[] x,
                                              int n)
        Return a new array that is the result of inserting (n-1) zeroes between each successive sample in the input array, resulting in an array of length n * L, where L is the length of the original array. Throw an exception for n ≤ 0.
        Parameters:
        x - The input array of doubles.
        n - An integer specifying the upsampling factor.
        Returns:
        A new array of doubles.
        Throws:
        java.lang.IllegalArgumentException - If the second argument is not strictly positive.