Documentation

Waveform Generator

Output waveforms using signal notations

Library

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 Supported Waveforms).

  • Name-value syntax — Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN. For more information, see Supported Waveforms.

This block supports normal, accelerator, and rapid accelerator modes and fast restart.

Supported Operators

OperationOperator

Absolute value

abs()

Addition

+

Division

/

Multiplication

*

Parentheses

()

Subtraction

-

Unary minus

-

The Waveform block observes the following rules of operator precedence:

  1. ( )

  2. + - (unary)

  3. * /

  4. + -

Supported Waveforms

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

Examples

  • 1

  • 1.1

  • x

  • pi

Gaussian Noise

Syntax

gaussian(mean,variance,seed)
gaussian('Mean',mean,'Variance',variance,'Seed',seed)

Input Arguments

  • 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

Example

gaussian('Mean',0,'Variance',10,'Seed',1)

Pulse

Syntax

pulse(amplitude,trigger_time,duration)
pulse('Amplitude',amplitude,'TriggerTime',trigger_time,'Duration',duration)

Input Arguments

  • 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

Example

pulse('Amplitude',1,'TriggerTime',1,'Duration',1)

Sawtooth

Syntax

sawtooth(amplitude,frequency,phase_offset)
sawtooth('Amplitude',amplitude,'Frequency',frequency,'Phase',phase_offset)

Input Arguments

  • 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

Example

sawtooth('Amplitude',1,'Frequency',1,'Phase',0)

Sine Wave

Syntax

sin(amplitude,frequency,phase_offset)
sin('Amplitude',amplitude,'Frequency',frequency,'Phase',phase_offset)

Input Arguments

  • amplitude — Amplitude of sine wave.

    • Default: 1

  • frequency — Waveform frequency, in rad/s.

    • Default: 1

  • phase_offset — Phase offset, in rads.

    • Default: 0

Examples

sin('Amplitude',1,'Frequency',1,'Phase',0)

To get the cosine waveform:

sin('Amplitude',1,'Frequency',1,'Phase',pi/2)

Square

Syntax

square(amplitude,frequency,phase_delay,duty_cycle)
square('Amplitude',amplitude,'Frequency',frequency,'Phase',phase_delay,...
'DutyCycle',duty_cycle)

Input Arguments

  • 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

Example

square('Amplitude',1,'Frequency',1,'Phase',0,'DutyCycle',50)

Step

Syntax

step(step_time,initial_value,final_value)
step('StepTime',step_time,'InitialValue',initial_value,'FinalValue',final_value)

Input Arguments

  • step_time — Elapsed simulation time when signal changes from initial value to final value, in seconds.

    • Default: 1

    • Value: Constant or positive real scalar variable.

  • initial_value — Value of signal when elapsed simulation time is less than step_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

Example

step('StepTime',1,'InitialValue',0,'FinalValue',1)

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 Supported Waveforms.

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.

Data Type Support

The Waveform Generator block outputs scalar values. The default data type is double. However, the block also supports a large subset of Simulink data types, including fixed point (see Output data type).

For more information, see Data Types Supported by Simulink in the Simulink® documentation.

Parameters

Output Signal

Select the signal. The number corresponds to the line item in the Waveform Definition table. You can change this parameter while a simulation is running.

Settings

Default: 1

Command-Line Information

See Block-Specific Parameters for the command-line information.

Waveform Definition

Enter signal notations in the Waveform Definition table, one waveform definition per line. For more information on waveform definitions and how to enter them, see Supported Waveforms.

Settings

Default: none

Output minimum

Lower value of the output range that Simulink checks.

Settings

Default: [] (unspecified)

Specify this number as a finite, real, double, scalar value.

Simulink uses the minimum to perform:

Note

Output minimum does not saturate or clip the actual output signal. Use the Saturation block instead.

Command-Line Information

Parameter: OutMin
Type: character vector
Value: '[ ]'
Default: '[ ]'

Output maximum

Upper value of the output range that Simulink checks.

Settings

Default: [] (unspecified)

Specify this number as a finite, real, double, scalar value.

Simulink uses the maximum value to perform:

Note

Output maximum does not saturate or clip the actual output signal. Use the Saturation block instead.

Command-Line Information

Parameter: OutMax
Type: character vector
Value: '[ ]'
Default: '[ ]'

Output data type

Specify the output data type.

Settings

Default: Inherit: Inherit via back propagation

Inherit: Inherit via back propagation

Simulink chooses a data type to balance numerical accuracy, performance, and generated code size, while taking into account the properties of the embedded target hardware. If you change the embedded target settings, the data type selected by the internal rule might change. For example, if the block multiplies an input of type int8 by a gain of int16 and ASIC/FPGA is specified as the targeted hardware type, the output data type is sfix24. If Unspecified (assume 32-bit Generic), i.e., a generic 32-bit microprocessor, is specified as the target hardware, the output data type is int32. If none of the word lengths provided by the target microprocessor can accommodate the output range, Simulink software displays an error in the Diagnostic Viewer.

It is not always possible for the software to optimize code efficiency and numerical accuracy at the same time. If the internal rule doesn’t meet your specific needs for numerical accuracy or performance, use one of the following options:

  • Specify the output data type explicitly.

  • Explicitly specify a default data type such as fixdt(1,32,16) and then use the Fixed-Point Tool to propose data types for your model. For more information, see fxptdlg.

  • To specify your own inheritance rule, use Inherit: Inherit via back propagation and then use a Data Type Propagation block. Examples of how to use this block are available in the Signal Attributes library Data Type Propagation Examples block.

Inherit: Inherit via back propagation

Use data type of the driving block.

double

Output data type is double.

single

Output data type is single.

