Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

dsp.TimeScope System object

Time domain signal display and measurement

Description

The dsp.TimeScope System object™ displays time-domain signals. You can use the scope to measure signal values, find peaks, display bilevel measurements and statistics.

To see time-domain signals in the scope:

  1. Create the dsp.TimeScope object and set its properties.

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

To learn more about how System objects work, see What Are System Objects? (MATLAB).

Oscilloscope features:

  • Triggers — Set triggers to sync repeating signals and pause the display when events occur.

  • Cursor Measurements — Measure signal values using vertical and horizontal cursors.

  • Signal Statistics — Display the maximum, minimum, peak-to-peak difference, mean, median, and RMS values of a selected signal.

  • Peak Finder — Find maxima, showing the x-axis values at which they occur.

  • Bilevel Measurements — Measure transitions, overshoots, undershoots, and cycles.

For information on measurements and triggers, see Configure Time Scope.

Scope display features:

  • Multiple signals — Plot multiple signals on the same y-axis (display) using multiple input ports.

  • Multiple y-axes (displays) — Display multiple y-axes. All the y-axes have a common time range on the x-axis.

  • Modify parameters — Modify scope parameter values before and during a simulation.

  • Axis autoscaling — Autoscaling during or at the end of a simulation. Margins are drawn at the top and bottom of the axes.

Creation

Syntax

scope = dsp.TimeScope
scope = dsp.TimeScope(numInputs,sampleRate)
scope = dsp.TimeScope(___,Name,Value)

Description

scope = dsp.TimeScope returns a Time Scope System object, scope. This object displays real- and complex-valued floating and fixed-point signals in the time domain.

scope = dsp.TimeScope(numInputs,sampleRate) creates a Time Scope and sets the NumInputPorts property to numInputs and the SampleRate property to sampleRate.

example

scope = dsp.TimeScope(___,Name,Value) sets properties specified as Name,Value pairs.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects (MATLAB).

Frequently Used

Number of input ports, specified as a positive integer. Each signal coming through an input port becomes a separate channel in the scope. You must invoke the scope with the same number of inputs as the value of this property.

Specify the sample rate, in hertz, of the input signals.

You can specify a scalar or a numeric vector with length equal to the value of NumInputPorts. The inverse of the sample rate determines the spacing between points on the time axis in the displayed signal. When you set SampleRate to a scalar value and NumInputPorts is greater than 1, the object uses the same sample rate for all inputs.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the time span, in seconds, as a positive, numeric scalar value. The time-axis limits are calculated as follows.

  • Minimum time-axis limit = min(TimeDisplayOffset)

  • Maximum time-axis limit = max(TimeDisplayOffset) + TimeSpan

Tunable: Yes

Dependencies

To use this property, set FrameBasedProcessing to false, or set FrameBasedProcessing to true and TimeSpanSource to 'Property'.

UI Use

Open the Configuration Properties. On the Main tab, set Time Span.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify how the scope displays new data beyond the visible time span.

  • Wrap — In this mode, the scope displays new data until the data reaches the maximum time-axis limit. When the data reaches the maximum time-axis limit of the scope window, the scope clears the display. The scope then updates the time offset value and begins displaying subsequent data points starting from the minimum time-axis limit.

  • Scroll — In this mode, the scope scrolls old data to the left to make room for new data on the right side of the scope display. This mode is graphically intensive and can affect run-time performance. However, it is beneficial for debugging and monitoring time-varying signals.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Main tab, set Time Span overrun action.

Specify the source of the time span for frame-based input signals as:

  • 'Property' – The object derives the x-axis limits from the TimeDisplayOffset and TimeSpan properties.

  • 'Auto' – The time-axis limits are derived from the TimeDisplayOffset and SampleRate properties and the FrameSize (number of rows in each input signal). The limits are calculated as:

    • Minimum time-axis limit = min(TimeDisplayOffset)

    • Maximum time-axis limit = max(TimeDisplayOffset) + max(1/SampleRate.*FrameSize)

Tunable: Yes

Dependencies

To use this property, set FrameBasedProcessing to true.

UI Use

Open the Configuration Properties. On the Main tab, set Time Span.

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 and only once after 10 updates.

UI Use

Select Tools > Axes Scaling.

Advanced

Specify the name of the scope as a character vector or string. This name appears as the title of the scope's figure window. To specify a title of a scope plot, use the Title property.

Tunable: Yes

Data Types: char | string

Scope window position in pixels, specified by the size and location of the scope window as a 4-element 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 to this property.

By default, the window appears in the center of your screen with a width of 410 pixels and height of 300 pixels. The exact position value depends on your screen resolution.

Tunable: Yes

  • true — The scope logs data for later use and updates the window periodically.

  • false — The scope updates every time the scope is called.

The simulation speed is faster when this property is set to true.

Tunable: Yes

UI Use

Select Simulation > Reduce Updates to Improve Performance.

Specify the layout grid dimensions as a 2-element vector: [numberOfRows,numberOfColumns]. You can use up to 16 rows and 16 columns.

Example: scope.LayoutDimensions = [2,4]

Tunable: Yes

UI Use

Select View > Layout.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Specify the type of plot to use.

  • Line — Line graph, similar to the line or plot function.

  • Stairs — Stair-step graph, similar to the stairs function. Stair-step graphs are useful for drawing time history graphs of digitally sampled data.

Tunable: Yes

UI Use

Open the Style properties. Set Plot type.

Specify the size of the buffer that the scope holds in its memory cache. Memory is limited by available memory on your system. If your signal has M rows of data and N data points in each row, M x N is the number of data points per time step. Multiply this result by the number of time steps for your model to obtain the required buffer length. For example, if you have 10 rows of data with each row having 100 data points and your run will be 10 time steps, you should enter 10,000 (10 x 100 x 10) as the buffer length.

UI Use

Open the Data History Properties. Set Buffer length.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

  • true — Enable frame-based processing.

  • false — Enable sample-based processing.

UI Use

Open the Configuration Properties. On the Main tab, set Input processing.

Specify the units used to describe the time axis. You can select one of the following options:

  • Metric — In this mode, the scope converts the times on the time axis to the most appropriate measurement units. These units include milliseconds, microseconds, nanoseconds, minutes, days, etc. The scope chooses the appropriate measurement units based on the minimum time-axis limit and the maximum time-axis limit of the scope window.

  • Seconds — In this mode, the scope always displays the units on the time axis as seconds.

  • None — In this mode, the scope does not display any units on the time axis. The scope only shows the word Time on the time axis.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Main tab, set Time units.

Specify, in seconds, how far to move the data on x-axis. The signal value does not change, only the displayed x-axis.

If you specify this property as a scalar, then that value is the time display offset for all channels.

If you specify a vector, each vector element is the time offset for the corresponding channel. For vectors with length less than the number of input channels, the time display offsets for the remaining channels are set to 0. If a vector has a length greater than the number of input channels, the extra vector elements are ignored.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Main tab, set Time display offset.

Specify how time-axis labels should appear in the scope displays as:

  • 'All' — Time-axis labels appear in all displays.

  • 'Bottom' — Time-axis labels appear in the bottom display of each column.

  • 'None' — No labels appear in any display.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Main tab, set Time-axis labels.

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 the Title and YLabel 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 the Title and YLabel properties are hidden.

  • 'Off' — None of the axes appear maximized.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Main tab, set Maximize axes.

Display

Specify the active display, by integer display number, to get and set relevant properties. The number of a display corresponds to its column-wise placement index. Set this property to control which display has its axes colors, line properties, marker properties, and visibility changed.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Display tab, set Active Display.

Specify the display title as a character vector or string. Enter %<SignalLabel> to use the signal labels as the axes titles.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Display tab, set Title.

To show a legend with the input names, set this property to true.

From the legend, you can control which signals are visible. This control is equivalent to changing the visibility in the Style dialog 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, press Esc.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Display tab, select Show legend.

When you set this property to true, the scope displays the time-axis label. When you set this property to false, the scope does not display the time-axis label, but still displays tick marks and other time-axis items. This property applies only if the TimeAxisLabels property is All or Bottom.

Tunable: Yes

Dependency

To control which display's axis is labeled, use the ActiveDisplay property.

UI Use

Open the Configuration Properties. On the Main tab, set Show time-axis label.

Specify the input channel names as a cell array of character vectors or 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.

UI Use

Show the legend and double-click the channel name.

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

Tunable: Yes

UI Use

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

When you set this property to true, the scope plots the magnitude and phase of the input signal on two separate axes within the same active display. When you set this property to 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.

Tunable: Yes

UI Use

Open the Configuration Properties. On the Display tab, select Plot signals as magnitude and phase.

Specify the y-axis limits as a two-element numeric vector, [ymin, ymax].

If PlotAsMagnitudePhase is false, the default is [-10,10]. If PlotAsMagnitudePhase is false, the default is [0,10].

Tunable: Yes

Dependencies

