Calculates the 2D joint time-frequency spectrogram as an image.
SPECGRAM(series, len, overlap, fftlen, swin, ampflag)
series |
- |
An input series |
||||||||||||||||||||||
len |
- |
Optional. An integer, the segment length. Defaults to 512. |
||||||||||||||||||||||
overlap |
- |
Optional. An integer, the number of points to overlap each segment. Defaults to len/2. |
||||||||||||||||||||||
fftlen |
- |
Optional. An integer, the FFT length. Defaults to len. |
||||||||||||||||||||||
swin |
- |
Optional. An integer, the windowing function
|
||||||||||||||||||||||
ampflag |
- |
Optional. An integer, the window correction method.
|
A table of Amplitude values in Frequency vs Time format displayed as an image.
W1: {gsin(300, .01, 20), gsin(300, .01, 40), gsin(300, .01, 30)};setvunits("V")
W2: spectrum(W1)
W3: specgram(W1, 128);turbo
W1 consists of three concatenated sinusoids of 20, 40 and 30 Hertz.
W2 shows the frequency spectrum with peaks at 20, 40, and 30 Hertz.
W3 divides W1 into columns of 128 points that overlap by 64 points. The SPECTRUM (i.e. normalized magnitude of the FFT) of each column is calculated and the result is displayed as an image with the turbo colormap.
The image in W3 shows how the frequency of the series in W1 changes over time, clearly showing the distinct 20, 40 and 30 Hertz components and the times when the components occurred.
W4: specgram(W1, 128, 120, 1024);turbo
Same as above, but a longer segment overlap is used and the FFT size is zero padded to 1024 points producing a finer resolution image.

W1: gnotes();gcmajscale();lines
W2: specgram(W1, 256, 250, 1024*1);sety(400, 1200);gridh;gridsol;gridcolor(0);setcolormap(rev(gray))
W3: readimage(gethome()+"data\cmaj.png");scales(0);label("C Major Scale")

W1 generates a frequency series based on the 12-tone equal temperament system, providing the complete chromatic scale needed for Western music. From this series, W1 extracts the seven frequencies that define the C Major scale (C, D, E, F, G, A, B, and the octave C). These frequencies are then synthesized into a time-domain audio signal, with each note rendered as a pure sinusoidal waveform and played in sequence.
W2 computes the joint time-frequency spectrogram of the generated C major scale. The plot is shaded with an inverse gray colormap.
W3 displays an image of the standard musical notation of the C major scale with whole notes. The notation is very similar the to the joint time-frequency spectrogram. The spectrogram shows the frequency step between the 3rd and 4th tones (E and F) and the 7th and 8th tones (B and C) is a semitone (half-step). The frequency steps between the other notes are whole tones demonstrating the whole-whole-half-whole-whole-whole-half step pattern of the Major Scale.
SPECGRAM produces a joint time-frequency amplitude spectrum where the magnitude of the result represents the instantaneous amplitude of the input series at a particular time value.
SPECGRAM divides the input series into segments of length len, optionally overlapped by OVERLAP number of points. Each segment is multiplied by an optional window function with optional amplitude correction and the SPECTRUM of each segment is computed. The result in transposed to yield an image with Time along the X axis and Frequency along the Y axis. Each row of a SPECGRAM is a SPECTRUM of the corresponding series segment.
The amplitude specgram is converted to a PSD specgram with:
psdspecgram(s) = deltax(s) * specgram(s)^2 * LEN / 2
where len is the specgram segment length. The mean-squared correction factor (3) is appropriate for the window correction of the PSD specgram.
If fftlen is larger than the segment length, the segments are zero-padded before computing the SPECTRUM.
Time integration of the un-windowed or amplitude corrected SPECGRAM is approximately equal to the un-windowed or amplitude corrected SPECTRUM of the entire input series, i.e.
colmean(specgram(s)) = spectrum(s) approximately
The SPECTRUM function displays the frequency content of the data where the SPECGRAM functions displays the frequencies and the times at which those frequencies occurs. For example, when applied to music, the spectrum (or FFT) only indicates the notes and the amplitudes of the notes of a given song. The spectrogram is more like a musical score, displaying the notes, the amplitudes of the notes and the times at which those notes were played.
See DADiSP/FFTXL to optimize the underlying FFT computation.