Will the resulting spectrogram from this algorithm be 1D or 2D?

I'm implementing a spectrogram algorithm and I get the basic concepts, however, I'm struggling with something.

Let's say I have a 1D vector:

data = [0.36, 0.58, ...., 0.25]


I then compute a STFT of this data (with an overlap of say 128) this then produces a 2D array. I then compute the log of these values in order to compute the spectrogram. Would the resulting vector be 1D or 2D? Since the STFT is 2D (as it is split into blocks), I'm guessing that the spectrogram will be a 1D representation since I'm calculating the logs.

Spectrograms are two-dimensional, usually calculated from a one dimensional input vector.

As an example say that you want a spectrogram with k-pts of frequency domain span and M-pts of time-domain span. With NO overlap an input vector of length N = k x M will fill the spectrogram. Every k samples a k-pt DFT is performed and makes one of the M time-axis vectors on the spectrogram.

For a running spectrogram with an overlap of k/2, then N/2 input samples will be needed to create a k x M spectrogram, and the time scale will be cut in half.

Usually the logarithm only comes in to scale the amplitude of the output of the DFT. i.e., each of the k complex samples in the DFT output becomes a scalar value computed from the log of the complex sample magnitude.

• Thanks for your reply. So, could I therefore plot the 2D vector? I've seen before: Px = spectrogram(...); plot(Px) I just assumed this was 1D? Also, is it worth calculating the detrend mean of the signal? – Phorce Jan 4 '14 at 21:19

The log of every element of a 2D matrix is still a 2D matrix (usually time vs frequency for a spectrogram). Taking the log() is usually done to make the graphic output closer to a human perceptual response than does a linear visualization.

In spectrogram, you split the 1D data vector (time sequency) into several segments with some overlaps. Fourier transform of the segment still produces you a 1D vector with the frequency axis. However, you do the STFT on all the segments, which will provide you the time axis as well. By aligning the STFT of each segments, you form a 2D array (time * frequency). If Px = spectrogram(...); plot(abs(Px)) gives you a bunch of curves with each one as the y-axis value of the column of Px. In other words, the function plots the STFT curve of each segments. More often used is imagesc(abs(Px)) which shows you the magnitude image with each pixel representing the specific time and frequency.