# STFT - Plotting is not a true representation

I might be going crazy here. Following my question: here

I did some thinking and probably understood that my STFT algorithm was not performing correctly.

I followed this algorithm:

-> Get 256 of data

-> Apply windowing function

-> Get the FFT

-> get the first 128 points

Here is my result. I have used NFFT = 256 which should give me 128 points. I firstly calculated the FFT (after the windowing function was applied) and only counted the first 128 values of this. I.e. FFT_RESULT / 2 Whereas my last output was the following: I don't quite understand why the values along the X axis are particular that high?

EDIT:

Ok, so following the advice, I did the following:

1) Created a 2D vector for each of the "256 resulting FFT values"

for(size_t i=0; (i < signal.size()); i++)
{
std::vector<double> temp_vector;
// store blocks of 256 inside temp_vector

// Compute Hanning Window

// Compute FFT

std::vector<std::vector<complex> stft;

stft.push_back(temp_vector);
}


This gave me a total of 74 blocks within the 2D vector.

I then took the absolute value of the REAL values and stored these inside a double, read these in and with pylab library I used imshow() and got the following result: However, If I plot normally, I get the following: I think my calculations are correct, I just don't think I'm plotting them right using the spectrogram!!

• Your spectrogram looks perfectly correct to me. If you want to increase the resolution, you can take FFT of more points (make your window longer) and also make your window overlap bigger (i.e. shift your window by fewer samples every time). – Phonon Jan 13 '14 at 23:54
• @Phonon But, does it tell you anything? I haven't actually implemented the "shift" of the window. I'm going to try and do this now =) My main objective, is to try to identify where the "peaks" are within the signal.. It's evident in the final graph, but, when I compute the Htz of each block (using the formular) it does not work very well. – Phorce Jan 13 '14 at 23:57
• Okay, so what are the rows and columns of the image you just posted? By shifting the window I mean that you're taking many windows, right? And they can overlap by an arbitrary number of samples. That's what I mean by shifting windows: how many sample you skip to take the next window. – Phonon Jan 14 '14 at 0:01
• So, the vector contains 72x256 I took, the signal, split it into blocks of 256 and took them windows. I did not skip any samples at all, to take the next window.. I'm guessing this is wrong? – Phorce Jan 14 '14 at 0:03
• No, that's not wrong. It's just a special case which has 0% overlap. You can generally have overlapping windows, and that would give you better resolution. Using 50% overlap is pretty standard. – Phonon Jan 14 '14 at 1:15

Your calculations are correct, but that's not how you plot STFT. If you think about it, you're trying to plot three-dimensional data, namely value that is a function of both time and frequency. To represent three-dimensional data we use images rather than graphs. Vertical and horizontal coordinates represent frequency and time respectively, and pixel color or intensity represents FFT magnitude of a specific frequency at a specific time. We call these images spectrograms. MATLAB Signal Processing Toolbox comes with a spectrogram command which lets you plot spectrograms.