In the Test Sequence block, you can generate signals for testing.
Define an output data symbol in the Data Symbols pane.
Use the output name with a signal generation function in the test step action.
You can call external functions from the Test Sequence block. Define a function in a script on the MATLAB® path, and call the function in the test sequence.
This example shows how to produce a sine and a random number test signal in a Test Sequence block.
The step Sine
outputs a sine wave with a period of 10 seconds, specified by the argument et*2*pi/10
. The step Random
outputs a random number in the interval -0.5 to 0.5
.
The test sequence produces signal sg
.
This example shows how to call an externally-defined function from the Test Sequence block. Define a function in a script on the MATLAB® path, and call the function from the test sequence.
In this example, the step ReducedSine
reduces the signal sg
using the function Attenuate
.
The test sequence produces signal sg
and attenuated signal asg
.
Some signal generation functions use the temporal operator et
, which is the
elapsed time of the test step in seconds. Scaling, rounding, and other approximations of
argument values can affect function outputs. Common
signal generation functions include:
Function | Syntax | Description | Example |
---|---|---|---|
square | square(x) | Represents a square wave output with a period of Within
the interval | Output a square wave with a period of square(et/10) |
sawtooth | sawtooth(x) | Represents a sawtooth wave output with a period of Within
the interval | Output a sawtooth wave with a period of sawtooth(et/10) |
triangle | triangle(x) | Represents a triangle wave output with a period of Within
the interval | Output a triangle wave with a period of triangle(et/10) |
ramp | ramp(x) | Represents a ramp signal of slope
| Ramp one unit for every 5 seconds of test step elapsed time: ramp(et/5) |
heaviside | heaviside(x) | Represents a heaviside step signal, returning | Output a heaviside signal after heaviside(et-5) |
latch | latch(x) | Saves the value of | Latch b = latch(torque) |
sin | sin(x) | Returns the sine of | A sine wave with a period of 10 sec: sin(et*2*pi/10) |
cos | cos(x) | Returns the cosine of | A cosine wave with a period of 10 sec: cos(et*2*pi/10) |
rand | rand | Uniformly distributed pseudorandom values | Generate new random values for each simulation by declaring coder.extrinsic('rand')
nr = rand
sg = a + (b-a)*nr |
randn | randn | Normally distributed pseudorandom values |
Generate new random values for each simulation by declaring
coder.extrinsic('randn')
nr = randn
sg = nr*2 |
exp | exp(x) | Returns the natural exponential function, . | An exponential signal progressing at one tenth of the test step elapsed time: exp(et/10) |
Test Sequence | Test Sequence and Assessment Syntax