|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectptolemy.math.SignalProcessing
public class SignalProcessing
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.
Red (cxh) |
Yellow (ctsay) |
Nested Class Summary | |
---|---|
static class |
SignalProcessing.GaussianSampleGenerator
This class generates samples of a Gaussian function with the specified mean and standard deviation. |
static class |
SignalProcessing.PolynomialSampleGenerator
This class generates samples of a polynomial. |
static class |
SignalProcessing.RaisedCosineSampleGenerator
This class generates samples of a raised cosine pulse, or if the excess is zero, a modified sinc function. |
static class |
SignalProcessing.SawtoothSampleGenerator
This class generates samples of a sawtooth wave with the specified period and phase. |
static class |
SignalProcessing.SincSampleGenerator
This class generates samples of a sinc wave with the specified first zero crossing. |
static class |
SignalProcessing.SinusoidSampleGenerator
This class generates samples of a sinusoidal wave. |
static class |
SignalProcessing.SqrtRaisedCosineSampleGenerator
This class generates samples of a square-root raised cosine pulse. |
Field Summary | |
---|---|
private static double[][] |
_CTable
|
private static int |
_FFCTGenLimit
|
private static boolean |
_FORWARD_TRANSFORM
|
private static Complex[][][] |
_IDCTfactors
|
private static boolean |
_INVERSE_TRANSFORM
|
private static double |
_LOG10SCALE
|
private static double |
_LOG2SCALE
|
private static double[][] |
_P1Table
|
private static double[][] |
_P2Table
|
static 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. |
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, w[n] = 2n/M for 0 <= n <= M/2 w[n] = 2 - 2n/M for M/2 < n <= M use this window type. |
static 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. |
static 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. |
static 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. |
static 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. |
static int |
WINDOW_TYPE_RECTANGULAR
To select the rectangular window, w[n] = 1 for 0 <= n <= M use this window type. |
static int |
WINDOW_TYPES
The number of window types that can be generated. |
Constructor Summary | |
---|---|
private |
SignalProcessing()
|
Method Summary | |
---|---|
private static Complex[] |
_checkTransformArgs(Complex[] x,
int order,
boolean inverse)
|
private static double[] |
_checkTransformArgs(double[] x,
int order,
boolean inverse)
|
private static void |
_checkTransformOrder(int order)
|
private static double[] |
_cosDFT(double[] x,
int size,
int order)
|
private static double[] |
_DCT(double[] x,
int size,
int order)
|
private static void |
_FFCTTableGen(int limit)
|
private static double[] |
_sinDFT(double[] x,
int size,
int order)
|
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 Complex[] |
convolve(Complex[] array1,
Complex[] array2)
Return a new array that is the convolution of two complex arrays. |
static double[] |
convolve(double[] array1,
double[] array2)
Return a new array that is the convolution of the two argument 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(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 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 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[] |
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[] |
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[] |
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[] |
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(Complex[] x)
Return a new array of double's 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 double's which is the real part of the inverse FFT of an input array of Complex's. |
static double[] |
IFFTRealOut(double[] x)
Return a new array of double's 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 double's which is the real part of the inverse FFT of an input array of doubles. |
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. the base-2 logarithm of the size. |
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 |
---|
public static final double EPSILON
public static final int DCT_TYPE_NORMALIZED
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
public static final int DCT_TYPE_UNNORMALIZED
public static final int DCT_TYPE_ORTHONORMAL
public static final int DCT_TYPES
public static final int WINDOW_TYPE_RECTANGULAR
w[n] = 1 for 0 <= n <= M
use this window type.
public static final int WINDOW_TYPE_BARTLETT
w[n] = 2n/M for 0 <= n <= M/2
w[n] = 2 - 2n/M for M/2 < n <= M
public static final int WINDOW_TYPE_HANNING
w[n] = 0.5 - 0.5 cos(2 * PI * n / M)
for 0 <= n <= M
public static final int WINDOW_TYPE_HAMMING
w[n] = 0.54 - 0.46 cos(2 * PI * n / M)
for 0 <= n <= M
public static final int WINDOW_TYPE_BLACKMAN
w[n] = 0.42 - 0.5 cos(2 * PI * n /M) +
0.08 cos (4 * PI * n / M)
for 0 <= n <= M
public static final int WINDOW_TYPE_BLACKMAN_HARRIS
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
public static final int WINDOW_TYPES
private static final double[][] _P1Table
private static final double[][] _P2Table
private static final double[][] _CTable
private static int _FFCTGenLimit
private static final Complex[][][] _IDCTfactors
private static final double _LOG10SCALE
private static final double _LOG2SCALE
private static final boolean _FORWARD_TRANSFORM
private static final boolean _INVERSE_TRANSFORM
Constructor Detail |
---|
private SignalProcessing()
Method Detail |
---|
public static final boolean close(double first, double second)
public static final double[] convolve(double[] array1, double[] array2)
array1
- The first array.array2
- The second array.
public static final Complex[] convolve(Complex[] array1, Complex[] array2)
array1
- The first array.array2
- The second array.
public static final double[] DCT(double[] x)
x
- An array of doubles.
public static final double[] DCT(double[] x, int order)
x
- An array of doubles.order
- Log base 2 of the size of the transform.
public static final double[] DCT(double[] x, int order, int type)
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.
DCT_TYPE_NORMALIZED
,
DCT_TYPE_UNNORMALIZED
,
DCT_TYPE_ORTHONORMAL
public static final double decibel(double value)
value
- The value to convert to decibels.toDecibels(double)
public static final double[] decibel(double[] values)
public static final double[] downsample(double[] x, int n)
x
- An array of doubles.n
- An integer specifying the downsampling factor.
public static final double[] downsample(double[] x, int n, int startIndex)
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.
public static final Complex[] FFT(Complex[] x)
x
- An array of complex numbers.
public static final Complex[] FFT(Complex[] x, int order)
x
- An array of complex numbers.order
- The log base 2 of the length of the FFT.
public static final Complex[] FFTComplexOut(Complex[] x)
x
- An array of Complex's.
public static final Complex[] FFTComplexOut(Complex[] x, int order)
x
- An array of Complex's.order
- The base-2 logarithm of the size of the transform.
public static final Complex[] FFTComplexOut(double[] x)
x
- An array of doubles.
public static final Complex[] FFTComplexOut(double[] x, int order)
x
- An array of doubles.order
- The base-2 logarithm of the size of the transform.
public static final double[] FFTImagOut(Complex[] x)
x
- An array of Complex's.
public static final double[] FFTImagOut(Complex[] x, int order)
x
- An array of Complex's.order
- The base-2 logarithm of the size of the transform.
public static final double[] FFTImagOut(double[] x)
x
- An array of doubles.
public static final double[] FFTImagOut(double[] x, int order)
x
- An array of doubles.order
- The base-2 logarithm of the size of the transform.
public static final double[] FFTRealOut(Complex[] x)
x
- An array of Complex's.
public static final double[] FFTRealOut(Complex[] x, int order)
x
- An array of Complex's.order
- The base-2 logarithm of the size of the transform.
public static final double[] FFTRealOut(double[] x)
x
- An array of doubles.
public static final double[] FFTRealOut(double[] x, int order)
x
- An array of doubles.order
- The base-2 logarithm of the size of the transform
public static final double[] IDCT(double[] x)
x
- An array of doubles.
public static final double[] IDCT(double[] x, int order)
x
- An array of doubles.
public static final double[] IDCT(double[] x, int order, int type)
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.
DCT_TYPE_NORMALIZED
,
DCT_TYPE_UNNORMALIZED
,
DCT_TYPE_ORTHONORMAL
public static final Complex[] IFFT(Complex[] x)
x
- An array of complex numbers.
public static final Complex[] IFFT(Complex[] x, int order)
x
- An array of complex numbers.order
- The log base 2 of the length of the FFT.
public static final Complex[] IFFTComplexOut(Complex[] x)
x
- An array of Complex's.
public static final Complex[] IFFTComplexOut(Complex[] x, int order)
x
- An array of Complex's.order
- The base-2 logarithm of the size of the transform.
public static final double[] IFFTRealOut(Complex[] x)
x
- An array of Complex's.
public static final double[] IFFTRealOut(Complex[] x, int order)
x
- An array of Complex's.
public static double[] IFFTRealOut(double[] x)
x
- An array of doubles.
public static double[] IFFTRealOut(double[] x, int order)
x
- An array of doubles.order
- The base-2 logarithm of the size of the transform.
public static final double[] generateBartlettWindow(int length)
length
- The length of the window to be generated.
public static final double[] generateBlackmanWindow(int length)
length
- The length of the window to be generated.
public static final double[] generateBlackmanHarrisWindow(int length)
length
- The length of the window to be generated.
public static final double[] generateGaussianCurve(double standardDeviation, double extent, int length)
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.
public static final double[] generateHammingWindow(int length)
length
- The length of the window to be generated.
public static final double[] generateHanningWindow(int length)
length
- The length of the window to be generated.
public static final double[] generatePolynomialCurve(double[] polynomial, double start, double step, int length)
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.
public static final double[] generateRaisedCosinePulse(double excessBandwidth, double firstZeroCrossing, int length)
sin(PI t/T) cos(x PI t/T) h(t) = ----------- * ----------------- PI t/T 1-(2 x t/T)2where 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.
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.
public static final double[] generateRectangularWindow(int length)
length
- The length of the window to be generated.
public static final double[] generateSqrtRaisedCosinePulse(double excessBandwidth, double firstZeroCrossing, int length)
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.
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.
public static final double[] generateWindow(int length, int windowType)
length
- The length of the window to be generated.windowType
- The type of window to generate.
public static final int nextPowerOfTwo(double x)
x
- A positive real number.
java.lang.IllegalArgumentException
- If the argument is less than
or equal to zero.public static final int order(int size)
size
- The size of the transform.
public static final Complex[] poleZeroToFrequency(Complex[] poles, Complex[] zeros, Complex gain, int numSteps)
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.public static final double[] sampleWave(int length, double startTime, double interval, DoubleUnaryOperation sampleGen)
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.
DoubleUnaryOperation
public static double sawtooth(double period, double phase, double time)
period
- The period of the sawtooth wave.phase
- The phase of the sawtooth wave.time
- The time of the sample.
public static final double sinc(double x)
x
- A number.
public static double square(double period, double phase, double time)
period
- The period of the square wave.phase
- The phase of the square wave.time
- The time of the sample.
public static double triangle(double period, double phase, double time)
period
- The period of the triangle wave.phase
- The phase of the triangle wave.time
- The time of the sample.
public static final double toDecibels(double value)
value
- The value to convert to decibels.public static final double[] unwrap(double[] angles)
angles
- An array of angles.
public static final double[] upsample(double[] x, int n)
x
- The input array of doubles.n
- An integer specifying the upsampling factor.
java.lang.IllegalArgumentException
- If the second argument is not
strictly positive.private static void _checkTransformOrder(int order)
private static double[] _checkTransformArgs(double[] x, int order, boolean inverse)
private static Complex[] _checkTransformArgs(Complex[] x, int order, boolean inverse)
private static double[] _cosDFT(double[] x, int size, int order)
private static double[] _sinDFT(double[] x, int size, int order)
private static double[] _DCT(double[] x, int size, int order)
private static void _FFCTTableGen(int limit)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |