# spectrumAnalyzer

Display frequency spectrum of time-domain signals

## Description

The spectrumAnalyzer object displays frequency-domain signals and the frequency spectrum of time-domain signals. The scope shows the spectrum view and the spectrogram view. The object performs spectral estimation using the filter bank method and Welch's method of averaged modified periodograms. You can customize the spectrum analyzer display to show the data and the measurement information that you need. For more details, see Algorithms. The spectrum analyzer can display the power spectrum of the signal in three units, Watts, dBm, and dBW. For more information on how to convert the power within these three units, see Convert the Power Between Units.

To display the spectra of signals in the Spectrum Analyzer:

1. Create the spectrumAnalyzer object and set its properties.

2. Call the object with arguments, as if it were a function.

## Creation

### Description

example

scope = spectrumAnalyzer creates a spectrumAnalyzer object that displays the frequency spectrum of real or complex signals.

scope = spectrumAnalyzer(Name=Value) specifies nondefault properties for scope using one or more name-value arguments. For example, to display both spectrum and spectrogram, set ViewType to "spectrum-and-spectrogram".

## Properties

expand all

### Frequently Used

The domain of the input signal you want to visualize, specified as "time" or "frequency". If you want to visualize time-domain signals, the Spectrum Analyzer transforms the signal to the frequency spectrum based on the algorithm you specify in the Method property.

#### Scope Window Use

In the Estimation tab on the Spectrum Analyzer toolstrip, set Input Domain to Time or Frequency.

Data Types: char | string

The type of spectrum to display, specified as one of the following:

• "power" — Power spectrum.

• "power-density" — Power spectral density. The power spectral density is the squared magnitude of the spectrum normalized to a bandwidth of 1 hertz.

• "rms" — Root mean square. The root-mean-square shows the square root of the mean square. Use this option to view the frequency of voltage or current signals.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "time".

#### Scope Window Use

In the Analyzer tab on the Spectrum Analyzer toolstrip, click the drop down arrow of to select Power, Power Density, or RMS.

To enable these options, set the Input Domain on the Estimation tab to Time.

Data Types: char | string

View to display, specified as one of the following:

• "spectrum" — Display frequency spectrum of signals.

• "spectrogram" — Display spectrogram of signals. Spectrogram shows the frequency content over time. Each line of the spectrogram is one periodogram. Time scrolls from the top to the bottom of the display. The most recent spectrogram update is at the top of the display.

• "spectrum-and-spectrogram" — Display both spectrum and spectrogram.

Tunable: Yes

#### Scope Window Use

In the Analyzer tab on the Spectrum Analyzer toolstrip, select , , or both.

Data Types: char | string

The sample rate of the input in Hz, specified as a positive scalar.

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the Bandwidth section, specify Sample Rate (Hz) to a finite scalar.

The Spectrum Analyzer shows the sample rate in the status bar at the bottom of the display.

Data Types: double

Spectrum estimation method, specified as one of the following:

• "filter-bank" –– Use an analysis filter bank to estimate the power spectrum. Compared to Welch's method, this method has a lower noise floor, better frequency resolution, and lower spectral leakage and requires fewer samples per update.

• "welch" –– Use Welch's method of averaged modified periodograms.

For more details on these methods, see Algorithms.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "time".

#### Scope Window Use

In the Estimation tab of the Spectrum Analyzer toolstrip, set Method to Filter bank or Welch.

To enable this parameter, set Input Domain to Time in the Estimation tab.

Data Types: char | string

Option to plot spectrum as two-sided, specified as one of the following:

• true — Compute and plot two-sided spectral estimates. When the input signal is complex-valued, you must set this property to true.

• false — Compute and plot one-sided spectral estimates. If you set this property to false, then the input signal must be real-valued.

When you set this property to false, the Spectrum Analyzer uses power-folding. The y-axis values are twice the amplitude that they would be if you were to set this property to true, except at 0 and the Nyquist frequency. A one-sided power spectral density (PSD) contains the total power of the signal in the frequency interval from DC to half the Nyquist rate. For more information, see pwelch.

#### Scope Window Use

Click the Spectrum tab or the Spectrogram tab (if enabled) of the Spectrum Analyzer toolstrip. In the section, select Two-Sided Spectrum to compute and plot two-sided spectral estimates.

Data Types: logical

Scale to display frequency, specified as one of the following:

• "linear" — Use a linear scale to display frequencies on the x-axis.

• "log" — Use a logarithmic scale to display frequencies on the x-axis.

Tunable: Yes

#### Dependency

To set this property to "log", set the PlotAsTwoSidedSpectrum property to false.

#### Scope Window Use

Click the Spectrum tab or the Spectrogram tab (if enabled) of the Spectrum Analyzer toolstrip. In the section, set the Frequency Scale to Linear or Log.

