Having some trouble understanding this concept, really could do with some advice.

I want my STFT to have the following parameters: NFFT = 256 overlap/hop = 128

Now essentially, the algorithm will work as follows:

1) Split the signal into blocks of 256 

This will result in around 72*265:

2) For each of these blocks, calculate against the Hanning Window 

3) Create a "slider" that does an overlap of 128.. So, in theory it would 
   therefore be: `size = 256 + 128` 

Therefore, when I'm computing the DFT for each of the overlapped blocks, will my FFT remain at size 256 or will the size be 256 + 128 If this is the case, does each block in the resulting vector still have to be of size 256?



This is now my result:

enter image description here

But, compare this to a spectrogram in matplotlib

enter image description here

Where am I actually going wrong? I cannot make any sense of this.

I've looked bat through all the data, the blocks are correctly overlapping, Hanning window is being applied correctly.

Could it be to do with the fact I'm using a 1D DFT? I.e.

std::vector<complex> FFT->transform(complex_vector[0...n], 256);

The overlap is the way that you walk on your signal to be analyzed, lets go to an simple example, imagine that your signal X has a length = 14, NFFT = 4 and overlap/hop = 2

X = 1 2 3 4 5 6 7 8 9 10 11 12 13 14

To know the number of blocks of analysis you will:

int(n_samples/Overlap) - 1 

Then for this example:

(14/2)-1 = 6

lets get 4 points from X to pass to your FFT

At the first time you get from X

X2 = 1 2 3 4

from now you need overlap by 2

X2 = 3 4 5 6

Third time

X2 = 5 6 7 8

fourth time

X2 = 7 8 9 10

fifth time

X2 = 9 10 11 12

sixth time

X2 = 11 12 13 14
  • $\begingroup$ Thanks for this. The signal contains 18941 data samples. With an NFFT = 256 and overlap = 128 this gives 146 blocks. When I plot the graph of these values, it gives 146 instead of 128 (along the x-axis) is this correct? I know you told me before that it should only be outputting 128 blocks $\endgroup$
    – Phorce
    Jan 14 '14 at 16:26
  • 1
    $\begingroup$ If graphing a 2D spectrogram, then the X axis is just the number blocks, and you get a picture. If plotting an 1D FFT spectrum, then the X axis is each bin frequency. and you get a line or bar graph. $\endgroup$
    – hotpaw2
    Jan 14 '14 at 16:33
  • $\begingroup$ @ederwander - Please see my updated post $\endgroup$
    – Phorce
    Jan 14 '14 at 19:52

For a non-zero overlap, the size of each FFT will remain exactly the same. However some of the data points used in each successive FFT will be from the previous FFT window, thus allowing less completely new data points to make up the final length to be fed to that successive FFT. Thus more overlap will create a larger number of blocks.

For an overlap of 128, the 2nd FFT uses 128 points from the end of the first FFT, and adds 128 new points from the data stream, to make up a total of 256 data points, the same length as the first FFT. Rinse and repeat. The number of blocks for 50% overlap will approach double that of the number for zero overlap.

  • $\begingroup$ Please see my updated post. Something is really wrong and I can't seem to find out where! $\endgroup$
    – Phorce
    Jan 14 '14 at 19:51
  • $\begingroup$ Your X and Y axis are swapped, and your current X axis is just the bin index instead of the frequency represented by that bin index. The index should only go to 128 anyway, not 256 for real data. That's why your current plot is symmetrically redundant. $\endgroup$
    – hotpaw2
    Jan 14 '14 at 22:03
  • $\begingroup$ Hey thanks for the reply. Could this therefore be the reason why my results are so out in comparison to what I get from the matplotlib? $\endgroup$
    – Phorce
    Jan 14 '14 at 22:06

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.