How to Plot a Spectrogram in MATLAB

Written by suman medda
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Plot a Spectrogram in MATLAB
Spectrograms can be plotted in MATLAB with the "spectrogram" function. (NA/ Images)

While MATLAB 6.5 and earlier versions of the software contained a function called "specgram" that could handle the plotting of a signal's spectrogram, the newer versions come with improved functionality such as 3D rendering. Even though the old definition of the function is still supported, the use of "spectrogram" instead of "specgram" is highly recommended, especially since "specgram" is likely to be completely removed from future versions of MATLAB.

Skill level:


  1. 1

    Open a new MATLAB project. Go to "File" and then click on "New."

  2. 2

    Use the following line of code to load a speech signal from your computer:"[x, fs] = wavread('test.wav')." 'Test.wav' is the name of the file you will be using for plotting the spectrogram.

  3. 3

    Use the spectrogram function to display the spectrogram of the signal in a new window as follows:

    "figure, spectrogram(x)."

  4. 4

    Add a "yaxis" flag to the command if you wish to have time represented on the horizontal axis. This step is optional, but will help render the most common representation of a spectrogram. The corresponding line of code is: "spectrogram(x, 'yaxis')."

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.