To set the Frequency Scale to Log, clear the Two-Sided Spectrum check box in the section in the Spectrum or the Spectrogram tab (if enabled). If you select the Two-Sided Spectrum check box, then you must set the Frequency Scale to Linear.

Data Types: char | string

Type of plot to use for displaying normal traces, specified as "line" or "stem". Normal traces are traces that display free-running spectral estimates.

Tunable: Yes

#### Dependencies

To enable this property, set:

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip, navigate to the section and click . In the Spectrum Analyzer Settings window that opens, under Display and Labels, set Plot Type to Line or Stem.

To enable the Plot Type, you must:

• Select in the Views section of the Analyzer tab.

• Enable the Normal Trace check box in the Trace Options section of the Spectrum tab.

Data Types: char | string

Axes scaling mode, specified as one of the following:

• "auto" — The scope scales the axes to fit the data, both during and after simulation.

• "manual" — The scope does not scale the axes automatically.

• "onceatstop" — The scope scales the axes when the simulation stops and you call the release function.

• "updates" — The scope scales the axes after a specific number of visual updates. It determines the number of updates using the AxesScalingNumUpdates property.

Tunable: Yes

Data Types: char | string

Number of updates before scaling, specified as a positive integer.

Tunable: Yes

#### Dependency

To enable this property, set AxesScaling to "updates".

Data Types: double

The source of the resolution bandwidth (RBW), specified as "auto" or "property".

• "auto" — The Spectrum Analyzer adjusts the spectral estimation resolution to ensure that there are 1024 RBW intervals over the defined frequency span.

• "property" — Specify the resolution bandwidth directly using the RBW property.

Tunable: Yes

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the section, set RBW (Hz) to either Auto or a positive scalar.

Data Types: char | string

Resolution bandwidth (RBW) in Hz, specified as a positive scalar. Specify the value to ensure that there are at least two RBW intervals over the specified frequency span. The ratio of the overall span to RBW satisfies this condition:

$\frac{span}{RBW}>2$

Specify the overall span based on how you set the FrequencySpan property.

RBW controls the spectral resolution of the displayed signal. The RBW value determines the spacing between frequencies that can be resolved. A smaller value gives a higher spectral resolution and lowers the noise floor. That is, the Spectrum Analyzer can resolve frequencies that are closer to each other. However, this comes at the cost of a longer sweep time.

Tunable: Yes

#### Dependency

To enable this property, set RBWSource to "property".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the section, set RBW (Hz) to a positive scalar.

The Spectrum Analyzer shows the value of RBW in the status bar at the bottom of the display.

Data Types: double

Sharpness of the prototype lowpass filter, specified as a real nonnegative scalar in the range [0,1].

Increasing the filter sharpness decreases the spectral leakage and gives a more accurate power reading.

Tunable: Yes

#### Dependencies

To enable this property, set Method to "filter-bank".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, move the Sharpness slider.

To enable this parameter, set Input Domain to Time in the Estimation tab.

Data Types: double

Source of the frequency vector, specified as one of the following:

• "auto" — The Spectrum Analyzer computes the frequency vector based on the frame size of the input signal and the specified sample rate.

• "property" — Enter a custom vector in the FrequencyVector property.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "frequency".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency (Hz) to either Auto or a monotonically increasing vector of length equal to the input signal frame size.

To enable the Frequency (Hz), set Input Domain to Frequency.

Data Types: char | string

Custom frequency vector, specified as a monotonically increasing vector. This vector determines the x-axis of the display. The vector must be monotonically increasing and must have the same length as the input signal frame size.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency (Hz) to either Auto or a monotonically increasing vector of length equal to the input signal frame size.

To enable the Frequency (Hz), set Input Domain to Frequency.

Data Types: double

Frequency span mode, specified as one of the following:

• "full" –– The Spectrum Analyzer computes and plots the spectrum over the entire Nyquist Frequency Interval.

• "span-and-center-frequency" –– The Spectrum Analyzer computes and plots the spectrum over the interval specified by the Span and CenterFrequency properties.

• "start-and-stop-frequencies" –– The Spectrum Analyzer computes and plots the spectrum over the interval specified by the StartFrequency and StopFrequency properties.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "time".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency Span to Full, Span and Center Frequency, or Start and Stop Frequencies.

To enable the Frequency Span, set Input Domain to Time.

Data Types: char | string

Frequency span over which the Spectrum Analyzer computes and plots the spectrum, specified as a positive scalar in Hz. The overall span, defined by this property and the CenterFrequency property, must fall within the Nyquist Frequency Interval.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency Span to Span and Center Frequency and Span (Hz) to a positive scalar.

To enable the Frequency Span, set Input Domain to Time.

Data Types: double

Center of frequency span over which the Spectrum Analyzer computes and plots the spectrum, specified as a real scalar in Hz. The overall frequency span, defined by Span and this property, must fall within the Nyquist Frequency Interval.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency Span to Span and Center Frequency and Center Frequency (Hz) to a real scalar.

To enable the Frequency Span, set Input Domain to Time.

Data Types: double

Starting frequency in the frequency interval over which the Spectrum Analyzer computes and plots the spectrum, specified as a real scalar in Hz. The overall span, which is defined by this property and StopFrequency, must fall within the Nyquist Frequency Interval.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency Span to Start and Stop Frequencies and Start Frequency (Hz) to a real scalar.

To enable the Frequency Span, set Input Domain to Time.

Data Types: double

Ending frequency in the frequency interval over which the Spectrum Analyzer computes and plots the spectrum, specified as a real scalar in Hz. The overall span, which is defined by this property and the StartFrequency property, must fall within the Nyquist Frequency Interval.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Frequency Span to Start and Stop Frequencies and Stop Frequency (Hz) to a real scalar.

To enable the Frequency Span, set Input Domain to Time.

Data Types: double

Percentage of overlap between the previous and current buffered data segments, specified as a scalar in the range [0 100). The overlap creates a window segment that the object uses to compute a spectral estimate.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the Window Options section, set the Overlap (%).

To enable the Overlap (%), set Input Domain to Time and Method to Welch in the Estimation tab on the Spectrum Analyzer toolstrip.

Data Types: double

Window function, specified as one of the following preset windows. For more information on a window option, click the link to the corresponding function.

Window OptionCorresponding Signal Processing Toolbox™ Function
"hann"hann
"blackman-harris"blackmanharris
"chebyshev"chebwin
"flat-top"flattopwin
"hamming"hamming
"kaiser"kaiser
"rectangular"rectwin

To use your own spectral estimation window, set this property to "custom" and specify a custom window function in the CustomWindow property.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the Window Options section, set the Window.

To enable the Window, set Input Domain to Time and Method to Welch in the Estimation tab on the Spectrum Analyzer toolstrip.

Data Types: char | string

Name of custom window function, specified as a character array or string scalar. The custom window function name must be on the MATLAB® path. Use this property to customize a window function using additional properties available with the Signal Processing Toolbox.

Tunable: Yes

#### Example:

Define and use a custom window function.

function w = my_hann(L)
w = hann(L,"periodic")
end

scope.Window = "custom";
scope.CustomWindow = "my_hann"

#### Dependency

To use this property, set Window to "custom".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the Window Options section, for the Window, enter a custom window function name.

Data Types: char | string

Sidelobe attenuation of the window in decibels (dB), specified as a positive scalar greater than or equal to 45.

Tunable: Yes

#### Dependency

To enable this property, set Window to "chebyshev" or "kaiser".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the Window Options section, set the Attenuation (dB).

To enable the Attenuation (dB), set:

• Input Domain to Time

• Method to Welch

• Window to either Chebyshev or Kaiser in the Estimation tab on the Spectrum Analyzer toolstrip.

Data Types: double

Averaging method, specified as one of the following:

• "vbw" — Video bandwidth method. The object uses a lowpass filter to smooth the trace and decrease noise. Use the VBWSource and VBW properties to specify the VBW value.

• "exponential" — Weighted average of samples. The object computes the average over samples weighted by an exponentially decaying forgetting factor. Use the ForgettingFactor property to specify the weighted forgetting factor.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "time".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Averaging Method to VBW or Exponential.

To enable the Averaging Method, set Input Domain to Time.

Data Types: char | string

Forgetting factor of the exponential weighted averaging method, specified as a scalar in the range [0,1].

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, adjust the slider for Forgetting Factor.

To enable the Forgetting Factor, set Input Domain to Time and Averaging Method to Exponential.

Data Types: double

Source of the video bandwidth (VBW), specified as either "auto" or "property".

• "auto" — The Spectrum Analyzer adjusts the VBW such that the equivalent forgetting factor is 0.9.

• "property" — The Spectrum Analyzer adjusts the VBW using the value specified in the VBW property.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "time" and AveragingMethod to vbw.

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set VBW (Hz) to either Auto or a positive real scalar less than or equal to Sample Rate (Hz)/2.

To enable the VBW (Hz), set Input Domain to Time and Averaging Method to VBW.

Data Types: char | string

Video bandwidth, specified as a positive scalar less than or equal to SampleRate/2. For more details on the video bandwidth method, see Averaging Method.

The Spectrum Analyzer shows the value of VBW in the status bar at the bottom of the display.

Tunable: Yes

#### Dependency

To enable this property, set VBWSource to "property".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set VBW (Hz) to either Auto or enter a positive real scalar that is less than or equal to Sample Rate (Hz)/2.

