1
$\begingroup$

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;
}
$\endgroup$
4
$\begingroup$

Figure 1

Figure 2

As you can see; When a sinusoidal signal of arbitrary frequency is input to the ‘N’ point DFT, the spectral response of the signal will not be a Delta function (impulse) because when we take into account of the missing end point to be the same as the beginning of the next period of the periodic extension of the sequence, the periodic extension of the signal is no more a sinusoid. One way to solve this problem is to ensure Coherent Sampling as shown in figure 1

But coherent sampling can be done only if the DFT engine receives pure monotone signals. So in a real world application, Coherent sampling is not feasible.

SO, just diminish the magnitude of the discontinuities by multiplying the whole signal with some function.

So, when you multiply by window function, it eliminates the jump discontinuities and removes the false frequency that is introduced when coherent sampling is not done (see Figure 3.

Figure 3

The length of the window should be the length of your signal. Selection of your window could be depending on how much side-lobe height do you tolerate.

Performance of windows

Image Source: http://electronicdesign.com/analog/choose-right-fft-window-function-when-evaluating-precision-adcs

$\endgroup$
0
$\begingroup$

Windowing is essential before performing FFT to ensure there is no spectral leakage. As FT works well with periodic data, data discontinuity can effect in spectral artifacts.

http://www.ni.com/white-paper/4844/en/

$\endgroup$
  • $\begingroup$ Thanks, but I was reading and still isn't clear for me. To apply Window what is the appropriate size? $\endgroup$ – Anita Dec 30 '14 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.