# Implementing short-time Fourier transform

I have a $512$ sample frame, lets call it X. The frame is further divided into four sub-frames of $128$ samples each. Each of these sub-frames have a different frequency.

For STFT, I use MATLAB's gausswin(N) function where N is equal to $128$ in my case to generate a Gaussian window, let's call it W. I zero-pad my windows W to make it equal to $512$ samples.

I now multiply my original frame X point by point with W to get y. I then take FFT of y to get Y. It works till here.

My question is, naturally the next logical step should be to shift my zero-padded window W to right by 128 samples and repeat the multiply and FFT procedure again.

• But how do I accumulate these results?
• Concretely, how do I convert it into a time-frequency plot?

admittedly, i have never used the buffer() function in matlab. for doing STFT analysis and processing, i have just broken it into frames myself with code similar to this answer. it's easier to see what's going on.

while you can use a gaussian window for analysis (i found it mathematically useful in this paper, email me if you want a pdf copy), you must use a complementary window, one that adds to 1 with the windows of its adjacent frames, for the reconstruction of the signal. at least if you want this to pass the signal unchanged when the processing is set to "null".

• Your point about mandatory usage of complementary window is interesting. I know that Hann is used widely to meet that requirement, but why do you need that in STFT? Especially when it is working only for 50% of overlap and you can use different values? I've seen thousand times people using windows like Kaiser or Dolph in STFT. Regarding buffer - it's cool, but one 'must' -> Signal Processing Toolbox. – jojek Jul 12 '14 at 16:33
• @jojek, it's during reconstruction using the STFT that you need complementary windows so that the signal coming out is equal to the signal going in when the processing is "null processing" (a.k.a. a "wire"). but the analysis can use other windows that may be advantagious. the gaussian window is useful because you can do many frequency domain processes that preserve the gaussian window coming out. then, if you know it's gaussian windowed on the output of the iDFT for that frame, you can turn that gaussian into a complementary hann window with a simple multiplication. – robert bristow-johnson Jul 12 '14 at 18:16
• I see your point. Probably that's because I did reconstruction from STFT only once. Perfectly reasonable explanation! +1 – jojek Jul 12 '14 at 18:24
1. To make things easier, I suggest you to use MATLAB function buffer.
2. Regarding storage of your results I recommend to save it into matrix with dimensions no_frames and $512$. So if your current frame index is i, then do:

S(:,i) = spec;

Where S is your output matrix and spec is the spectrum calculated for a given frame. Please mind that the S(:,i) will assign spec as i'th column in resulting matrix. If you need to transpose results, then just do S(i,:) or flip the spectrum by doing spec'.