To enable the VBW (Hz), set Input Domain to Time and Averaging Method to VBW.

Data Types: double

Units of the frequency-domain input, specified as "dBm", "dBV", "dBW", "Vrms", "Watts", or "none". The Spectrum Analyzer scales frequency data according to the specified display unit.

Tunable: Yes

#### Dependency

To enable this property, set InputDomain to "frequency".

#### Scope Window Use

Click the Estimation tab on the Spectrum Analyzer toolstrip. In the section, set Input Unit.

To enable the Input Unit, set Input Domain to Frequency.

Data Types: char | string

Units in which the Spectrum Analyzer displays power values, specified as one of the following:

• "dBm"

• "dBFS"

• "dBV"

• "dBW"

• "Vrms"

• "Watts"

• "dBm/Hz"

• "dBW/Hz"

• "dBFS/Hz"

• "Watts/Hz"

• "auto"

Tunable: Yes

#### Dependency

The spectrum units available depend on the value you specify in the SpectrumType property.

InputDomainSpectrumTypeAllowed SpectrumUnits
"time""power""dBm", "dBW", "dBFS", "Watts"
"power-density""dBm/Hz", "dBW/Hz","dBFS/Hz", "Watts/Hz"
"rms""dBV", "Vrms"
"frequency""auto", "dBm", "dBV", "dBW", "Vrms", "Watts"

If you set the InputDomain property to "frequency" and the SpectrumUnits property to "auto", the Spectrum Analyzer assumes the spectrum units to be equal to input units specified in the InputUnits property. If you set InputDomain to "time" and SpectrumUnits to any option other than "auto", the Spectrum Analyzer converts the units specified in InputUnits to the units specified in SpectrumUnits.

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip. In the section, set Spectrum Unit.

Data Types: char | string

Source of the dBFS scaling factor, specified as either "auto" or "property".

• "auto" –– The Spectrum Analyzer adjusts the scaling factor based on the input data.

• "property" –– Specify the full-scale scaling factor using the FullScale property.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip. In the section, set the Full Scale to either Auto or a positive scalar.

To enable the Full Scale:

• In the Analyzer tab, set the spectrum type to Power or Power Density.

• In the Estimation tab, set Input Domain to Time.

• In the Spectrum tab, set Spectrum Unit to dBFS or dBFS/Hz (when spectrum type is set to Power Density).

Data Types: char | string

dBFS full scale, specified a positive scalar.

Tunable: Yes

#### Dependency

To enable this property, set:

1. InputDomain to "time"

2. SpectrumType to "power" or "power-density"

3. SpectrumUnits to "dBFS" or "dBFS/Hz"

4. FullScaleSource to "property"

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip. In the section, set the Full Scale to either Auto or enter a positive scalar.

To enable the Full Scale:

• In the Analyzer tab, set the spectrum type to Power or Power Density.

• In the Estimation tab, set Input Domain to Time.

• In the Spectrum tab, set Spectrum Unit to dBFS or dBFS/Hz (when spectrum type is set to Power Density).

Data Types: double

Load that the scope uses as a reference to compute power levels, specified as a positive scalar in Ohms.

Tunable: Yes

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip. In the section, set Reference Load (Ω).

Data Types: double

Offset to apply to the frequency axis (x-axis) in units of Hz, specified as one of the following:

• Scalar — Apply the same frequency offset to all channels.

• Vector — Apply a specific frequency offset for each channel. The vector length must be equal to the number of input channels.

The overall span must fall within the Nyquist Frequency Interval. You can control the overall span in different ways based on how you set the FrequencySpan property.

Tunable: Yes

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the section, set Offset (Hz).

Data Types: double

### Spectrogram

Channel for which the spectrogram is plotted, specified as a positive integer in the range [1 N], where N is the number of input channels.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrogram" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Spectrogram tab on the Spectrum Analyzer toolstrip. In the Channel section, select a Channel.

Data Types: double

Source of the time resolution of each spectrogram line, specified as either "auto" or "property".

When you set RBWSource and TimeResolutionSource to "auto", then RBW is set such that there are 1024 RBW intervals in one frequency span. The time resolution is set to 1/RBW.

When RBWSource is set to "auto" and TimeResolutionSource is set to "property", then time resolution becomes the main control and RBW is set to 1/TimeResolution Hz.

When RBWSource is set to "property" and TimeResolutionSource is set to "auto", then RBW becomes the main control and the time resolution is set 1/RBW s.

When both RBWSource and TimeResolutionSource are set to "property", then the specified time resolution value must be equal to or larger than the minimum attainable time resolution which is defined by 1/RBW. Several spectral estimates are combined into one spectrogram line to obtain the desired time resolution.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrogram" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Spectrogram tab on the Spectrum Analyzer toolstrip. In the Time Options section, set the Time Resolution (s) to Auto or enter a positive scalar.