When PlotAsMagnitudePhase is true, this property specifies the y-axis limits of only the magnitude plot. The y-axis limits of the phase plot are always [-180,180].

UI Use

Open the Configuration Properties. On the Display tab, set Y-limits (Minimum) and Y-limits (Maximum).

Specify the text for the scope to display to the left of the y-axis.

Tunable: Yes

Dependencies

This property applies only when PlotAsMagnitudePhase is false. When PlotAsMagnitudePhase is true, the two y-axis labels are read-only values. The y-axis labels are set to 'Magnitude' and 'Phase' for the magnitude plot and the phase plot, respectively.

UI Use

Open the Configuration Properties. On the Display tab, set Y-Label.

Data Types: char | string

Usage

For versions earlier than R2016b, use the step function to run the System object™ algorithm. The arguments to step are the object you created, followed by the arguments shown in this section.

For example, y = step(obj,x) and y = obj(x) perform equivalent operations.

Syntax

scope(signal)
scope(signal,signal2,...,signalN)

Description

scope(signal) displays the signal, signal, in the time scope display.

scope(signal,signal2,...,signalN) displays the signals signal, signal2,...,signalN in the time scope display when you set the NumInputPorts property to N. In this case, signal1, signal2,...,signalN can have different data types and dimensions.

Input Arguments

expand all

Specify one or more input signals to visualize in the dsp.TimeScope. Signals can have different data types and dimensions.

Example: scope(signal1,signal2)

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | table | cell | categorical | datetime | fi

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)
showDisplay scope window
hideHide scope window
stepRun System object algorithm
cloneCreate duplicate System object
getNumInputsNumber of inputs required to call the System object
getNumOutputsNumber of outputs from calling the System object
isLockedDetermine if System object is locked
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

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

Examples

expand all

Create dsp.SineWave and dsp.TimeScope objects. Run the scope to display the signal

sine = dsp.SineWave('Frequency',100,'SampleRate',1000);
sine.SamplesPerFrame = 10;
scope = dsp.TimeScope('SampleRate',sine.SampleRate,'TimeSpan',0.1);
for ii = 1:10
     x = sine();
     scope(x);
end

Run the release method to allow changes to property values and input characteristics. The scope automatically scales the axes.

release(scope)

Create a dsp.SineWave with a 1000 Hz sampling frequency. Create a dsp.FIRDecimator object to decimate the sine wave by 2. Create a dsp.TimeScope object with two input ports.

Fs = 1000;  % Sampling frequency
sine = dsp.SineWave('Frequency',50,...
   'SampleRate',Fs, ...
   'SamplesPerFrame',100);
decimate = dsp.FIRDecimator; % To decimate sine by 2
scope = dsp.TimeScope(2,[Fs Fs/2], ...
   'TimeDisplayOffset',[0 38/Fs], ...
   'TimeSpan',0.25, ...
   'YLimits',[-1 1], ...
   'ShowLegend', true);

Call the dsp.SineWave object to create a sine wave signal. Use the dsp.FIRDecimator object to create a second signal that equals the original signal, but decimated by a factor of 2. Display the signals by calling the dsp.TimeScope object.

for ii = 1:2
     xsine = sine();
     xdec = decimate(xsine);
     scope(xsine,xdec)
end
release(scope)

Close the Time Scope window and clear the variables.

clear scope Fs sine decimate ii xsine xdec

Create a vector representing a complex-valued sinusoidal signal, and create a dsp.TimeScope object. Call the scope to display the signal.

fs = 1000;
t = (0:1/fs:10)';
CxSine = cos(2*pi*0.2*t) + 1i*sin(2*pi*0.2*t);
CxSineSum = cumsum(CxSine);
scope = dsp.TimeScope(1,fs,'TimeSpanSource','Auto','ShowLegend',1);
scope(CxSineSum);
scope.AxesScaling = 'Auto';

By default, when the input is a complex-valued signal, Time Scope plots the real and imaginary portions on the same axes. These real and imaginary portions appear as different-colored lines on the same axes within the same active display.

Change the PlotAsMagnitudePhase property to true and call release.

scope.PlotAsMagnitudePhase = true;
release(scope)

Time Scope now plots the magnitude and phase of the input signal on two separate axes within the same active display. The top axes display magnitude and the bottom axes display the phase, in degrees.

Use a Time Scope to display a variable-size signal.

Create a vector that represents a two-channel constant signal. Create another vector that represents a three-channel constant signal. Construct a dsp.TimeScope object with two input ports. Call the scope to display the signal.

