我读到需要窗口来应用滤波器(低通、高通、带通或带阻),但不适用于 FFT。
1. 什么优点适用窗口或缺点不适用?
2. 选择尺码的标准是什么(我的长度W:汉窗的长度)?
3. 我在哪里可以找到具体的文献?
我的代码:
假设一个样本数组存储在
integer SIZE = 16384; //SomeValue
short[] sSamples = new short[SIZE];
sSamples = obtainSamples(); //Some method to fill my array
现在我需要获得我的 FFT。我为我的 FFT 任意选择了 4096,然后是 8 倍(或 8 fft)
FFTLength = 4096;
SIZE = 16384;
double Overlap = 0.5;
SIZE/(FFTLength*Overlap) = 8;
直接法:
complex cSamples = new complex[SIZE];
cSamples = short2Complex(sSamples);
现在我需要获取长度为 8 个样本数组的部分数组:SIZE/4
//getPartArray(from, until) maybe like System.ArrayCopy
complex[] cSamples00 = getPartArray(0,4095);
complex[] cSamples01 = getPartArray(4096,8191);
//similarly for all, from 00 until 07
complex[] cSamples01 = getPartArray(12287,16383);
最后,获得 FFT
//fft(complex[], length)
complex[] cFFT00 = fft(cSamples00,4096);
//similarly for all, from 00 until 07
complex[] cFFT07 = fft(cSamples00,4096);
窗口方法:
//int LengthW = ?? // (besides positive and odd)
double[] Wn = new double[LengthW];
//Suppose Han Window,can be Hamming, Kaiser, Blackman, etc
Wn = obtainHanWindow(LengthW);
double[] sWindowedSamples = applyingWindow(Wn,sSamples);
complex cSamples = new complex[SIZE];
cSamples = short2Complex(sWindowedSamples);
现在我需要获取长度为 8 个样本数组的部分数组:SIZE/4
//getPartArray(from, until) maybe like System.ArrayCopy
complex[] cSamples00 = getPartArray(0,4095);
complex[] cSamples01 = getPartArray(4096,8191);
//similarly for all, from 00 until 07
complex[] cSamples01 = getPartArray(12287,16383);
最后,获得 FFT
//fft(complex[], length)
complex[] cFFT00 = fft(cSamples00,4096);
//similarly for all, from 00 until 07
complex[] cFFT07 = fft(cSamples00,4096);
唯一的区别是计算一个窗口并将其应用于输入。
定义的类和方法
复杂类的定义如下:
class complex {
public double real = 0.0;
public double imag = 0.0;
}
短2复杂:
short2Complex(short[] intSSample) {
complex intCSample = new complex[intSSample.length];
for (int i = 0; i < intSSample.length; i++) {
complex tcomplex = new complex();
tcomplex.real = intSSample[i];
intCSample[i] = tcomplex;
}
return intCSample;
}
获取HanWindow:
double[] obtainHanWindow(int Size) {
//Size must be Odd and Positive integer
double[] dHan = new double[Size];
int HalfSize = (int)Math.floor((double)Size/2);
for (int i = 0; i < HalfSize; i++) {
int j = 2*HalfSize - i;
double Pi2DivSize = 2.0*Math.PI/Size;
dHan[i] = 0.5+0.5*Math.cos(Pi2DivSize*(double)(i - HalfSize));
dHan[j] = 0.5+0.5*Math.cos(Pi2DivSize*(double)(HalfSize - i));
}
dHan[HalfSize] = 1.0;
return dHan;
}
应用窗口
applyingWindow(double[] dWn, double[] dSamples) {
double dOutput = new double[dSamples.length]
for (int i=0; i < dWn.length; i++) {
dOutput[i] = 0;
for (int j=0; j < dSamples.length; j++) {
if(i-j>=0) {
dOutput[i] += dSamples[j]*dWn[i-j];
}
}
}
return dOutput;
}



