Signal Processing Toolbox
dspdata.msspectrum

Mean-square (power) spectrum

Syntax

• Hmss = dspdata.msspectrum(Data)
Hmss = dspdata.msspectrum(Data,Frequencies)
Hmss = dspdata.msspectrum(...,'Fs',Fs)
Hmss = dspdata.msspectrum(...,'SpectrumType',SpectrumType)
Hmss = dspdata.msspectrum(...,'CenterDC',flag)

Description

The mean-squared spectrum (MSS) is intended for discrete spectra. Unlike the power spectral density (PSD), the peaks in the MSS reflect the power in the signal at a given frequency. The MSS of a signal is the Fourier transform of that signal's autocorrelation.

Hmss = dspdata.msspectrum(Data) uses the mean-square (power) spectrum data contained in Data, which can be in the form of a vector or a matrix, where each column is a separate set of data. Default values for other properties of the object are as follows:

.

 Property Default Value Description Name 'Mean-square Spectrum' Read-only string Frequencies []type double Vector of frequencies at which the spectrum is evaluated. The range of this vector depends on the SpectrumType value. For a one-sided spectrum, the default range is [0, pi) or [0, Fs/2) for odd length, and [0, pi] or [0, Fs/2] for even length, if Fs is specified. For a two-sided spectrum, it is [0, 2pi) or [0, Fs). The length of the Frequencies vector must match the length of the columns of Data.If you do not specify Frequencies, a default vector is created. If one-sided is selected, then the whole number of FFT points (nFFT) for this vector is assumed to be even.If onesided is selected and you specify Frequencies, the last frequency point is compared to the next-to-last point and to pi (or Fs/2, if Fs is specified). If the last point is closer to pi (or Fs/2) than it is to the previous point, nFFT is assumed to be even. If it is closer to the previous point, nFFT is assumed to be odd. Fs `Normalized' Sampling frequency, which is 'Normalized' if NormalizedFrequency is true. If NormalizedFrequency is false Fs defaults to 1 Hz. SpectrumType 'Onesided' Nyquist interval over which the power spectrum is calculated. Valid values are 'Onesided' and 'Twosided'. See the onesided and twosided methods in dspdata for information on changing this property.The interval for Onesided is [0 pi) or [0 pi] depending on the number of FFT points, and for Twosided the interval is [0 2pi). NormalizedFrequency true Whether the frequency is normalized (true) or not (false). This property is set automatically at construction time based on Fs. If Fs is specified, NormalizedFrequency is set to false. See the normalizefreq method in dspdata for information on changing this property.

Hmss = dspdata.msspectrum(Data,Frequencies) uses the power spectrum data contained in Data and Frequencies vectors.

Hmss = dspdata.msspectrum(...,'Fs',Fs) uses the sampling frequency Fs. Specifying Fs uses a default set of linear frequencies (in Hz) based on Fs and sets NormalizedFrequency to false.

Hmss = dspdata.msspectrum(...,'SpectrumType',SpectrumType) uses the SpectrumType string to specify the interval over which the power spectrum was calculated. For data that ranges from [0 pi) or [0 pi], set the SpectrumType to onesided; for data that ranges from [0 2pi), set the the SpectrumType to twosided.

Hmss = dspdata.msspectrum(...,'CenterDC',flag) uses the value of flag to indicate whether the zero-frequency (DC) component is centered. If flag is true, it indicates that the DC component is in the center of the two-sided spectrum. Set the flag to false if the DC component is on the left edge of the spectrum.

Methods

Methods provide ways of performing functions directly on your dspdata object without having to specify the parameters again. You can apply a method directly on the variable you assigned to your dspdata.msspectrum object. You can use the following methods with a dspdata.msspectrum object.

• centerdc
• normalizefreq
• onesided
• plot
• twosided

For example, to normalize the frequency and set the NormalizedFrequency parameter to true, use

• Hmss = normalizefreq(Hs)

For detailed information on using the methods and plotting the spectrum, see the dspdata reference page.

Examples

This example shows how to view the spectral content of two sinusoids with random noise.

• Fs = 32e3;
t = 0:1/Fs:2.96;
x = cos(2*pi*t*1.24e3)+cos(2*pi*t*10e3)+randn(size(t));
X = fft(x);
P = (abs(X)/length(x)).^2;        % Compute the mean-square.

% Create data object.
Hmss = dspdata.msspectrum(P,'Fs',Fs,'centerdc',true);
plot(Hmss);                       % Plot the mean-square spectrum.