Search code examples
matlabsignal-processingfftspectrogram

Spectrogram example in Matlab


Is there Matlab code that shows a series of numbers representing a waveform as a spectrogram?

The time interval each sample represents is the same, idearly this could also be given to use for the axis scale.

http://www.davegrossman.net/gould/media/spectrum-devocalized.jpg

For example:

spec({1 2 3 2 1 2 3 2}, 0.1 seconds)

or

spec(my_data.txt, 10 Hz)

etc...


Solution

  • If you have the Signal Processing Toolbox, then you can use the spectrogram() function. e.g.:

    T = 0:0.001:2;
    X = chirp(T,100,1,200,'q');
    spectrogram(X,128,120,128,1E3); 
    

    (Example taken from that documentation page.)

    The numeric params are window length, overlap length, FFT length and sampling frequency, respectively.