estimate the power spectrum in simulink
the power spectrum (ps) 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 power spectral estimation is to estimate the power spectrum 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 power spectrum is estimated using fourier transform methods such as the welch method and the filter bank method. for signals with relatively small length, the filter bank approach produces a spectral estimate with a higher resolution, a more accurate noise floor, and peaks more precise than the welch method, with low or no spectral leakage. these advantages come at the expense of increased computation and slower tracking. for more details on these methods, see . you can also use other techniques such as the maximum entropy method.
in simulink®, you can perform real-time spectral analysis of a dynamic signal using the
block. you can view the spectral data in the spectrum
analyzer. to acquire the last spectral data for further processing, create a object and run the function on this object. alternately, you can use the
block from the
dspspect3
library to compute the power spectrum, and block to view the spectrum.
estimate the power spectrum using the spectrum analyzer
you can view the power spectrum of a signal using the spectrum analyzer block. the power spectrum 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 spectrum of the signal in real time.
open and inspect the model
open and inspect the ex_psd_sa
model. 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.the spectrum analyzer shows the power spectral density of the signal.
run the model
run the model. the spectrum analyzer shows two tones at frequencies 5000 hz and 10000 hz, which correspond to the two frequencies at the input.
rbw, the resolution bandwidth is the minimum frequency bandwidth that can be resolved by the spectrum analyzer. by default, rbw (hz) is set to auto
. in the auto
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. the spectrum analyzer in ex_psd_sa
is configured to show one-sided spectrum. hence, the rbw is (44100/2)/1024 or 21.53 hz.
using this value of rbw, the number of input samples used to compute one spectral update is given by nsamples = fs/rbw, which is 44100/21.53 or 2048.
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.
on zooming, you can see that the peaks are not distinguishable.
to increase the frequency resolution, decrease rbw to 1 hz and run the simulation.
on zooming, the two peaks, which are 15 hz apart, are now distinguishable.
when you increase the frequency resolution, the time resolution decreases. to maintain a good balance between the frequency resolution and time resolution, change the rbw (hz) to auto
.
change the input signal
when you change the dynamics of the input signal during simulation, the power spectrum 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.
when the model is running, in the spectrum tab of the spectrum analyzer toolstrip, change the frequency scale to log
. the power spectrum is now displayed on a log scale.
for more information on how the spectrum analyzer settings affect the power spectrum data, see the 'algorithms' section of the block reference page.
estimate power spectrum using the spectrum estimator block
alternately, you can compute the power spectrum of the signal using the block in the dspspect3
library. you can acquire the output of the spectrum estimator and store the data for further processing.
open and run the model
replace the spectrum analyzer block in ex_psd_sa
with the block followed by an block. open the equivalent ex_psd_estimatorblock
model. in addition, to access the spectral estimation data in matlab, connect the (simulink) block to the output of the spectrum estimator block.
the spectrum displayed in the array plot block is similar to the spectrum seen in the spectrum analyzer block in ex_psd_sa
.
the filter bank approach produces peaks that have very minimal spectral leakage.
convert x-axis to represent frequency
by default, the array plot block plots the power spectrum 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 power spectrum 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, do the following:
click the settings icon in the plot tab of the array plot window. under data and axes, set sample increment to fs/framelength.
for a one-sided spectrum, set x-offset to 0.
for a two-sided spectrum, set x-offset to -fs/2.
in this example, the spectrum is one-sided and hence, the sample increment and x-offset are set to 44100/1024 and 0, respectively. to specify the frequency in khz, set the sample increment to 44.1/1024.
live processing
the output of the spectrum estimator block contains the spectral data and is available for further processing. the data can be processed in real-time or it can be stored in the workspace using the to workspace block. this example writes the spectral data to the workspace variable estimate
.