To enable the Time Resolution (s), select Spectrogram in the Analyzer tab.

Data Types: char | string

Time resolution of each spectrogram line in seconds, specified as a positive scalar.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Spectrogram tab on the Spectrum Analyzer toolstrip. In the Time Options section, set the Time Resolution (s) to Auto or enter a positive scalar.

To enable the Time Resolution (s), select Spectrogram in the Analyzer tab.

Data Types: double

Source for the time span of the spectrogram, specified as either one of these:

• "auto" –– The spectrogram displays 100 spectrogram lines at any given time.

• "property" –– The spectrogram uses the time duration you specify in seconds in the TimeSpan property.

The time span that you specify must be at least two times larger than the duration of the number of samples required for a spectral update.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrogram" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Spectrogram tab on the Spectrum Analyzer toolstrip. In the Time Options section, set the Time Span (s) to Auto or enter a positive scalar.

Data Types: char | string

Time span of the spectrogram display in seconds, specified as a positive scalar. You must set the time span to be at least twice as large as the duration of the number of samples required for a spectral update.

Tunable: Yes

#### Dependency

To enable this property, set:

#### Scope Window Use

Click the Spectrogram tab on the Spectrum Analyzer toolstrip. In the Time Options section, set the Time Span (s) to Auto or enter a positive scalar.

Data Types: double

### Measurements

The channel for which you need to obtain measurements, specified as a positive integer in the range [1 N], where N is the number of input channels.

Tunable: Yes

#### Scope Window Use

Click the Measurements tab on the Spectrum Analyzer toolstrip. In the Channel section, select a Channel.

Data Types: double

Channel measurements, specified as a ChannelMeasurementsConfiguration object. Enable channel measurements to compute and display the occupied bandwidth or adjacent channel power ratio. All ChannelMeasurementsConfiguration properties are tunable.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to either "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Channel Measurements tab on the Spectrum Analyzer toolstrip and modify the measurement settings.

The Channel Measurements tab appears when you select Spectrum in the Analyzer tab.

Cursor measurements, specified as a CursorMeasurementsConfiguration object. Enable cursor measurements to display waveform cursors. All CursorMeasurementsConfiguration properties are tunable.

Tunable: Yes

#### Scope Window Use

Click the Measurements tab on the Spectrum Analyzer toolstrip and modify the cursor measurements in the Cursors section.

Distortion measurements, specified as a DistortionMeasurementsConfiguration object. Enable distortion measurements to compute and display the harmonic distortion and intermodulation distortion. All DistortionMeasurementsConfiguration properties are tunable. For more details, see Distortion Measurements and Harmonic Measurements.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to either "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Measurements tab on the Spectrum Analyzer toolstrip and modify the distortion measurements in the Distortion section.

The Measurements tab appears when you select Spectrum in the Analyzer tab.

Peak finder measurement, specified as a PeakFinderConfiguration object. Enable peak finder to compute and display the largest calculated peak values. All PeakFinderConfiguration properties are tunable.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to either "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Measurements tab on the Spectrum Analyzer toolstrip and modify the peak finder measurements in the Peaks section.

The Measurements tab appears when you select Spectrum in the Analyzer tab.

Spectral mask configuration, specified as a SpectralMaskConfiguration object. Use the spectral mask configuration to draw upper and lower or upper or lower mask lines in the power and power-density plots. All SpectralMaskConfiguration properties are tunable.

Tunable: Yes

#### Dependency

To enable this property, set:

• ViewType to either "spectrum" or "spectrum-and-spectrogram".

• SpectrumType to either "power" or "power-density".

#### Scope Window Use

Click the Spectral Mask tab on the Spectrum Analyzer toolstrip and modify the settings.

The Spectral Mask tab appears when you:

• Select Spectrum in the Analyzer tab.

• In the drop-down list under Spectrum, choose either Power or Power Density.

### Visualization

Title of the scope window.

Tunable: Yes

Data Types: char | string

Spectrum Analyzer window position in pixels, specified as a four-element double vector of the form [left bottom width height]. You can place the scope window in a specific position on your screen by modifying the values of this property.

By default, the window appears at the center of your screen with a width of 800 pixels and height of 500 pixels. The exact center coordinates depend on your screen resolution.

Tunable: Yes

Maximize axes control, specified as one of the following:

• "auto" –– The Spectrum Analyzer maximizes axes only if the display does not contain any labels or title annotations.

• "on" –– The Spectrum Analyzer maximizes axes in all displays.

• "off" –– The Spectrum Analyzer does not maximize axes in any display.

Tunable: Yes

Data Types: char | string

