Up until now, you have been dealing with signals in the time domain. The DSP System Toolbox™ product is also capable of working with signals in the frequency domain. You can use the software to perform fast Fourier transforms (FFTs), power spectrum analysis, short-time FFTs, and many other frequency-domain applications.
The power spectrum of a signal represents the contribution of every frequency of the spectrum to the power of the overall signal. It is useful because many signal processing applications, such as noise cancellation and system identification, are based on frequency-specific modifications of signals.
First, assemble and connect the blocks needed to calculate the power spectrum of your speech signal:
Open a new Simulink® model.
Add the following blocks to your model. Subsequent topics describe how to use these blocks.
Signal From Workspace
Signal Management / Buffers
Estimation / Power Spectrum Estimation
Connect the blocks as shown in the next figure.
Once you have assembled the blocks needed to calculate the power spectrum of your speech signal, you can set the block parameters.
Now that you have assembled the blocks needed to calculate the power spectrum of your speech signal, you need to set the block parameters. These parameter values ensure that the model calculates the power spectrum of your signal accurately:
If the model you created in Create the Block Diagram is not open on your desktop, you can open an equivalent model by typing
at the MATLAB® command prompt.
Load the speech signal into the MATLAB workspace
load mtlb at the MATLAB command
prompt. This speech signal is a woman's voice saying "MATLAB."
Use the Signal From Workspace block to import the speech signal from the MATLAB workspace into your Simulink model. Open the Signal From Workspace dialog box by double-clicking the block. Set the block parameters as follows:
Sample time =
Samples per frame =
Form output after final data value by =
Once you are done setting these parameters, the Signal From Workspace dialog box should look similar to the figure below. Click OK to apply your changes.
The DSP System Toolbox product is capable of frame-based
processing. In other words, DSP System Toolbox blocks can
process multiple samples of data at one time. This improves the computational
speed of your model. In this case, by setting the Samples
per frame parameter to
80, you are telling
the Signal From Workspace block to output a frame that contains 80
signal samples at each simulation time step. Note that the sample
period of the input signal is 1/8000 seconds. Also, after the block
outputs the final signal value, all other outputs are zero.
Use the Buffer block to buffer the input signal into frames that contain 128 samples. Open the Buffer dialog box by double-clicking the block. Set the block parameters as follows:
Output buffer size (per channel) =
Buffer overlap =
Initial conditions =
Treat Mx1 and unoriented sample-based signals
Once you are done setting these parameters, the Buffer dialog box should look similar to the figure below. Click OK to apply your changes.
Based on these parameters, the first output frame contains 48 initial condition values followed by the first 80 samples from the first input frame. The second output frame contains the last 48 values from the previous frame followed by the second 80 samples from the second input frame, and so on. You are buffering your input signal into an output signal with 128 samples per frame to minimize the estimation noise added to your signal. Because 128 is a power of 2, this operation also enables the Periodogram block to perform an FFT on the signal.
Use the Periodogram block to compute a nonparametric estimate of the power spectrum of the speech signal. Open the Periodogram dialog box by double-clicking the block and set the block parameters as follows:
Window sampling =
Select the Inherit FFT length from input dimensions check box.
Number of spectral averages =
Once you are done setting these parameters, the Periodogram dialog box should look similar to the figure below. Click OK to apply your changes.
Based on these parameters, the block applies a Hamming window periodically to the input speech signal and averages two spectra at one time. The length of the FFT is assumed to be 128, which is the number of samples per frame being output from the Buffer block.
Use the Vector Scope block to view the power spectrum of the speech signal. Open the Vector Scope dialog box by double-clicking the block. Set the block parameters as follows:
Input domain =
Click the Axis Properties tab.
Clear the Inherit sample time from input check box.
Sample time of original time series =
Y-axis label =
Once you are done setting these parameters, the Axis Properties pane of the Vector Scope dialog box should look similar to the figure below. As you can see by the Y-axis scaling parameter, the decibel amplitude is plotted in a vector scope window.
Because you are buffering the input with a nonzero overlap, you have altered the sample time of the signal. As a result, you need to specify the sample time of the original time series. Otherwise, the overlapping buffer samples lead the block to believe that the sample time is shorter than it actually is.
After you have set the block parameter values, you can calculate and view the power spectrum of the speech signal.
In the previous topics, you created a power spectrum model and set its parameters. In this topic, you simulate the model and view the power spectrum of your speech signal:
If the model you created in Set the Model Parameters is not open on your desktop, you can open an equivalent model by typing
at the MATLAB command prompt.
Set the configuration parameters. Open the Configuration Parameters dialog box by selecting Model Configuration Parameters from the Simulation menu. Select Solver from the menu on the left side of the dialog box, and set the parameters as follows:
Stop time =
(no continuous states)
Apply these parameters and close the Configuration Parameters dialog box by clicking OK. These parameters are saved only when you save your model.
If you have not already done so, load
the speech signal into the MATLAB workspace by typing
Run the model to open the Vector Scope window. The data is not immediately visible at the end of the simulation. To autoscale the y-axis to fit the data, in the Vector Scope window, right-click and choose Autoscale. The following figure shows the data displayed in the Vector Scope window.
During the simulation, the Vector Scope window displays a series of frames output from the Periodogram block. Each of these frames corresponds to a window of the original speech signal. The data in each frame represents the power spectrum, or contribution of every frequency to the power of the original speech signal, for a given window.
In the next section, Spectrograms, you use these power spectra to create a spectrogram of the speech signal.