Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Spectrograms

Modify the Block Diagram

Spectrograms are color-based visualizations of the evolution of the power spectrum of a speech signal as this signal is swept through time. Spectrograms use the periodogram power spectrum estimation method and are widely used by speech and audio engineers. You can use them to develop a visual understanding of the frequency content of your speech signal while a particular sound is being vocalized.

In the previous section, you built a model capable of calculating the power spectrum of a speech signal that represents a woman saying "MATLAB." In this topic, you modify this model to view the spectrogram of your signal:

  1. If the model you created in View the Power Spectrum Estimates is not open on your desktop, you can open an equivalent model by typing

    ex_gstut11ex_gstut11

    at the MATLAB® command prompt.

  2. Add the following blocks to your model. Subsequent topics describe how to use these blocks.

    BlockLibrary

    Selector

    Simulink / Signal Routing

    dB Conversion

    Math Functions / Math Operations

    Buffer

    Signal Management / Buffers

    Reshape

    Simulink / Math Operations

    Matrix Viewer

    Sinks

  3. Connect the blocks as shown in the figure below. These blocks extract the positive frequencies of each power spectrum and concatenate them into a matrix that represents the spectrogram of the speech signal.

Once you have assembled the blocks needed to view the spectrogram of your speech signal, you can set the block parameters.

Set the Model Parameters

In the previous topic, you assembled the blocks you need to view the spectrogram of your speech signal. Now you must set the block parameters:

  1. If the model you created in Modify the Block Diagram is not open on your desktop, you can open an equivalent model by typing

    ex_gstut12ex_gstut12

    at the MATLAB command prompt.

  2. Use the Selector block to extract the first 64 elements, or the positive frequencies, of each power spectrum. Open the Selector dialog box by double-clicking the block. Set the block parameters as follows:

    • Number of input dimensions = 1

    • Index mode = One-based

    • Index option = Index vector (dialog)

    • Index = 1:64

    • Input port size = 128

    At each time instance, the input to the Selector block is a vector of 128 elements. The block assigns one-based indices to these elements and extracts the first 64. Once you are done setting these parameters, the Selector dialog box should look similar to the figure below. To apply your changes, click OK.

  3. The dB Conversion block converts the magnitude of the input FFT signal to decibels. Leave this block at its default parameters.

  4. Use the Buffer1 block to buffer up the individual power spectrums. Open the Buffer1 dialog box by double-clicking the block. Set the block parameters as follows:

    • Output buffer size (per channel) = 64*48

    • Buffer overlap = 64*46

    • Initial conditions = -70

    • Treat Mx1 and unoriented sample-based signals as = One channel

    Once you are done setting these parameters, the Buffer1 dialog box should look similar to the following figure. To apply your changes, click OK.

    Setting the value of the Buffer overlap parameter slightly less than the value of the Output buffer size (per channel) parameter ensures that your spectrogram represents smooth movement through time. The Initial conditions parameter represents the initial values in the buffer; -70 represents silence.

  5. Use the Reshape block to reshape the input signal into a 64-by-48 matrix. To do so, set the Output dimensionality to Customize and the Output dimensions to [64 48].

  6. The Matrix Viewer enables you to view the spectrogram of the speech signal. Open the Matrix Viewer dialog box by double-clicking the block. Set the block parameters as follows:

    • Click the Image Properties tab.

    • Colormap matrix = jet(256)

    • Minimum input value = -150

    • Maximum input value = -65

    • Select the Display colorbar check box.

    Once you are done setting these parameters, the Image Properties pane should look similar to the figure below.

    • Click the Axis Properties tab.

    • Axis origin = Lower left corner

    • X-axis title = Time Index

    • Y-axis title = Frequency Index

    • Colorbar title = dB Magnitude

    In this case, you are assuming that the power spectrum values do not exceed -65 dB. Once you are done setting these parameters, the Axis Properties pane should look similar to the figure below. To apply your changes, click OK.

After you have set the parameter values, you can calculate and view the spectrogram of the speech signal.

View the Spectrogram of the Speech Signal

In the topic View the Power Spectrum Estimates, you used a Vector Scope block to display the power spectrum of your speech signal. In this topic, you view the spectrogram of your speech signal using a Matrix Viewer block. The speech signal represents a woman's voice saying "MATLAB":

  1. If the model you created in Set the Model Parameters is not open on your desktop, you can open an equivalent model by typing

    ex_gstut13ex_gstut13

    at the MATLAB command prompt.

  2. Run the model. During the simulation, the Vector Scope window displays a sequence of power spectrums, one for each window of the original speech signal. The power spectrum is the contribution of every frequency to the power of the speech signal.

    The Matrix Viewer window, shown below, displays the spectrogram of the speech signal. This spectrogram is calculated using the Periodogram power spectrum estimation method. Note the harmonics that are visible in the signal when the vowels are spoken. Most of the signal's energy is concentrated in these harmonics; therefore, two distinct peaks are visible in the spectrogram.

In this example, you viewed the spectrogram of your speech signal using a Matrix Viewer block. You can find additional DSP System Toolbox™ product examples in the Help browser. To access these examples, click the Contents tab, double-click DSP System Toolbox, and then click Examples. A list of the examples in the DSP System Toolbox documentation appears in the right pane of the Help browser.

Was this topic helpful?