To remove normal traces from the display, set this property to false. These traces display the free-running spectral estimates. The Spectrum Analyzer continues its spectral computations even when you set this property to false.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip and select the Normal Trace check box in the Trace Options section.

To enable the Normal Trace check box, select Spectrum in the Analyzer tab.

Data Types: logical

Option to plot max-hold trace, specified as true or false. To compute and plot the maximum-hold spectrum of each input channel, set this property to true. The Spectrum Analyzer computes the maximum-hold spectrum at each frequency bin by keeping the maximum value of all the power spectrum estimates. When you change the value of this property, the Spectrum Analyzer resets its maximum-hold computations.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip and select the Max-Hold Trace check box in the Trace Options section.

To enable the Max-Hold Trace check box, select Spectrum in the Analyzer tab.

Data Types: logical

Option to plot min-hold trace, specified as true or false. To compute and plot the minimum-hold spectrum of each input channel, set this property to true. The Spectrum Analyzer computes the minimum-hold spectrum at each frequency bin by keeping the minimum value of all the power spectrum estimates. When you change the value of this property, the Spectrum Analyzer resets its minimum-hold computations.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Spectrum tab on the Spectrum Analyzer toolstrip and select the Min-Hold Trace check box in the Trace Options section.

To enable the Min-Hold Trace check box, select Spectrum in the Analyzer tab.

Data Types: logical

Specify the display title as a character vector or string.

Tunable: Yes

#### Scope Window Use

Open the Configuration Properties. Set Title.

Data Types: char | string

y-axis label, specified as a character vector or a string scalar. The Spectrum Analyzer displays the label to the left of the y-axis.

Regardless of this property, Spectrum Analyzer always displays power units as one of the SpectrumUnits values.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the Configuration section, click . In the Spectrum Analyzer Settings window that opens up, under Display and labels, enter Y-Label.

To enable the Y-Label, select Spectrum in the Analyzer tab.

Data Types: char | string

y-axis limits, specified as a two-element numeric vector of the form [ymin ymax]. The units of the y-axis limits depend on the SpectrumUnits property.

Example: scope.YLimits = [-10,20]

Tunable: Yes

#### Dependencies

To enable this property, set the ViewType property to "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the Configuration section, click . In the Spectrum Analyzer Settings window that opens up, under Display and Labels, enter Y-Axis Limits.

To enable the Y-Axis Limits, select Spectrum in the Analyzer tab.

Color limits of the spectrogram, specified as a two-element numeric vector of the form [colorMin colorMax]. The units of the color limits directly depend upon the SpectrumUnits property.

Example: scope.ColorLimits = [-10,20]

Tunable: Yes

#### Dependencies

To enable this property, set the ViewType property to "spectrogram" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the Configuration section, click . In the Spectrum Analyzer Settings window that opens up, under Display and Labels, enter Color Limits.

To enable the Color Limits, select Spectrogram in the Analyzer tab.

Color look-up table, specified as a valid colormap name or a three-column matrix with values in the range [0,1] defining RGB triplets.

Tunable: Yes

#### Dependencies

To enable this property, set the ViewType property to "spectrogram" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. In the Configuration section, click . In the Spectrum Analyzer Settings window that opens up, under Display and Labels, enter Color Map.

To enable the Color Map, select Spectrogram in the Analyzer tab.

Data Types: double | char | string

Set this property to true to show gridlines on the plot.

Tunable: Yes

#### Scope Window Use

Open the Configuration Properties. On the Display tab, set Show grid.

Data Types: logical

Show or hide the legend, specified as true or false. To show a legend with the input names, set this property to true.

Use the legend to control which signals are visible. In the scope legend, click a signal name to hide the signal in the scope. To show the signal, click the signal name again. To show only one signal, right-click the signal name. To show all signals, press Esc.

Tunable: Yes

#### Dependencies

To enable this property, set the ViewType property to "spectrum" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. To see the legend, click in the Configuration section.

To enable the Legend, select Spectrum in the Analyzer tab.

Data Types: logical

Show or hide color bar, specified as true or false.

Tunable: Yes

#### Dependencies

To enable this property, set the ViewType property to "spectrogram" or "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. To see the color bar, click in the Configuration section.

To enable the , select Spectrogram in the Analyzer tab.

Data Types: logical

Specify the input channel names as a cell array of character vectors or an array of strings. The names appear in the legend, Style dialog box, and Measurements panels. If you do not specify names, the channels are labeled as Channel 1, Channel 2, etc.

Tunable: Yes

#### Dependency

To see channel names, set ShowLegend to true.

#### Scope Window Use

On the legend, double-click the channel name.

Data Types: char

Layout of the axes, specified as one of "vertical" or "horizontal". A vertical layout stacks the spectrum above the spectrogram. A horizontal layout puts the two views side-by-side.

