Java 类com.sun.media.sound.FFT 实例源码

项目:DataVec    文件:FastFourierTransform.java   
/**
 * Get the frequency intensities
 * 
 * @param amplitudes
 *            amplitudes of the signal
 * @return intensities of each frequency unit: mag[frequency_unit]=intensity
 */
public double[] getMagnitudes(double[] amplitudes) {

    int sampleSize = amplitudes.length;

    // call the fft and transform the complex numbers
    FFT fft = new FFT(sampleSize / 2, -1);
    fft.transform(amplitudes);
    // end call the fft and transform the complex numbers

    // even indexes (0,2,4,6,...) are real parts
    // odd indexes (1,3,5,7,...) are img parts
    int indexSize = sampleSize / 2;

    // FFT produces a transformed pair of arrays where the first half of the
    // values represent positive frequency components and the second half
    // represents negative frequency components.
    // we omit the negative ones
    int positiveSize = indexSize / 2;

    double[] mag = new double[positiveSize];
    for (int i = 0; i < indexSize; i += 2) {
        mag[i / 2] = Math.sqrt(amplitudes[i] * amplitudes[i] + amplitudes[i + 1] * amplitudes[i + 1]);
    }

    return mag;
}
项目:Canova    文件:FastFourierTransform.java   
/**
 * Get the frequency intensities
 * 
 * @param amplitudes
 *            amplitudes of the signal
 * @return intensities of each frequency unit: mag[frequency_unit]=intensity
 */
public double[] getMagnitudes(double[] amplitudes) {

    int sampleSize = amplitudes.length;

    // call the fft and transform the complex numbers
    FFT fft = new FFT(sampleSize / 2, -1);
    fft.transform(amplitudes);
    // end call the fft and transform the complex numbers

    double[] complexNumbers = amplitudes;

    // even indexes (0,2,4,6,...) are real parts
    // odd indexes (1,3,5,7,...) are img parts
    int indexSize = sampleSize / 2;

    // FFT produces a transformed pair of arrays where the first half of the
    // values represent positive frequency components and the second half
    // represents negative frequency components.
    // we omit the negative ones
    int positiveSize = indexSize / 2;

    double[] mag = new double[positiveSize];
    for (int i = 0; i < indexSize; i += 2) {
        mag[i / 2] = Math.sqrt(complexNumbers[i] * complexNumbers[i] + complexNumbers[i + 1] * complexNumbers[i + 1]);
    }

    return mag;
}