Waveform Generator
Output waveforms using signal notations
Libraries:
Simulink /
Sources
Description
The Waveform Generator block outputs waveforms based on signal notations that you enter in the Waveform Definition table.
This block supports these syntaxes for the signal notations:
Function syntax — Specify all arguments in the specific order for the signal syntax (see Algorithms).
Name-value syntax — Specify optional comma-separated pairs of
Name,Value
arguments.Name
is the argument name andValue
is the corresponding value.Name
must appear inside single quotes (' '
). You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN
. For more information, see Algorithms.
This block supports normal, accelerator, and rapid accelerator modes and fast restart.
Supported Operators
Operation | Operator |
---|---|
Absolute value |
abs()
|
Addition |
+
|
Division |
/
|
Multiplication |
*
|
Parentheses |
()
|
Subtraction |
-
|
Unary minus |
-
|
The Waveform block observes the following rules of operator precedence:
( )
+ -
(unary)* /
+ -
Supported Operations
The Waveform Generator block outputs one signal at a time. You can change this output signal. Express frequency and phase offset parameters in radians. You can also:
Nest signal notations, for example:
sin('Amplitude',sin('Amplitude',1,'Frequency',1,'Phase',0),'Frequency',1,'Phase',1)
Reference real scalar variables in the base or model workspace, for example:
sin('Amplitude',x,'Frequency',y,'Phase',z)
x, y, and z exist in the base workspace.
For more information on waveforms, see Algorithms.
To quickly determine the response of a system to different types of inputs, you can vary the output signal of the Waveform Generator block while a simulation is in progress.
Examples
Create Interchangeable Variations of Model Components
Create variants of a model component.
Switch Between Output Waveforms During Code Execution for Waveform Generator Block
Generate code that enables you to switch between stimulus waveforms during code execution.
(Embedded Coder)
Limitations
You cannot tune the parameters of a waveform, such as frequency or amplitude, during execution of the code that you generate by using Simulink® Coder™. Instead, you can generate code that enables you to switch between waveform variants that you specify. For more information, see Switch Between Output Waveforms During Code Execution for Waveform Generator Block (Simulink Coder).
Ports
Output
Port_1 — Generated output signal
scalar | vector
Output signal specified by an entry in the Waveform Definition table.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| bus
Parameters
Main
Output Signal — Waveform for output signal
1 (default) | integer
Select waveform definition to specify the output signal. The number corresponds to the line item in the Waveform Definition table. You can change this parameter while a simulation is running.
Programmatic Use
Block Parameter:
SelectedSignal |
Type: character vector |
Values: scalar |
Default:
'1' |
Waveform Definition — Waveform signal notations
constant | gaussian(mean,variance,seed)
| pulse(amplitude,trigger_time,duration)
| sawtooth(amplitude,frequence,phase_offset)
| sin(amplitude,frequence,phase_offset)
| square(amplitude,frequence,phase_offset)
| step(step_time,initial_value,final_value)
Enter signal notations in the Waveform Definition table, one waveform definition per line. For syntax details, see Algorithms.
Signal Attributes
The Data Type Assistant helps you set data attributes. To use the Data Type Assistant, click . For more information, see Specify Data Types Using Data Type Assistant.
Output minimum — Minimum output value for range checking
[]
(default) | scalar
Lower value of the output range that the software checks.
The software uses the minimum to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Tips
Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | OutMin |
Values: | '[]' (default) | scalar in quotes |
Output maximum — Maximum output value for range checking
[]
(default) | scalar
Upper value of the output range that the software checks.
The software uses the maximum value to perform:
Parameter range checking (see Specify Minimum and Maximum Values for Block Parameters) for some blocks.
Simulation range checking (see Specify Signal Ranges and Enable Simulation Range Checking).
Automatic scaling of fixed-point data types.
Optimization of the code that you generate from the model. This optimization can remove algorithmic code and affect the results of some simulation modes such as SIL or external mode. For more information, see Optimize using the specified minimum and maximum values (Embedded Coder).
Tips
Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | OutMax |
Values: | '[]' (default) | scalar in quotes |
Output data type — Specify the output data type
double
(default) | Inherit: Inherit via back
propagation
| single
| int8
| int32
| uint32
| int64
| uint64
| fixdt(1,16,2^0,0)
| <data type expression>
| ...
Choose the data type for the output. The type can be inherited,
specified directly, or expressed as a data type object such as
Simulink.NumericType
.
Programmatic Use
Block Parameter:
OutDataTypeStr |
Type: character vector |
Values: 'Inherit:
Inherit via back propagation' |
'double' | 'single' |
'int8' | 'uint8' |
int16 | 'uint16' |
'int32' | 'uint32' |
'int64' | 'uint64' |
fixdt(1,16,0) |
fixdt(1,16,2^0,0) |
fixdt(1,16,2^0,0) | '<data
type expression>' |
Default:
'double' |
Lock output data type setting against changes by the fixed-point tools — Prevent fixed-point tools from overriding data types
off
(default) | on
Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).
Programmatic Use
Block Parameter:
LockScale |
Type: character vector |
Values:
'off' |
'on' |
Default:
'off' |
Integer rounding mode — Specify the rounding mode for fixed-point operations
Floor
(default) | Ceiling
| Convergent
| Nearest
| Round
| Simplest
| Zero
Choose one of these rounding modes.
Ceiling
Rounds both positive and negative numbers toward positive infinity. Equivalent to the MATLAB®
ceil
function.Convergent
Rounds number to the nearest representable value. If a tie occurs, rounds to the nearest even integer. Equivalent to the Fixed-Point Designer™
convergent
function.Floor
Rounds both positive and negative numbers toward negative infinity. Equivalent to the MATLAB
floor
function.Nearest
Rounds number to the nearest representable value. If a tie occurs, rounds toward positive infinity. Equivalent to the Fixed-Point Designer
nearest
function.Round
Rounds number to the nearest representable value. If a tie occurs, rounds positive numbers toward positive infinity and rounds negative numbers toward negative infinity. Equivalent to the Fixed-Point Designer
round
function.Simplest
Automatically chooses between round toward floor and round toward zero to generate rounding code that is as efficient as possible.
Zero
Rounds number toward zero. Equivalent to the MATLAB
fix
function.
Programmatic Use
Block Parameter:
RndMeth |
Type: character vector |
Values:
'Ceiling' |
'Convergent' |
'Floor' |
'Nearest' |
'Round' |
'Simplest' |
'Zero' |
Default:
'Floor' |
See Also
For more information, see Rounding Modes (Fixed-Point Designer).
Saturate on integer overflow — Method of overflow action
off
(default) | on
Specify whether overflows saturate or wrap.
on
— Overflows saturate to either the minimum or maximum value that the data type can represent.off
— Overflows wrap to the appropriate value that the data type can represent.
For example, the maximum value that the signed 8-bit integer int8
can represent is 127. Any block operation result greater than this maximum value causes
overflow of the 8-bit integer.
With this parameter selected, the block output saturates at 127. Similarly, the block output saturates at a minimum output value of -128.
With this parameter cleared, the software interprets the overflow-causing value as
int8
, which can produce an unintended result. For example, a block result of 130 (binary 1000 0010) expressed asint8
is -126.
Tips
Consider selecting this parameter when your model has a possible overflow and you want explicit saturation protection in the generated code.
Consider clearing this parameter when you want to optimize efficiency of your generated code. Clearing this parameter also helps you to avoid overspecifying how a block handles out-of-range signals. For more information, see Troubleshoot Signal Range Errors.
When you select this parameter, saturation applies to every internal operation on the block, not just the output or result.
In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.
Programmatic Use
To set the block parameter value programmatically, use
the set_param
function.
Parameter: | SaturateOnIntegerOverflow |
Values: | 'off' (default) | 'on' |
Sample time — Time interval between samples
0.1
(default) | scalar
Specify the time interval between samples. To inherit the sample time,
set this parameter to -1
. See Specify Sample Time
for more information.
Programmatic Use
Block Parameter:
SampleTime |
Type: character vector |
Values: scalar |
Default:
'0.1' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
Algorithms
Enter signal notations in the Waveform Definition table, one waveform definition per line. To add a waveform definition, click Add. The new waveform appears as an empty character vector. The block interprets empty character vectors or white space character vectors as ground.
To remove a waveform definition, click Remove. You can select multiple waveforms using Ctrl+click or Shift+click.
Constant
Constant values can be:
Numbers
Workspace variables
Scalar, real variables only
Built-in MATLAB constant,
pi
1
1.1
x
pi
Gaussian Noise
gaussian(mean
,variance
,seed
)
gaussian('Mean',mean
,'Variance',variance
,'Seed',seed
)
mean
— Mean value of the random variable output.Default: 0
variance
— Standard deviation squared of the random variable output.Default: 1
Value: Positive constant or positive real scalar variable
seed
— Initial seed value for the random number generator.Default: 0
Value: Constant or real scalar variable
gaussian('Mean',0,'Variance',10,'Seed',1)
Pulse
pulse(amplitude
,trigger_time
,duration
)
pulse('Amplitude',amplitude
,'TriggerTime',trigger_time
,'Duration',duration
)
amplitude
— Value of signal when pulse is high.Default: 1
trigger_time
— Elapsed simulation time when signal changes to amplitude, in seconds.Default: 1
Value: Constant or real scalar variable
duration
— How long the signal remains at the given amplitude before returning to ground, in seconds.Default: 1
Value: Positive constant or positive real scalar variable
pulse('Amplitude',1,'TriggerTime',1,'Duration',1)
Sawtooth
sawtooth(amplitude
,frequency
,phase_offset
)
sawtooth('Amplitude',amplitude
,'Frequency',frequency
,'Phase',phase_offset
)
amplitude
— Sawtooth peak value.Default: 1
frequency
— Waveform frequency, in rad/s.Default: 1
phase_offset
— Horizontal signal shift, based on elapsed simulation time, in seconds.Default: 0
sawtooth('Amplitude',1,'Frequency',1,'Phase',0)
Sine Wave
sin(amplitude
,frequency
,phase_offset
)
sin('Amplitude',amplitude
,'Frequency',frequency
,'Phase',phase_offset
)
amplitude
— Amplitude of sine wave.Default: 1
frequency
— Waveform frequency, in rad/s.Default: 1
phase_offset
— Phase offset, in rads.Default: 0
sin('Amplitude',1,'Frequency',1,'Phase',0)
To get the cosine waveform:
sin('Amplitude',1,'Frequency',1,'Phase',pi/2)
Square
square(amplitude
,frequency
,phase_delay
,duty_cycle
)
square('Amplitude',amplitude
,'Frequency',frequency
,'Phase',phase_delay
,... 'DutyCycle',duty_cycle
)
amplitude
— Amplitude of signal.Default: 1
frequency
— Waveform frequency in rad/s.Default: 1
phase_delay
— Horizontal signal shift based on elapsed simulation time, in seconds.Default: 0
duty_cycle
— Percentage of high signal per period (0–100%). The block clips the minimum signal to 0% and the maximum signal to 100%.Default: 50
square('Amplitude',1,'Frequency',1,'Phase',0,'DutyCycle',50)
Step
step(step_time
,initial_value
,final_value
)
step('StepTime',step_time
,'InitialValue',initial_value
,'FinalValue',final_value
)
step_time
— Elapsed simulation time when signal changes frominitial value
tofinal value
, in seconds.Default: 1
Value: Constant or positive real scalar variable.
initial_value
— Value of signal when elapsed simulation time is less thanstep_time
, in seconds.Default: 0
final_value
— Value of signal when elapsed simulation time is greater than or equal to step time, in seconds.Default: 1
step('StepTime',1,'InitialValue',0,'FinalValue',1)
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Not recommended for production code.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
Version History
Introduced in R2015b
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)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)