I read that the window is needed to apply filter (Low Pass, High Pass, Band Pass or band Stop), but not for the FFT.
1. What advantage does apply a window or disadvantage does not apply?
2. What is the criteria to choose the size (My LengthW:Length of Han Window)?
3. Where I can find literature that specifically?
My code:
Suppose an array of samples stored in
integer SIZE = 16384; //SomeValue
short[] sSamples = new short[SIZE];
sSamples = obtainSamples(); //Some method to fill my array
Now I need to obtain my FFT. I arbitrarily chose 4096 for my FFT, then are 8 times (or 8 fft's)
FFTLength = 4096;
SIZE = 16384;
double Overlap = 0.5;
SIZE/(FFTLength*Overlap) = 8;
DIRECT METHOD:
complex cSamples = new complex[SIZE];
cSamples = short2Complex(sSamples);
Now I need to obtain part of array of sample 8 arrays of length: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);
Finally, Obatin the FFT
//fft(complex[], length)
complex[] cFFT00 = fft(cSamples00,4096);
//similarly for all, from 00 until 07
complex[] cFFT07 = fft(cSamples00,4096);
WINDOWED METHOD:
//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);
Now I need to obtain part of array of sample 8 arrays of length: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);
Finally, Obatin the FFT
//fft(complex[], length)
complex[] cFFT00 = fft(cSamples00,4096);
//similarly for all, from 00 until 07
complex[] cFFT07 = fft(cSamples00,4096);
The only difference is calculate a window and apply it to the input.
Definition's class and methods
The complex class is defined like:
class complex {
public double real = 0.0;
public double imag = 0.0;
}
short2Complex:
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;
}
obtainHanWindow:
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
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;
}