Tunable: Yes

#### Dependency

To enable this property, set ViewType to "spectrum-and-spectrogram".

#### Scope Window Use

Click the Analyzer tab on the Spectrum Analyzer toolstrip. Select Spectrum and Spectrogram. In the Configuration section, select and update Layout.

Data Types: char | string

## Usage

### Description

example

scope(signal) displays the frequency spectrum of the time-domain signal in the Spectrum Analyzer. If signal is a frequency-domain signal, the signal is displayed directly in the Spectrum Analyzer.

scope(signal1,signal2,...,signalN) displays the frequency spectrum of multiple signals in the Spectrum Analyzer. The number of channels in each signal can be different but the frame size of each signal should be the same.

### Input Arguments

expand all

Input signal or signals to visualize, specified as a scalar, vector, or a matrix. The number of channels in each signal can be different but the frame size of each signal should be the same.

This scope supports variable-size input signals. That is, the frame size (number of rows) of the input signals can change during simulation, but the number of channels (number of columns) cannot change.

When you set the InputDomain property to "time", the input signals can be real or complex. When you set the InputDomain property to "frequency", the input signals must be real.

Example: scope(signal1,signal2)

#### Scope Window Use

To change the appearance of signals in the Spectrum Analyzer, click the tab and then click . In the Spectrum Analyzer Settings window, under Color and styling, select a signal and modify its style, width, color, and marker type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi
Complex Number Support: Yes

## Object Functions

expand all

 generateScript Generate MATLAB script to create scope with current settings getMeasurementsData Get the current measurement data displayed on the spectrum analyzer getSpectralMaskStatus Get test results of current spectral mask getSpectrumData Save spectrum data shown in spectrum analyzer isNewDataReady Check spectrum analyzer for new data
 show Display scope window hide Hide scope window isVisible Determine visibility of scope
 step Run System object algorithm release Release resources and allow changes to System object property values and input characteristics reset Reset internal states of System object

Note

If you want to restart the simulation from the beginning, call reset to clear the scope window display. Do not call reset after calling release.

## Examples

collapse all

View a one-sided power spectrum made from the sum of fixed real sine waves with different amplitudes and frequencies.

Fs = 100e6;  % Sample rate
fSz = 5000;  % Frame size

sin1 = dsp.SineWave(1e0,5e6,0,SamplesPerFrame=fSz,SampleRate=Fs);
sin2 = dsp.SineWave(1e-1,15e6,0,SamplesPerFrame=fSz,SampleRate=Fs);
sin3 = dsp.SineWave(1e-2,25e6,0,SamplesPerFrame=fSz,SampleRate=Fs);
sin4 = dsp.SineWave(1e-3,35e6,0,SamplesPerFrame=fSz,SampleRate=Fs);
sin5 = dsp.SineWave(1e-4,45e6,0,SamplesPerFrame=fSz,SampleRate=Fs);

scope = spectrumAnalyzer(SampleRate=Fs,AveragingMethod="exponential",...
PlotAsTwoSidedSpectrum=false,...
RBWSource="auto",SpectrumUnits="dBW");

for idx = 1:250
y1 = sin1();
y2 = sin2();
y3 = sin3();
y4 = sin4();
y5 = sin5();
scope(y1+y2+y3+y4+y5+0.0001*randn(fSz,1));
end

Call the release function to let property values and input characteristics change. The scope automatically scales the axes.

release(scope)

Run the clear function to close the Spectrum Analyzer window.

clear('scope');

View a two-sided power spectrum of a noisy sine wave on the Spectrum Analyzer.

sin = dsp.SineWave(Frequency=100,SampleRate=1000,...
SamplesPerFrame=1000);
scope = spectrumAnalyzer(SampleRate=sin.SampleRate);
for ii = 1:250
x = sin() + 0.05*randn(1000,1);
scope(x);
end

Call the release function to change property values and input characteristics. The scope automatically scales the axes and updates the display one more time if the internal buffer contains any more data.

release(scope);

Run the MATLAB clear function to close the Spectrum Analyzer window.

clear('scope');

Plot the spectrogram for a chirp signal with added random noise.

Fs = 233e3;
frameSize = 20e3;
chirp = dsp.Chirp(SampleRate=Fs,SamplesPerFrame=frameSize,...
InitialFrequency=11e3,TargetFrequency=11e3+55e3);

scope = spectrumAnalyzer(SampleRate=Fs,...
AveragingMethod="exponential",...
ForgettingFactor=0.3,ViewType="spectrogram",...
RBWSource="property",RBW=500,...
TimeSpanSource="property",TimeSpan=2);

scope.PlotAsTwoSidedSpectrum = false;

for idx = 1:50
y = chirp()+0.05*randn(frameSize,1);
scope(y);
end
release(scope)

