1
$\begingroup$

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

enter image description here

Whereas my last output was the following:

enter image description here

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:

enter image description here

However, If I plot normally, I get the following:

enter image description here

I think my calculations are correct, I just don't think I'm plotting them right using the spectrogram!!

$\endgroup$
  • $\begingroup$ 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). $\endgroup$ – Phonon Jan 13 '14 at 23:54
  • $\begingroup$ @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. $\endgroup$ – Phorce Jan 13 '14 at 23:57
  • $\begingroup$ 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. $\endgroup$ – Phonon Jan 14 '14 at 0:01
  • $\begingroup$ 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? $\endgroup$ – Phorce Jan 14 '14 at 0:03
  • $\begingroup$ 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. $\endgroup$ – Phonon Jan 14 '14 at 1:15
2
$\begingroup$

Regarding your first 2 plots: for FFT results, the X axis is usually labeled with the FFT_bin_index * sample_rate / FFT_length, and the Y axis with either the magnitude (absolute value of the complex bin value), or the log magnitude of the FFT result bin.

$\endgroup$
0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ So, therefore, do my results look correct to you? I'm aware of Spectrograms, however, I was told that this data (STFT) can be a one-dimensional data and only plotting the REAL values? $\endgroup$ – Phorce Jan 13 '14 at 23:01
  • 2
    $\begingroup$ You are told wrong. The real part of an STFT is 2-dimensional. Moreover people generally do not use 'real' part of the STFT, rather the absolute value of the STFT is used for analysis. You have to plot each FFT result to a column and construct a matrix. That matrix will be your spectrogram. $\endgroup$ – Deniz Jan 13 '14 at 23:10
  • $\begingroup$ @Deniz Will this ever end? :(! Ok so the result of the STFT, should be in a 2D vector.. So for each 256 values, apply window, apply FFT.. After each of the analysis is done, I will end up with a 2D vector, BUT I still do not know what to plot. I can plot to spectrogram using the following formula (10 * log10(sqrt(re * re + im * im) This is therefore, what I plot? $\endgroup$ – Phorce Jan 13 '14 at 23:15
  • 1
    $\begingroup$ OK, after applying window you have 256 values, an array. Now think this as a column vector. You apply another window and get second 256 values, and put this as another column vector, right of the first one. Now you have a 256x2 matrix right? Do this until the end, you have 'complex' spectrogram. Take absolute value with abs function in matlab. Now to plot in matlab, use imagesc. You have it. $\endgroup$ – Deniz Jan 13 '14 at 23:18
  • 1
    $\begingroup$ @Deniz Your should write a separate answer consisting of your comments. I feel like they're more helpful than mine. $\endgroup$ – Phonon Jan 13 '14 at 23:20

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.