本文整理汇总了Java中org.apache.commons.math.transform.FastFourierTransformer类的典型用法代码示例。如果您正苦于以下问题:Java FastFourierTransformer类的具体用法?Java FastFourierTransformer怎么用?Java FastFourierTransformer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastFourierTransformer类属于org.apache.commons.math.transform包,在下文中一共展示了FastFourierTransformer类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transform
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
@Override
public Double[] transform(Double value) {
window.transform(value);
double[] valuesArray = new double[window.size()] ;
int i = 0;
for (Double v: window.values()) {
valuesArray[i++] = v;
}
Complex[] complexFFTResult = new FastFourierTransformer().transform(valuesArray);
// only the first half of the FFT is reasonable, the other half is just a mirror of the first
int resultLength = (complexFFTResult.length / 2) + 1;
Double[] fftResult = new Double[resultLength];
for (i = 0; i < resultLength; i++) {
fftResult[i] = complexFFTResult[i].abs()/origSize;
}
return fftResult;
}
示例2: testDoubleValues
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
public void testDoubleValues(String title, Transformer<Double, double[]> tr) {
FastFourierTransformer apache = new FastFourierTransformer();
CLQueue queue = tr.getContext() == null ? null : tr.getContext().createDefaultOutOfOrderQueueIfPossible();
for (double[] data : createTestDoubleInputs()) {
double[] expected = complexToInterleavedDoubles(apache.transform(interleavedDoublesToComplex(data)));
assertArrayEquals(title + " (n = " + (data.length / 2) + ")", expected, tr.transform(queue, data, false), precisionDouble);
}
}
示例3: testFloatValues
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
public void testFloatValues(String title, Transformer<Float, float[]> tr) {
FastFourierTransformer apache = new FastFourierTransformer();
CLQueue queue = tr.getContext() == null ? null : tr.getContext().createDefaultOutOfOrderQueueIfPossible();
for (double[] data : createTestDoubleInputs()) {
float[] dataf = toFloat(data);
double[] expected = complexToInterleavedDoubles(apache.transform(interleavedDoublesToComplex(data)));
assertArrayEquals(title + " (n = " + (data.length / 2) + ")", toFloat(expected), tr.transform(queue, dataf, false), precisionFloat);
}
}
示例4: MelFrequencyCC
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
/**
* Default constructor. Leaves object ready for processing whole audio
* samples with {@link #processAll(double)} or single windows with
* {@link #processWindow(double)}. Window size must be larger than 32 and a
* power of two.
*
* @param sampleRate
* @param windowSize
* @param numberCoefficients
* @param minFreq
* @param maxFreq
* @param numberFilters
*/
public MelFrequencyCC(int sampleRate, int windowSize,
int numberCoefficients, int minFreq, int maxFreq, int numberFilters) {
this.sampleRate = sampleRate;
this.windowSize = windowSize;
this.numberCoefficients = numberCoefficients;
this.minFreq = minFreq;
this.maxFreq = maxFreq;
this.numberFilters = numberFilters;
if (numberCoefficients != numberFilters) {
throw new IllegalArgumentException(
"number of mel coefficients must be equal to number of mel filters");
}
// derived stuff
hopSize = windowSize / 2;
// frequency resolution, one element of the
// fft will correspond to this many hertz (?)
baseFreq = sampleRate / windowSize;
buffer = new double[windowSize];
filterBank = new MelFilterBank(sampleRate, windowSize, minFreq,
maxFreq, numberFilters);
fft = new FastFourierTransformer();
dct = new FastCosineTransformer();
// experimental: use matrix for DCT operation
dctMatrix = createDCTMatrix();
}
示例5: inverseFFT
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
/**
* Calculates the inverse FFT of the frequency domain representation
* of the signal. That is: converts the given data from frequency domain
* to the time domain.
* @param fft the frequency domain representation of the signal
* (e.g. the output of the {@link FourierTransform#forwardFFT(double[])}
* @return the time domain representation of the signal
*/
public double[] inverseFFT(Complex[] fft) {
FastFourierTransformer transformer = new FastFourierTransformer();
Complex[] complexSignal = transformer.inversetransform(fft);
double[] signal = new double[complexSignal.length];
for (int i = 0; i < complexSignal.length; i++) {
signal[i] = complexSignal[i].getReal();
}
return signal;
}
示例6: init
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
public boolean init() {
try {
fft_size = getPredicateValueAsIntWithException("window-size");
fft = new FastFourierTransformer () ;
if (! FastFourierTransformer.isPowerOf2(fft_size)) {
logger.error("The window size >" + fft_size + "< is not a power of 2.");
return false;
}
}catch (Exception e) {
logger.error(e.getMessage(),e);
return false;
}
return true;
}
示例7: inverseFFT
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
/**
* Calculates the inverse FFT of the frequency domain representation of the
* signal. That is: converts the given data from frequency domain to the
* time domain.
*
* @param fft the frequency domain representation of the signal (e.g. the
* output of the {@link FourierTransform#forwardFFT(double[])}
* @return the time domain representation of the signal
*/
public double[] inverseFFT(Complex[] fft) {
FastFourierTransformer transformer = new FastFourierTransformer();
Complex[] complexSignal = transformer.inversetransform(fft);
double[] signal = new double[complexSignal.length];
for (int i = 0; i < complexSignal.length; i++) {
signal[i] = complexSignal[i].getReal();
}
return signal;
}
示例8: compute
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
@Override
protected ImageResult compute(PreferencesWithAxes<PreferencesForSTFT> preferences, AsyncStatus status) throws Exception {
final PreferencesForSTFT prefs = preferences.prefs;
final ImageResult result = new ImageResult(preferences.width, preferences.height, "Averaged Short-Time Fourier Transform");
final FastFourierTransformer fft = new FastFourierTransformer();
double paddedLengthMin = prefs.windowLength;
if (prefs.padToHeight) {
paddedLengthMin = Math.max(
paddedLengthMin,
calculatePaddedHeight(preferences.height, preferences.yMin, preferences.yMax, signal.getSamplingFrequency())
);
}
int paddedLength = 2;
while (paddedLength < paddedLengthMin) {
paddedLength *= 2;
}
WindowFunction wf = new WindowFunction(prefs.windowType, prefs.windowType.getParameterDefault());
double[] chunk = new double[prefs.windowLength];
double[] padded = new double[paddedLength];
for (int ix=0; ix<preferences.width; ++ix) {
if (status.isCancelled()) {
return null;
}
status.setProgress(ix / (double) preferences.width);
double t0 = preferences.xMin + (preferences.xMax - preferences.xMin) * ix / (preferences.width - 1);
result.t[ix] = t0;
int n0 = (int) Math.round(t0 * sampling);
Arrays.fill(chunk, 0.0);
signal.getSamples(n0 - prefs.windowLength / 2, prefs.windowLength, chunk);
double[] windowed = wf.applyWindow(chunk);
System.arraycopy(windowed, 0, padded, 0, prefs.windowLength);
Complex[] spectrum = fft.transform(padded);
for (int iy=0; iy<preferences.height; ++iy) {
double fIdeal = preferences.yMin + (preferences.yMax - preferences.yMin) * iy / (preferences.height - 1);
int i = (int) Math.round(spectrum.length * fIdeal / sampling);
double fExact = i * sampling / spectrum.length;
result.f[iy] = fExact;
// phase difference between start and center of time window
Complex phaser = new Complex(0, Math.PI*result.f[iy]*prefs.windowLength/sampling).exp().multiply(2.0);
Complex value = (i >= 0 && i < paddedLength) ? spectrum[i].multiply(phaser) : Complex.ZERO;
result.values[ix][iy] = value;
}
}
return result;
}
示例9: forwardFFT
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
/**
* Calculates the FFT of the given signal.
*
* If a {@link WindowType} was specified while calling a constructor
* it is applied to the signal before processing.
*
* If the signal's length is not a power of 2 (which is required by the
* FFT algorithm) this function automatically pads it with zeros.
*
* @param signal the signal for which the FFT should be calculated
* @return the result of the FFT
*/
public Complex[] forwardFFT(double[] signal) {
FastFourierTransformer transformer = new FastFourierTransformer();
double[] windowedSignal = windowFunction.applyWindow(signal);
double[] paddedSignal = padWithZeroIfNecessary(windowedSignal);
return transformer.transform(paddedSignal);
}
示例10: forwardFFT
import org.apache.commons.math.transform.FastFourierTransformer; //导入依赖的package包/类
/**
* Calculates the FFT of the given signal.
*
* If a {@link WindowType} was specified while calling a constructor it is
* applied to the signal before processing.
*
* If the signal's length is not a power of 2 (which is required by the FFT
* algorithm) this function automatically pads it with zeros.
*
* @param signal the signal for which the FFT should be calculated
* @return the result of the FFT
*/
public Complex[] forwardFFT(double[] signal) {
FastFourierTransformer transformer = new FastFourierTransformer();
double[] windowedSignal = windowFunction.applyWindow(signal);
double[] paddedSignal = padWithZeroIfNecessary(windowedSignal);
return transformer.transform(paddedSignal);
}