dsp.ArrayPlot
Display vectors or arrays
Description
Display vectors or arrays where the data is uniformly spaced along thex-axis.
Creation
Description
scope = dsp.ArrayPlot
creates an Array Plot object,scope
.
scope = dsp.ArrayPlot(Name=Value)
sets properties using one or more name-value pairs. For example,scope = dsp.ArrayPlot(NumInputPorts=3)
Properties
Most properties can be changed from thedsp.ArrayPlot
UI.
Plot Configuration
NumInputPorts
—Number of input ports
1
(default) |integer between [1, 96]
Number of input ports, specified as a positive integer. Each signal coming through a separate input becomes a separate channel in the scope. You must invoke the scope with the same number of inputs as the value of this property.
XDataMode
—Source of thex-data spacing
"Sample increment and X-offset"
(default) |"Custom"
Specify whether to use theSampleIncrement
andXOffset
property values to determine spacing, or specify your own custom spacing. If you specify"Custom"
, you also must specify theCustomXData
property values.
You can set this property only when creating the object.
Scope Window Use
Open thePlottab, clickSettings, and setX-Data Mode.
Data Types:char
|string
CustomXData
—X-data values
empty vector(default) |vector
Specify the desiredx-data values as a row or column vector of length equal to the frame length of the individual inputs. If you use the default (empty vector) value, thex-data is uniformly spaced and set to (0:L–1), whereLis the frame length.
You can set this property only when creating the object.
Example:scope = dsp.ArrayPlot(XDataMode="Custom",CustomXData=logspace(0,log10(44100/2),1024))
Scope Window Use
Open thePlottab, clickSettings, and setX-Data ModetoCustomand specifyCustom X-Data.
Dependency
To use this property, setXDataMode
to"Custom"
.
SampleIncrement
—Sample increment of input
1
(default) |finite numeric scalar
Specify the spacing between samples along thex-axis as a finite numeric scalar. The input signal is onlyy-axis data.x设在数据设置自动基于theXOffset
andSampleIncrement
properties.
Example:WhenXOffset
is0
andSampleIncrement
is1
, thex-axis values are set to0, 1, 2, 3, 4, …
.
Example:WhenXOffset
is-1
andSampleIncrement
is0.25
, thex-axis values are set to-1, -0.75, -0.5, -0.25, 0, …
.
Scope Window Use
Open thePlottab, clickSettings, and setSample Increment.
Dependency
To use this property, setXDataMode
to'Sample increment and X-offset'
.
XOffset
—Display offset of x-axis
0
(default) |scalar
Display offset ofx-axis, specified as a numeric scalar.x-axis data is set automatically based on both theSampleIncrement
andXOffset
值。x代表第一个值thex-axis.
Example:WhenXOffset
is 0 andSampleIncrement
is 1, thex-axis values are set to 0, 1, 2, 3, 4, … .
Example:WhenXOffset
is -1 andSampleIncrement
is 0.25, thex-axis values are set to -1, -0.75, -0.5, -0.25, 0, … .
Scope Window Use
Open thePlottab, clickSettings, and setX-Offset.
Dependency
To use this property, setXDataMode
to"Sample increment and X-offset"
.
XScale
—Scale of x-axis
"Linear"
(default) |"Log"
Specify whether the scale of thex-axis is"Linear"
or"Log"
. IfXOffset
is a negative value, you cannot set this property to"Log"
.
Scope Window Use
Open thePlottab, clickSettings, and setXScale.
Data Types:char
|string
YScale
—Scale ofy-axis
"Linear"
(default) |"Log"
Specify whether the scale of they-axis is"Linear"
or"Log"
.
Scope Window Use
Open thePlottab, clickSettings, and setYScale.
Data Types:char
|string
PlotType
—Control type of plot
"Stem"
(default) |"Line"
|"Stairs"
Specify the type of plot to use for all the input signals displayed in the scope window:
"Stem"
– The scope displays the input signal as circles with vertical lines extending down to thex-axis at each of the sampled values."Line"
– The scope displays the input signal as lines connecting each of the sampled values."Stairs"
——作为stair-s显示输入信号范围tep graph. A stair-step graph is made up of only horizontal lines and vertical lines. Each horizontal line represents the signal value for a discrete sample period and is connected to two vertical lines. Each vertical line represents a change in values occurring at a sample. Stair-step graphs are useful for drawing time history graphs of digitally sampled data.
Scope Window Use
Open theSettingsand setPlot Type.
AxesScaling
—Axes scaling mode
"OnceAtStop"
(default) |"Auto"
|"Manual"
|"Updates"
Specify when the scope scales the axes. Valid values are:
"Auto"
— The scope scales the axes as needed 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."Updates"
— The scope scales the axes once after a set number of visual updates. The number of updates is determined by the value of theAxesScalingNumUpdates
property.
You can set this property only when creating the object.
Scope Window Use
Hover over the array plot to see the zoom, pan, and autoscalebuttons. You can also zoom and pan using your mouse.
Data Types:char
|string
AxesScalingNumUpdates
—Number of updates before scaling
100(default) |real positive integer
Specify the number of updates before scaling as a real, positive scalar integer.
Dependency
To enable this property, setAxesScaling
to"Updates"
.
Data Types:double
Measurements
MeasurementChannel
—Channel for which to obtain measurements
1
(default) |positive integer
Channel for which to obtain measurements, specified as a positive integer in the range [1N], whereNis the number of input channels.
Scope Window Use
Click theMeasurementstab on the Array Plot toolstrip. In theChannelsection, select aChannel.
Data Types:double
CursorMeasurements
—Cursor measurements
CursorMeasurementsConfiguration
object
Cursor measurements to display screen or waveform cursors, specified as aCursorMeasurementsConfiguration
object.
AllCursorMeasurementsConfiguration
properties are tunable.
Scope Window Use
Click theMeasurementstab on the Array Plot toolstrip and modify the cursor measurements in theCursorssection.
PeakFinder
—Peak finder measurements
PeakFinderConfiguration
object
Peak finder measurements to compute and display the largest calculated peak values, specified as aPeakFinderConfiguration
object.
AllPeakFinderConfiguration
properties are tunable.
Scope Window Use
Click theMeasurementstab on the Array Plot toolstrip and modify the peak finder measurements in thePeakssection.
SignalStatistics
—Signal statistics measurements
SignalStatisticsConfiguration
object
Signal statistics measurements to compute and display signal statistics, specified as aSignalStatisticsConfiguration
object.
AllSignalStatisticsConfiguration
properties are tunable.
Scope Window Use
Click theMeasurementstab on the Array Plot toolstrip and modify the signal statistics measurements in theStatisticssection.
Visualization
Name
—Window name
'Array Plot'
(default) |character vector|string scalar
Specify the name of the scope. This name appears as the title of the scope's figure window. To specify a title of a scope plot, use theTitle
property.
Data Types:char
|string
Position
—Scope window position and size in pixels
screen center(default) |[left bottom width height]
Specify, in pixels, the size and location of the scope window as a four-element vector of the form[left bottom width height]
. By default, the scope window appears in the center of your screen with a width of 800 pixels and height of 450 pixels. The default values for this property may change depending on your screen resolution.
MaximizeAxes
—Maximize axes control
"Auto"
(default) |"On"
|"Off"
Specify whether to display the scope in maximized-axes mode. In this mode, the axes are expanded to fit into the entire display. To conserve space, labels do not appear in each display. Instead, tick-mark values appear on top of the plotted data. You can select one of the following options:
"Auto"
— The axes appear maximized in all displays only if theTitle
andYLabel
properties are empty for every display. If you enter any value in any display for either of these properties, the axes are not maximized."On"
— The axes appear maximized in all displays. Any values entered into theTitle
andYLabel
properties are hidden."Off"
— None of the axes appear maximized.
Scope Window Use
Hover over the array plot to see the maximize axes button.
Data Types:char
|string
Title
—Display title
''
(default) |character vector|string scalar
Specify the display title as a character vector or string.
Scope Window Use
Open thePlottab, clickSettings, and setTitle.
Data Types:char
|string
ShowLegend
—Show legend
false
(default) |true
To show a legend with the input names, set this property totrue
.
From the legend, you can control which signals are visible. This control is equivalent to changing the visibility in theStyledialog box. 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, pressEsc.
Note
The legend only shows the first 20 signals. Any additional signals cannot be viewed or controlled from the legend.
Scope Window Use
On thePlottab, clickLegend.
Data Types:logical
ChannelNames
—Channel names
empty cell(default) |cell array of character vectors|array of strings
Specify the input channel names as a cell array of character vectors or an array of strings. The names appear in the legend,Settings, andMeasurementspanels. If you do not specify names, the channels are labeled asChannel 1
,Channel 2
, etc.
Dependency
To see channel names, setShowLegend
totrue
.
Data Types:char
ShowGrid
—Display grid
true
(default) |false
Set this property totrue
to show grid lines on the plot.
Scope Window Use
Open thePlottab, clickSettings, and selectGrid.
PlotAsMagnitudePhase
—Plot signal as magnitude and phase
false
(default) |true
true
– The scope plots the magnitude and phase of the input signal on two separate axes within the same active display.false
– The scope plots the real and imaginary parts of the input signal on two separate axes within the same active display.
This property is useful for complex-valued input signals. Turning on this property affects the phase for real-valued input signals. When the amplitude of the input signal is nonnegative, the phase is 0 degrees. When the amplitude of the input signal is negative, the phase is 180 degrees.
Scope Window Use
On thePlottab, select theMagnitude Phasebutton.
XLabel
—x-axis label
""
(default) |character vector|string scalar
Specify the text for the scope to display below thex-axis.
Scope Window Use
Open thePlottab, clickSettings, and setXLabel.
Data Types:char
|string
YLabel
—y-axis label
"Amplitude"
(default) |character vector|string scalar
Specify the text for the scope to display to the left of they-axis.
Dependencies
This property applies only whenPlotAsMagnitudePhase
isfalse
. WhenPlotAsMagnitudePhase
istrue
, the twoy-axis labels are read-only values"Magnitude"
and"Phase"
情节,情节和级阶段,respectively.
Scope Window Use
Open thePlottab, clickSettings, and setYLabel.
Data Types:char
|string
YLimits
—y-axis limits
[-10,10]
(default) |[ymin, ymax]
Specify they-axis limits as a two-element numeric vector,[ymin, ymax]
.
IfPlotAsMagnitudePhase
isfalse
, the default is[-10,10]
. IfPlotAsMagnitudePhase
istrue
, the default is[0,10]
.
Dependencies
WhenPlotAsMagnitudePhase
istrue
, this property specifies they-axis limits of only the magnitude plot. They-axis limits of the phase plot are always[-180,180]
.
Scope Window Use
Open thePlottab, clickSettings, and setY-Axis Limitsas a two-element numeric vector.
Usage
Description
Input Arguments
signal
—Input signal or signals to visualize
scalar|vector|matrix
Specify one or more input signals to visualize in thedsp.ArrayPlot
. Signals can have a different number of channels and different frame lengths.
Example:scope(signal1,signal2)
UI Customization
To customize the style of signals on the array plot, open theSettingsand use the bottom row of options to select a signal and modify the style, width, color, and marker type.
Data Types:single
|double
|int8
|int16
|int32
|int64
|uint8
|uint16
|uint32
|uint64
|fi
Object Functions
To use an object function, specify the object as the first input argument.
generateScript |
GenerateMATLABscript to create scope with current settings |
hide |
Hide scope window |
show |
Display scope window |
isVisible |
Determine visibility of scope |
step |
RunSystem objectalgorithm |
release |
Release resources and allow changes toSystem objectproperty values and input characteristics |
reset |
Reset internal states ofSystem object |
If you want to restart the simulation from the beginning, callreset
to clear the scope window displays. Do not callreset
after callingrelease
.
Examples
Plot a Gaussian Distribution
Create a new Array Plot object.
scope = dsp.ArrayPlot;
Configure the properties of the Array Plot object for a Gaussian distribution.
scope.YLimits = [0 1]; scope.XOffset = -2.5; scope.SampleIncrement = 0.1; scope.Title ="Gaussian distribution"; scope.XLabel ="X"; scope.YLabel ="f(X)";
Call the Array Plot object to plot a Gaussian distribution.
scope(exp(-(-2.5:.1:2.5).*(-2.5:.1:2.5))')
You can scale the y-axis to show the plot on a log scale.
release(scope) scope.YScale ='Log'; scope(exp(-(-2.5:.1:2.5).*(-2.5:.1:2.5))')
Plot Changing Filter Weights
View least mean squares (LMS) adaptive filter weights on the Array Plot figure. Watch the filter weights change as they adapt to filter a noisy input signal.
Create an LMS adaptive filter System object™.
lmsFilter = dsp.LMSFilter(40,Method="Normalized LMS",...StepSize=0.002);
Create and configure adsp.AudioFileReader
System object to read the input signal from the specified audio file.
signalSource = dsp.AudioFileReader("dspafxf_8000.wav",...SamplesPerFrame=40,...PlayCount=Inf,...OutputDataType="double");
Create and configure adsp.FIRFilter
System object to filter random white noise, creating colored noise.
firFilter = dsp.FIRFilter(Numerator=fir1(39,0.25));
Create and configure adsp.ArrayPlot
object to display the adaptive filter weights.
scope = dsp.ArrayPlot(XLabel="Filter Tap",...YLabel="Filter Weight",...YLimits=[-0.05 0.2]');
Plot the LMS filter weights as they adapt to a desired signal. Read from the audio file, produce random data, and filter the random data. Update the filter weights and plot the filter weights.
numplays = 0;whilenumplays < 3 [y, eof] = signalSource(); noise = rand(40,1); noisefilt = firFilter(noise); desired = y + noisefilt; [~, ~, wts] = lmsFilter(noise,desired); scope(wts); numplays = numplays + eof;end
Power Spectrum of Multichannel Sinusoidal Signal
Compute the power spectrum of a multichannel sinusoidal signal using thedsp.SpectrumEstimator
System object™. You can get the vector of frequencies at which the spectrum is estimated using thegetFrequencyVector
function. To compute the resolution bandwidth of the estimate (RBW), use thegetRBW
function.
Generate a three-channel sinusoid sampled at 1 kHz. Specify sinusoidal frequencies of 100, 200, and 300 Hz. The second and third channels have their phases offset from the first byand, respectively.
sineSignal = dsp.SineWave('SamplesPerFrame',1000,'SampleRate',1000,...'Frequency',[100 200 300],'PhaseOffset',[0 pi/2 pi/4]);
Estimate and plot the one-sided spectrum of the signal. Use thedsp.SpectrumEstimator
object for the computation and thedsp.ArrayPlot
for the plotting.
estimator = dsp.SpectrumEstimator('FrequencyRange','onesided'); plotter = dsp.ArrayPlot('PlotType','Line','YLimits',[0 0.75],...'YLabel','Power Spectrum (watts)','XLabel','Frequency (Hz)');
Step through to obtain the data streams and display the spectra of the three channels.
y = sineSignal(); pxx = estimator(y); plotter(pxx)
Get the vector of frequencies at which the spectrum is estimated in Hz, using thegetFrequencyVector
function.
f = getFrequencyVector(estimator);
Compute the resolution bandwidth (RBW) of the estimate using thegetRBW
function.
rbw = getRBW(estimator)
rbw = 0.0015
The resolution bandwidth of the signal power spectrum is 0.0015 Hz. This frequency is the smallest frequency that can be resolved on the spectrum.
Power and Max-Hold Spectra of Noisy Sine Wave
Note: If you are using R2016a or an earlier release, replace each call to the object with the equivalentstep
syntax. For example,obj(x)
becomesstep(obj,x)
.
Generate a sine wave.
sineWave = dsp.SineWave('Frequency',100,...'SampleRate',1000,...'SamplesPerFrame',1000);
Use the spectrum estimator to compute the power spectrum and the max-hold spectrum of the sine wave. Use the Array Plot to display the spectra.
SE = dsp.SpectrumEstimator(...'SampleRate',sineWave.SampleRate,...'SpectrumType','Power','PowerUnits','dBm',...'FrequencyRange','centered',...'OutputMaxHoldSpectrum',true); plotter = dsp.ArrayPlot('PlotType','Line',...'XOffset',-500,...'YLimits',[-60 30],...'Title','Power Spectrum of 100 Hz Sine Wave',...'YLabel','Power Spectrum (dBm)',...'XLabel','Frequency (Hz)');
Add random noise to the sine wave. Stream in the data, and plot the power spectrum of the signal.
forii = 1:10 x = sineWave() + 0.05*randn(1000,1); [Pxx,Pmax] = SE(x); plotter([Pxx Pmax])end
Tips
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
Supports MEX code generation by treating the calls to the object as extrinsic. Does not support code generation for standalone applications.
SeeSystem Objects in MATLAB Code Generation(MATLAB Coder).
Version History
Introduced in R2013aR2022b:Channel names support array of strings
Starting in R2022b, you can specify theChannelNames
property of thedsp.ArrayPlot
object as an array of strings.
ap = dsp.ArrayPlot(ChannelNames=["Input","Noisy Output"]);
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina(Español)
- Canada(English)
- United States(English)
Europe
- Belgium(English)
- Denmark(English)
- Deutschland(Deutsch)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- 挪威(English)
- Österreich(Deutsch)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)