本文整理汇总了Java中com.sun.media.sound.FFT类的典型用法代码示例。如果您正苦于以下问题:Java FFT类的具体用法?Java FFT怎么用?Java FFT使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FFT类属于com.sun.media.sound包,在下文中一共展示了FFT类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMagnitudes
import com.sun.media.sound.FFT; //导入依赖的package包/类
/**
* 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;
}
示例2: getMagnitudes
import com.sun.media.sound.FFT; //导入依赖的package包/类
/**
* 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;
}