Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

Estimate the Power Spectral Density in Simulink

The power spectral density (PSD) of a time-domain signal is the distribution of power contained within the signal over frequency, based on a finite set of data. The frequency-domain representation of the signal is often easier to analyze than the time-domain representation. Many signal processing applications, such as noise cancellation and system identification, are based on the frequency-specific modifications of signals. The goal of the spectral density estimation is to estimate the spectral density of a signal from a sequence of time samples. Depending on what is known about the signal, estimation techniques can involve parametric or nonparametric approaches, and can be based on time-domain or frequency-domain analysis. For example, a common parametric technique involves fitting the observations to an autoregressive model. A common nonparametric technique is the periodogram. The spectral density is estimated using Fourier transform methods such as the Welch Method. You can also use other techniques such as the maximum entropy method.

In DSP System Toolbox™, you can perform real-time spectral analysis of a dynamic signal using the Spectrum Analyzer block. Alternatively, you can use the Spectrum Estimator block from the dspspect3 library to compute the power spectrum, and Array Plot block to view the spectrum.

Estimate PSD Using the Spectrum Analyzer

You can view the Power Spectral Density (PSD) of a signal using the Spectrum Analyzer block. The PSD is computed in real time and varies with the input signal, and with changes in the properties of the Spectrum Analyzer block. You can change the dynamics of the input signal and see what effect those changes have on the spectral density of the signal in real time. The PSD data can only be viewed and is not available for processing. To acquire and process the data, use the Spectrum Estimator block in the dspspect3 library.

The model ex_psd_sa feeds a noisy sine wave signal to the Spectrum analyzer block. The sine wave signal is a sum of two sinusoids: one at a frequency of 5000 Hz and the other at a frequency of 10,000 Hz. The noise at the input is Gaussian, with zero mean and a standard deviation of 0.01.

Open and Inspect the Model

To open the model, enter ex_psd_sa in the MATLAB® command prompt.

Here are the settings of the blocks in the model.

BlockParameter ChangesPurpose of the block
Sine Wave 1
  • Frequency to 5000

  • Sample time to 1/44100

  • Sample per frame to 1024

Sinusoid signal with frequency at 5000 Hz

Sine Wave 2
  • Frequency to 10000

  • Phase offset (rad) to 10

  • Sample time to 1/44100

  • Sample per frame to 1024

Sinusoid signal with frequency at 10000 Hz

Random Source
  • Source type to Gaussian

  • Variance to 1e-4

  • Sample time to 1/44100

  • Sample per frame to 1024

Random Source block generates a random noise signal with properties specified through the block dialog box
AddList of signs to +++.Add block adds random noise to the input signal
Spectrum AnalyzerClick the Spectrum Settings icon . A pane appears on the right.
  • In the Main options pane, under Type, select Power density.

  • In the Trace options pane, clear the Two-sided spectrum check box. This shows only the real-half of the spectrum.

  • Clear the Max-hold trace and Min-hold trace check boxes if needed.

Spectrum Analyzer block shows the Power Spectrum Density of the signal

Play the model. Open the Spectrum Analyzer block to view the PSD of the sine wave signal. There are two tones at frequencies 5000 Hz and 10,000 Hz, which correspond to the two frequencies at the input.

RBW is the resolution bandwidth. It is the minimum frequency bandwidth that can be resolved by the spectrum analyzer. By default, RBW (Hz) is set to Auto. In this mode, RBW is the ratio of the frequency span to 1024. In a two-sided spectrum, this value is Fs/1024, while in a one-sided spectrum, it is (Fs/2)/1024.

Using this value of RBW, the window length (Nsamples) is computed iteratively using this relationship:

Nsamples=(1Overlap100)*NENBW*FsRBW

Overlap is the amount of overlap between the previous and current buffered data segments. NENBW is the equivalent noise bandwidth of the window. For more information on the details of the spectral estimation algorithm, see Spectral Analysis.

RBW calculated in this mode gives a good frequency resolution.

To distinguish between two frequencies in the display, the distance between the two frequencies must be at least RBW. In this example, the distance between the two peaks is 5000 Hz, which is greater than RBW. Hence, you can see the peaks distinctly. Change the frequency of the second sine wave from 10000 Hz to 5015 Hz. The difference between the two frequencies is less than RBW.

The peaks are not distinguishable. To increase the frequency resolution, decrease RBW to 1 Hz.

The two peaks, which are 15 Hz apart, are now distinguishable.

When you increase the frequency resolution, the window length increases, but the tradeoff is that the time resolution decreases.

Change the Input Signal