Use the Spectrum Analyzer to display frequency input from spectral estimates of sinusoids embedded in white Gaussian noise.

Initialization

Create two dsp.SpectrumEstimator objects. Set one object to use the Welch-based spectral estimation technique with a Hann window, set the other object to use the filter bank estimation. Specify a noisy sine wave input signal with four sinusoids at 0.16, 0.2, 0.205, and 0.25 cycles per sample. View the spectral estimate using the spectrumAnalyzer object.

FrameSize = 420;
Fs = 1;
Frequency = [0.16 0.2 0.205 0.25];
sinegen = dsp.SineWave(SampleRate=Fs,SamplesPerFrame=FrameSize,...
Frequency=Frequency,Amplitude=[2e-5 1  0.05  0.5]);
NoiseVar = 1e-10;
numAvgs = 8;

hannEstimator = dsp.SpectrumEstimator(PowerUnits="dBm",...
Window="Hann",FrequencyRange="onesided",...
SpectralAverages=numAvgs,SampleRate=Fs);

filterBankEstimator = dsp.SpectrumEstimator(PowerUnits="dBm",...
Method="Filter bank",FrequencyRange="onesided",...
SpectralAverages=numAvgs,SampleRate=Fs);

spectrumPlotter = spectrumAnalyzer(InputDomain="frequency",...
SampleRate=Fs,SpectrumUnits="dBm",...
YLimits=[-120,40],PlotAsTwoSidedSpectrum=false,...
ChannelNames={'Hann window','Filter bank'},ShowLegend=true);

Streaming

Stream the input. Compare the spectral estimates in the spectrum analyzer.

for i = 1:1000
x = sum(sinegen(),2) + sqrt(NoiseVar)*randn(FrameSize,1);
Pse_hann = hannEstimator(x);
Pfb = filterBankEstimator(x);
spectrumPlotter([Pse_hann,Pfb])
end

Compute and display the power spectrum of a noisy sinusoidal input signal using the spectrumAnalyzer MATLAB® object. Measure the peaks, cursor placements, adjacent channel power ratio, and distortion values in the spectrum by enabling these properties:

• PeakFinder

• CursorMeasurements

• ChannelMeasurements

• DistortionMeasurements

Initialization

The input sine wave has two frequencies: 1000 Hz and 5000 Hz. Create two dsp.SineWave System objects to generate these two frequencies. Create a spectrumAnalyzer object to compute and display the power spectrum.

Fs = 44100;
Sineobject1 = dsp.SineWave(SamplesPerFrame=1024,PhaseOffset=10,...
SampleRate=Fs,Frequency=1000);
Sineobject2 = dsp.SineWave(SamplesPerFrame=1024,...
SampleRate=Fs,Frequency=5000);
SA = spectrumAnalyzer(SampleRate=Fs,SpectrumType="power",...
PlotAsTwoSidedSpectrum=false,ChannelNames={'Power spectrum of the input'},...
YLimits=[-120 40],ShowLegend=true);

Enable Measurements Data

To obtain the measurements, set the Enabled property to true.

SA.CursorMeasurements.Enabled = true;
SA.ChannelMeasurements.Enabled = true;
SA.PeakFinder.Enabled = true;
SA.DistortionMeasurements.Enabled = true;

Use getMeasurementsData

Stream in the noisy sine wave input signal and estimate the power spectrum of the signal using the spectrum analyzer. Measure the characteristics of the spectrum. Use the getMeasurementsData function to obtain these measurements programmatically. The isNewDataReady function returns true when there is new spectrum data. Store the measured data in the variable data.

data = [];
for Iter = 1:1000
Sinewave1 = Sineobject1();
Sinewave2 = Sineobject2();
Input = Sinewave1 + Sinewave2;
NoisyInput = Input + 0.001*randn(1024,1);
SA(NoisyInput);
data = [data;getMeasurementsData(SA)];
end
end

The bottom of the spectrum analyzer shows the measurement panes you enabled. The values in these panes match the values in the last time step of the data variable. You can access the individual fields of data to obtain the various measurements programmatically.

Compare Peak Values

Use the PeakFinder property to obtain peak values. Verify that the peak values in the last time step of data match the values shown on the spectrum analyzer plot.

peakvalues = data.PeakFinder(end).Value
peakvalues = 3×1

-59.4124
-59.8725
-60.0010

frequencieskHz = data.PeakFinder(end).Frequency/1000
frequencieskHz = 3×1

0.2799
0.5383
0.6029

expand all

## Tips

• To close the scope window and clear its associated data, use the MATLAB clear function.

• To hide or show the scope window, use the hide and show functions.

• Use the MATLAB mcc function to compile code containing a Spectrum Analyzer.

expand all

## Version History

Introduced in R2022a

expand all