fs = 10;
sigdim2 = [ones(5*fs,1) 1+ones(5*fs,1)];                   % 2-dim 0-5 s
sigdim3 = [2+ones(5*fs,1) 3+ones(5*fs,1) 4+ones(5*fs,1)];  % 3-dim 5-10 s
scope = dsp.TimeScope(2,fs,'TimeSpanSource','Property');
scope.PlotType = 'Stairs';
scope.TimeSpanOverrunAction = 'Scroll';
scope.TimeDisplayOffset = [0 0 5];
scope([sigdim2; sigdim3(:,1:2)], sigdim3(:,3));

In this example, the size of the input signal to the Time Scope block changes as the simulation progresses. When the simulation time is less than 5 seconds, Time Scope plots only the two-channel signal, sigdim2. After 5 seconds, Time Scope also plots the three-channel signal, sigdim3.

Run the release method to enable changes to property values and input characteristics. The scope automatically scales the axes.

release(scope)

Close the Time Scope window and remove the variables you created from the workspace.

clear scope fs sigdim2 sigdim3

Create and Display Clock Input Signal

Load the clock data, x and t. Find the sample time, ts.

load clockex
ts = t(2)-t(1);

Create a dsp.TimeScope object and call the object to display the signal. To autoscale the axes and enable changes to property values and input characteristics, call release.

scope = dsp.TimeScope(1,1/ts,'TimeSpanSource','Auto');
scope(x);
release(scope)

Use Bilevel Measurements Panel to Find Settling Time

1. From the Time Scope menu, select Tools > Measurements > Bilevel Measurements.

2. Expand the Settings pane and the Overshoots / Undershoots pane.

Initially, the Time Scope does not display the rising edge Settling Time parameter. This absence occurs because the default value of the Settle Seek parameter is longer than the entire simulation duration.

3. In the Settle Seek box, enter 2e-6 and press Enter.

Time Scope now displays a rising edge Settling Time value of 118.392 ns.

This settling time value is actually the statistical average of the settling times for all five rising edges. To show the settling time for only one rising edge, you can zoom in on that transition.

4. In the Time Scope toolbar, click the arrow next to the Zoom button, and then click the Zoom X button.

5. Click the display near a value of 2 microseconds on the time axis.

6. Drag your cursor right and release it near a value of 4 microseconds on the time axis.

Time Scope updates the rising edge Settling Time value to reflect the new time window.

7. Close the Time Scope and remove the variables you created from the workspace.

clear scope x t ts

Use Peak Finder panel of the Time Scope to measure a heart rate.

Create and Display ECG Signal

Create the electrocardiogram (ECG) signal. The custom ecg fuction helps generate the heartbeat signal.

function x = ecg(L)
a0 = [0,  1, 40,  1,   0, -34, 118, -99,   0,   2,  21,   2,   0,   0,   0];
d0 = [0, 27, 59, 91, 131, 141, 163, 185, 195, 275, 307, 339, 357, 390, 440];
a = a0 / max(a0);
d = round(d0 * L / d0(15));
d(15) = L;
for i = 1:14
    m = d(i) : d(i+1) - 1;
    slope = (a(i+1) - a(i)) / (d(i+1) - d(i));
    x(m+1) = a(i) + slope * (m - d(i));
end

x1 = 3.5*ecg(2700).';
y1 = sgolayfilt(kron(ones(1,13),x1),0,21);
n = (1:30000)';
del = round(2700*rand(1));
mhb = y1(n + del);
ts = 0.00025;

Create a dsp.TimeScope object and call the object to display the signal. To autoscale the axes and enable changes to property values and input characteristics, call release.

scope = dsp.TimeScope(1,1/ts,'TimeSpanSource','Auto');
scope(mhb);
release(scope)

Find Heart Rate

Use the Peak Finder measurements to measure the time between heart beats.

  1. In the Time Scope menu, select Tools > Measurements > Peak Finder.

  2. Expand the Settings pane.

  3. In the Max Num of Peaks property, enter 10 and press Enter.

In the Peaks pane, Time Scope displays a list of ten peak amplitude values and the times at which they occur.

The list of peak values shows a constant time difference of 0.675 second between each heartbeat. Based on the following equation, the heart rate of this ECG signal is about 89 beats per minute.

Close the Time Scope window and remove the variables you created from the workspace.

clear scope x1 y1 n del mhb ts

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 scope.

    You cannot open scope configuration dialogs if you have more than one compiled component in your application.

Extended Capabilities

Introduced in R2011a

Was this topic helpful?