When you change the dynamics of the input signal during simulation, the PSD of the signal also changes in real time. While the simulation is running, change the Frequency of the Sine Wave 1 block to 8000 and click Apply. The second tone in the spectral analyzer output shifts to 8000 Hz and you can see the change in real time.

Change the Spectrum Analyzer Settings

When you change the settings in the Spectrum Analyzer block, the effect can be seen on the spectral data in real time.

As an example, in the Spectrum Analyzer block, on the Main options pane, select Window length. The window length is 1024. Run the model.

During the simulation, change the Window length from 1024 to 500 and click anywhere on the screen. The Samples/update (Nsamples) parameter changes to 500.

When Nsamples decreases, RBW increases using this relationship:

When you change any parameter in the spectrum analyzer settings, the effect is immediately seen on the PSD data. For more information on how the Spectrum Analyzer settings affect the spectral density data, see the 'Algorithms' section of the Spectrum Analyzer block reference page.

Convert the Power in Watts to dBW and dBm

The spectrum analyzer provides three units to specify the power spectral density: Watts/Hz, dBm/Hz, and dBW/Hz. Corresponding units of power are Watts, dBm, and dBW. The default unit of Power is dBm.

Power in dBW is given by:

PdBW=10log10(powerinwatt/1watt)

Power in dBm is given by:

PdBm=10log10(powerinwatt/1milliwatt)

For a sine wave signal with an amplitude (A) of 1 V, the power of a one-sided spectrum in Watts is given by:

A2/2

In this example, this power equals 0.5 W. Corresponding power in dBm is given by:

PdBm=10log10(powerinwatt/1milliwatt)PdBm=10log10(0.5/10^3)

Here, the power equals 26.9897 dBm. To confirm this value with a peak finder, click Tools > Measurements > Peak Finder.

For a white noise signal, the spectrum is flat for all frequencies. The spectrum analyzer in this example shows a one-sided spectrum in the range [0 Fs/2]. For a white noise signal with a variance of 1e-4, the power per unit bandwidth (Punitbandwidth) is 1e-4. The total power in watts over the entire frequency range is:

Pwhitenoise=Punitbandwidth*numberoffrequencybins,Pwhitenoise=(104)*(Fs/2RBW),Pwhitenoise=(104)*(2205021.53)

The number of frequency bins is the ratio of total bandwidth to RBW. For a one-sided spectrum, the total bandwidth is half the sampling rate. RBW in this example is 21.53 Hz. With all these values, the total power of the white noise is -39.87 dBm.

Estimate PSD Using the Spectrum Estimator Block

Using the Spectrum Analyzer block, you can view and analyze, but cannot process the PSD data. To process the data, you must compute the spectral density using the Spectrum Estimator block in the dspspect3 library.

Replace the Spectrum Analyzer block in ex_psd_sa with the Spectrum Estimator block followed by an Array Plot block. To view the model, enter ex_psd_estimatorblock in the MATLAB command prompt. In addition, to access the spectral estimation data in MATLAB, connect the To Workspace block to the output of the Spectrum Estimator block. Here are the changes to the settings of the Spectrum Estimator block and the Array Plot block.

BlockParameter ChangesPurpose of the block
Spectrum EstimatorThe following settings align with the Spectrum Analyzer settings in ex_psd_sa. Set:
  • Spectrum type to Power density.

  • Frequency resolution method to Window length.

  • Window length source to Specify on dialog.

  • Window length to 1024.

Computes the power spectral density of the input signal using Welch's method of averaging periodograms
Array PlotClick View and
  • select Style. In the Style window, select the Plot type as Stairs.

  • select Configuration Properties. In the Configuration Properties window, set the Sample increment as 44100/1024. For details, see the section 'Convert the X-axis to Represent Frequency'.

Displays the power spectral density data

The spectrum displayed in the Array Plot block is similar to the spectrum seen in the Spectrum Analyzer block in ex_psd_sa.

Convert x-axis to Represent Frequency

By default, the Array Plot block plots the PSD data with respect to the number of samples per frame. The number of points on the x-axis equals the length of the input frame. The Spectrum analyzer plots the PSD data with respect to frequency. For a one-sided spectrum, the frequency varies in the range [0 Fs/2]. For a two-sided spectrum, the frequency varies in the range [-Fs/2 Fs/2]. To convert the x-axis of the array plot from sample-based to frequency-based, set the Sample Increment parameter in the configuration properties window to Fs/framelength. For a one-sided spectrum, XOffset parameter must be 0. For a two-sided spectrum, XOffset must be -Fs/2. In this example, for a one-sided spectrum, Sample Increment must be 44100/1024.

Live Processing

To process the spectral data while streaming, pass the output of the estimator block into a processing logic.

More About

Was this topic helpful?