int8

Output data type is int8.

uint8

Output data type is uint8.

int16

Output data type is int16.

uint16

Output data type is uint16.

int32

Output data type is int32.

uint32

Output data type is uint32.

boolean

Output data type is boolean.

fixdt(1,16)

Output data type is fixed point fixdt(1,16).

fixdt(1,16,0)

Output data type is fixed point fixdt(1,16,0).

fixdt(1,16,2^0,0)

Output data type is fixed point fixdt(1,16,2^0,0).

Command-Line Information

See Block-Specific Parameters for the command-line information.

See Also

See Control Signal Data Types for more information.

Data type override

Specify data type override mode for this signal.

Settings

Default: double

Inherit

Inherits the data type override setting from its context, that is, from the block, Simulink.Signal object or Stateflow® chart in Simulink that is using the signal.

Off

Ignores the data type override setting of its context and uses the fixed-point data type specified for the signal.

Tip

The ability to turn off data type override for an individual data type provides greater control over the data types in your model when you apply data type override. For example, you can use this option to ensure that data types meet the requirements of downstream blocks regardless of the data type override setting.

Dependency

This parameter appears only when the Mode is Built in or Fixed point.

Signedness

Specify whether you want the fixed-point data as signed or unsigned.

Settings

Default: Signed

Signed

Specify the fixed-point data as signed.

Unsigned

Specify the fixed-point data as unsigned.

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Word length

Specify the bit size of the word that holds the quantized integer.

Settings

Default: 16

Minimum: 0

Maximum: 32

Dependencies

Selecting Mode > Fixed point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Scaling

Specify the method for scaling your fixed-point data to avoid overflow conditions and minimize quantization errors.

Settings

Default: Binary point

Binary point

Specify binary point location.

Slope and bias

Enter slope and bias.

Dependencies

Selecting Mode > Fixed point enables this parameter.

Selecting Binary point enables:

  • Fraction length

Selecting Slope and bias enables:

  • Slope

  • Bias

Command-Line Information

See Block-Specific Parameters for the command-line information.

Fraction length

Specify fraction length for fixed-point data type.

Settings

Default: 0

Binary points can be positive or negative integers.

Dependencies

Selecting Scaling > Binary point enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Slope

Specify slope for the fixed-point data type.

Settings

Default: 2^0

Specify any positive real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Bias

Specify bias for the fixed-point data type.

Settings

Default: 0

Specify any real number.

Dependencies

Selecting Scaling > Slope and bias enables this parameter.

See Also

For more information, see Specifying a Fixed-Point Data Type.

Lock output data type setting against changes by the fixed-point tools

Select to lock the output data type setting of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor.

Settings

Default: Off

On

Locks the output data type setting for this block.

Off

Allows the Fixed-Point Tool and the Fixed-Point Advisor to change the output data type setting for this block.

Command-Line Information

Parameter: LockScale
Type: character vector
Value: 'off' | 'on'
Default: 'off'

See Also

For more information, see Use Lock Output Data Type Setting (Fixed-Point Designer).

Integer rounding mode

Specify the rounding mode for fixed-point operations.

Settings

Default: Floor

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.

Command-Line Information

Parameter: RndMeth
Type: character vector
Value: 'Ceiling' | 'Convergent' | 'Floor' | 'Nearest' | 'Round' | 'Simplest' | 'Zero'
Default: 'Floor'

See Also

For more information, see Rounding (Fixed-Point Designer) in the Fixed-Point Designer documentation.

Saturate on integer overflow

Specify whether overflows saturate.

Settings

Default: Off

On

Overflows saturate to either the minimum or maximum value that the data type can represent.

For example, an overflow associated with a signed 8-bit integer can saturate to -128 or 127.

Off

Overflows wrap to the appropriate value that the data type can represent.

For example, the number 130 does not fit in a signed 8-bit integer and wraps to -126.

Tips

  • Consider selecting this check box when your model has a possible overflow and you want explicit saturation protection in the generated code.

  • Consider clearing this check box when you want to optimize efficiency of your generated code.

    Clearing this check box also helps you to avoid overspecifying how a block handles out-of-range signals. For more information, see Check for Signal Range Errors.

  • When you select this check box, 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.

Command-Line Information

Parameter: SaturateOnIntegerOverflow
Type: character vector
Value: 'off' | 'on'
Default: 'off'

Sample time

Enter the time interval between sample time hits or specify -1 to inherit the sample time.

Settings

Default: 0.1

This value cannot be 0 (continuous) or inf (constant). For more information, see Sample Time.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Mode

Select the category of data to specify.

Settings

Default: Inherit

Inherit

Inheritance rules for data types. Selecting Inherit enables Inherit via back propagation.

Built in

Built-in data types. Selecting Built in enables a second menu/text box to the right. Select one of the following choices:

  • double (default)

  • single

  • int8

  • uint8

  • int16

  • uint16

  • int32

  • uint32

  • boolean

Fixed point

Fixed-point data types.

Enumerated

Enumerated data types. Selecting Enumerated enables a second menu/text box to the right, where you can enter the class name.

Expression

Expressions that evaluate to data types. Selecting Expression enables a second menu/text box to the right, where you can enter the expression.

Dependency

Clicking the Show data type assistant button enables this parameter.

Command-Line Information

See Block-Specific Parameters for the command-line information.

>> (Show data type assistant)

Displays the Data Type Assistant, to help you to set the Output data type parameter.

Characteristics

Data Types

See Data Type Support

Sample Time

Specified in the Sample time parameter

Multidimensional Signals

No

Variable-Size Signals

No

Zero-Crossing Detection

No

Code Generation

Yes

Introduced in R2015b

Was this topic helpful?