How to Plot a Spectrogram in MATLAB

How to Plot a Spectrogram in MATLAB thumbnail
Spectrograms can be plotted in MATLAB with the "spectrogram" function.

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.

Instructions

    • 1

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

    • 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

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

      "figure, spectrogram(x)."

    • 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')."

Related Searches:

References

  • Photo Credit NA/AbleStock.com/Getty Images

Comments

Related Ads

Featured