GenerateSignal - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


SignalProcessing

  

GenerateSignal

  

create a signal from an expression or procedure

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

GenerateSignal( algebraicgenerator, timevariable = starttime .. finishtime, size, options )

GenerateSignal( callablegenerator, starttime .. finishtime, size, options )

GenerateSignal( algebraicgenerator, timevariable, starttime, timestep, size, options )

GenerateSignal( callablegenerator, starttime, timestep, size, options )

GenerateSignal( algebraicgenerator, timevariable, samplerate, size, options )

GenerateSignal( callablegenerator, samplerate, size, options )

Parameters

algebraicgenerator

-

algebraic expression used to generate the discrete signal

callablegenerator

-

procedure or appliable module used to generate the discrete signal

finishtime

-

real value for the finish time of the signal. finishtime must be larger than starttime.

samplerate

-

positive real value for the sample rate of the signal

size

-

integer, no smaller than 2; the number of points used in the discrete signal

starttime

-

real value for the start time of the signal. starttime must be smaller than finishtime.

timestep

-

positive real value; the time step of the signal

timevariable

-

name for the time variable

Options

• 

copies: Positive integer which specifies how many copies of the base signal are to be included. The default is 1.

• 

datatype: One of float[8], complex[8], and recommended, specifies the datatype of the signal Vector. The default is recommended.

• 

fftnormalization: One of none, symmetric, or full, indicates the normalization to be applied when using the FFT. The default is symmetric.

• 

includefinishtime: Either true or false, specifies if the times Vector will end at finishtime. The default is true.

• 

includesamplerate: Either true or false, specifies if the (untruncated) frequencies Vector will end at samplerate. The default is true.

• 

jumps: Either true or false, specifies if the command should check for and handle jump discontinuities when creating the signal plot. The default is false.

• 

jumpnumber: Positive integer, specifies the number of jump discontinuities to find in the signal plot. The default is NULL.

• 

jumptolerance: Non-negative real value used to detect jump discontinuities in the signal plot. The default is NULL.

• 

mirror: One of none, symmetric, and antisymmetric, specifies if the signal should be extended on the right to include the mirror image. The default is none.

• 

noisedeviation: Non-negative real value for the standard deviation of the white noise to be applied to the signal. The default is 0.0.

• 

noisetype: Either additive or multiplicative, specifies how the white noise is to be applied to the signal. The default is additive.

• 

output: The type of output. The supported options are:

– 

fft: Returns a Vector, of complex[8] datatype, containing the FFT of the signal.

– 

finishtime: Returns the finish time of the signal.

– 

frequencies: Returns a Vector, of float[8] datatype, containing the frequencies.

– 

frequencystep: Returns the frequency step of the frequencies Vector.

– 

noise: Returns a Vector, of float[8] or complex[8] datatype, containing the noise.

– 

periodogram: Returns a periodogram of the signal.

– 

power: Returns a Vector, of float[8] datatype, containing the power spectrum of the signal.

– 

puresignal: Returns a Vector, of float[8] or complex[8] datatype, containing the signal before it is modified by noise or window.

– 

samplerate: Returns the sample rate.

– 

signal: Returns a Vector, of float[8] or complex[8] datatype, containing the signal. This is the default.

– 

signalplot: Returns a plot of the signal.

– 

starttime: Returns the start time of the signal.

– 

size: Returns the number of points used to generate the signal.

– 

times: Returns a Vector, of float[8] datatype, containing the times.

– 

timestep: Returns the time step of the times Vector.

– 

window: Returns a Vector, of float[8] datatype, which is used to apply the window.

– 

record: Returns a record with the previous options.

– 

list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order.

• 

periodogramoptions: List of options to be passed to the plot command creating the periodogram of the signal. The default is [].

• 

quantization: Either the keyword none or a list of options for quantization of the signal. The elements of the list are passed along with the signal to the Quantize command. The default is none.

• 

signalplotoptions: List of options to be passed to the plot command(s) creating the plot(s) of the signal. When the signal is complex and there are two plots (one for the real part and one for the complex part), these options are passed to both plots. The default is [].

• 

signalplotcomplexoptions: List of options to be passed to the plot command creating the plot of the complex part of the signal, in the case where the signal is complex. The default is [].

• 

signalplotrealoptions: List of options to be passed to the plot command creating the plot of the real part of the signal, in the case where the signal is complex. The default is [].

• 

truncate: Either true or false, specifies if, when the signal is real-valued, the second half of the frequencies, FFT, and power spectrum Vectors are to be discarded (due to the symmetry in the FFT). The default is false.

• 

window: Either a list, name, or string, specifies the windowing command to be applied to the signal. The default is none (for no windowing to be applied). If a list is passed, the first element provides the name of the windowing command, and any remaining terms are passed as options to the command.

• 

windownormalization: Either true or false, indicates if the windowing function is to be normalized with respect to Root Mean Square (RMS). The default is true.

Description

• 

The GenerateSignal command creates a signal of float[8] or complex[8] datatype from a procedure, appliable module, or algebraic expression.

• 

The expression algebraicgenerator, if passed, is used internally to create a procedure callablegenerator with timevariable as input. When a real value (the time) is passed as input, the procedure must output either a real or complex value. If callablegenerator, on the other hand, is passed, it must also take a single real value as input and output either a real or complex value.

• 

Suppose datatype=recommended. The GenerateSignal command attempts to use callablegenerator to construct a float[8] signal, first in evalhf mode, and then in regular mode if this fails. If a float[8] signal cannot be found, the command attempts to construct a complex[8] signal, first in evalhf mode, and then in regular mode if this fails. When datatype is either float[8] or complex[8], on the other hand, the command only attempts to construct a signal with the stipulated datatype. For the quickest execution of the command, it is recommended that the passed generator work in evalhf mode, and that the specific datatype be provided.

• 

Internally, the calling sequences with samplerate and starttime..finishtime are reduced to the calling sequence with starttime and timestep.

• 

Denote a=starttime, b=finishtime, fs=samplerate, and n=size. The time step, Δt, is computed as Δt=ban1 when includefinishtime=true, and Δt=ban when includefinishtime=false. Moreover, we use the relationship Δt=1fs, and the times Vector ends at b and bΔt, respectively, when includefinishtime=true and includefinishtime=false.

• 

When samplerate is passed, starttime is taken to be 0.0.

• 

When includesamplerate=true, the frequency step size, Δf, is given by Δf=fsn1 and the untruncated frequencies Vector ends at fs. When includesamplerate=false, on the other hand, Δf=fsn and the untruncated frequencies Vector ends at fsΔf. Moreover, the frequency step size, Δf, satisfies Δf=1ba.

• 

Setting includefinishtime=false would be useful, for example, if the resulting signal is to be periodic, and the excluded point at the end is equal to the point at the beginning.

• 

The signal and times Vectors will always have length n. The frequencies, FFT, and power spectrum Vectors will have length n when truncate=false or the signal has one or more non-trivial imaginary parts. Otherwise, they will have length m=n2+1.

• 

Let σ=noisedeviation. When the signal Vector has datatype float[8], or it has complex[8] datatype but no element has nonzero imaginary part, the noise Vector is constructed as a random Vector of float[8] datatype using a normal distribution having standard deviation σ, and mean 0.0 when noisetype=additive or 1.0 when noisetype=multiplicative. When the signal Vector has datatype complex[8] with at least one element with non-trivial imaginary part, on the other hand, the real and complex parts of the noise Vector are constructed separately in the same manner as the float[8] case, except σ2 is used as the standard deviation for the normal distribution. In both cases, the pure signal and noise Vectors are either added (when noisetype=additive) element-wise, or multiplied (when noisetype=multiplicative) element-wise, to form the noisy signal.

• 

Any noise, windowing, or quantization are applied in that order.

• 

The passed value of size refers to the size the signal would have without mirroring or multiple copies. When there is mirroring or multiple copies (mirroring occurs first, if there are both), the amplitude of the signal at the passed value of finishtime is computed, and serves as the junction point when the pieces from the base signal, mirroring, and copies are joined, with the final point of the left piece always being retained and the first point of the right piece always being omitted. Let n0=size, m be 0 when mirror=none and 1 otherwise, c=copies, and e be 1 when includefinishtime=true and 0 otherwise. When the junction point is first added, the size becomes n1=n0+1e. Then, when mirroring is added, the size becomes n2=n1+mn11, and when copies are added, the size becomes n3=n2+c1n21. Finally, when the final time is potentially removed, the adjusted size is n4=n3+e1. The output value of size is this n4, and the returned value of finishtime is a+bam+1c, where a and b are, respectively, the passed values of starttime and finishtime.

• 

When jumps is true, the command attempts to display jump discontinuities in the signal plot without connecting the left-hand and right-hand sides with a line. If no value for jumpnumber or jumptolerance is passed, the Root Mean Square (RMS) of all the amplitude changes in the signal are used as the tolerance to detect the jumps. Further, if jumpnumber is passed, the plotter uses the jumpnumber largest amplitude changes as the jump discontinuities. Finally, if jumptolerance is passed but jumpnumber is not passed, then this tolerance is used to detect the jump discontinuities.

• 

It is recommended that jumps be set to true only when jump discontinuities are expected. Moreover, jumpnumber is recommended when the exact number of discontinuities is known. Finally, jumptolerance is recommended when it is expected that size is large enough that genuine jump discontinuities are larger than jumptolerance, spurious jump discontinuities are smaller than jumptolerance, and the number of genuine jump discontinuities is small.

Examples

withSignalProcessing:

Example 1

• 

Create Vectors of size 100 for the times and signal of 5sint+3 over 0..2π, and record the sample rate:

sample_rate,Times,SignalGenerateSignal5sint+3,t=0..2π,100,output=samplerate,times,signal

Example 2

• 

The GenerateSignal command can also add noise to a signal, both additive and multiplicative. Here, let's generate and compare pure and noisy signals from t2+1cos2t, and then compute the signal-to-noise ratio. First, define the generator, sample rate, and number of points:

generatortsqrt1+t2cos2t

generatort1+t2cos2t

(1)

sample_rate75.0

sample_rate75.0

(2)

size28

size256

(3)
• 

Now, define the standard deviation for the additive noise, and create records for the pure and noisy signals with all the outputs:

σ0.5

σ0.5

(4)

PureGenerateSignalgenerator,sample_rate,size,signalplotoptions=color=blue,title=Pure Signal Plot,periodogramoptions=color=blue,title=Pure Signal Periodogram,output=record:

NoisyGenerateSignalgenerator,sample_rate,size,noisetype=additive,noisedeviation=σ,signalplotoptions=color=burgundy,title=Noisy Signal Plot,periodogramoptions=color=burgundy,title=Noisy Signal Periodogram,output=record:

• 

We can compare the signals visually:

plots:-displayPuresignalplot,Noisysignalplot,title=Pure and Noisy Signal Plots

plots:-displayPureperiodogram,Noisyperiodogram,title=Pure and Noisy Signal Periodograms

• 

Finally, compute the signal-to-noise ratio:

snrBandPowerPuresignal,sample_rateBandPowerNoisynoise,sample_rate

snr12.08654036

(5)

Example 3

• 

Procedures that define non-continuous expressions can also be used as generators:

gunapplypiecewiset<10&comma;0&comma;t<20&comma;5&comma;0&comma;t

gt0t<105t<200otherwise

(6)
• 

Now, define the start time, finish time, number of points, and time step:

a0

a0

(7)

b30

b30

(8)

n1024

n1024

(9)

dtban1

dt10341

(10)
• 

Finally, display the signal plot and (truncated) periodogram:

RGenerateSignalg&comma;a&comma;dt&comma;n&comma;truncate=true&comma;signalplotoptions=thickness=5&comma;output=record&colon;

Rsignalplot

Rperiodogram

Example 4

• 

Complex signals can be generated and plotted:

RGenerateSignalcost+Isin2t&comma;t=3π..3π&comma;256&comma;output=record&colon;

Rsignalplot

Rperiodogram

Example 5

• 

A window can be applied to the signal. For an example, first define the generator, start and finish times, and number of points:

gt10+3cost

gt10+3cost

(11)

a0

a0

(12)

b10π

b10π

(13)

n256

n256

(14)
• 

Now, plot three signals, one with no window applied, one with an unnormalized Hamming window applied, and one with a normalized Hamming window applied:

GenerateSignalg&comma;a..b&comma;n&comma;window=none&comma;signalplotoptions=title=Signal Plot Without Window&comma;output=signalplot

GenerateSignalg&comma;a..b&comma;n&comma;window=Hamming&comma;windownormalization=false&comma;signalplotoptions=title=Signal Plot With Unnormalized Hamming Window&comma;output=signalplot

GenerateSignalg&comma;a..b&comma;n&comma;window=Hamming&comma;windownormalization=true&comma;signalplotoptions=title=Signal Plot With Normalized Hamming Window&comma;output=signalplot

Example 6

• 

Signals with multiple copies and symmetry can be created:

GenerateSignal2t&comma;t=0..5&comma;3&comma;mirror=symmetric&comma;output=signalplot

GenerateSignal2t+4tI&comma;t=0..5&comma;200&comma;copies=5&comma;jumps=true&comma;output=signalplot

GenerateSignal5+sqrt1t14&comma;t=0..2&comma;200&comma;mirror=antisymmetric&comma;copies=4&comma;output=signalplot

Example 7

• 

Toggling the includefinishtime and includesamplerate options controls whether the times and frequencies Vectors include, respectively, the finish time and sample rate. First, define the generator for the signal, start time, finish time, and number of points:

gt1+t

gt1+t

(15)

a0

a0

(16)

b1

b1

(17)

n11

n11

(18)
• 

Define the time step, sample rate, and frequency step for when the right endpoint is included:

dt1ban1

dt1110

(19)

fs11dt1

fs110

(20)

df1fs1n1

df11

(21)
• 

Define also the time step, sample rate, and frequency step for when the right endpoint is not included:

dt2ban

dt2111

(22)

fs21dt2

fs211

(23)

df2fs2n

df21

(24)
• 

Finally, compare the signal plots for the two cases:

R1GenerateSignalg&comma;t=a..b&comma;n&comma;includefinishtime=true&comma;includesamplerate=true&comma;signalplotoptions=title=Signal Plot with Finish Time Included&comma;periodogramoptions=title=Periodogram with Sample Rate Included&comma;output=record&colon;

DocumentTools:-TabulateR1signalplot&comma;R1periodogram&colon;

 

maxR1times

1.

(25)

maxR1frequencies

10.

(26)

R2GenerateSignalg&comma;t=a..b&comma;n&comma;includefinishtime=false&comma;includesamplerate=false&comma;signalplotoptions=title=Signal Plot with Finish Time Not Included&comma;periodogramoptions=title=Periodogram with Sample Rate Not Included&comma;output=record&colon;

DocumentTools:-TabulateR2signalplot&comma;R2periodogram&colon;

 

maxR2times

0.909090909090909

(27)

maxR2frequencies

10.

(28)

Example 8

• 

A signal can be generated with analogue-to-digital conversion mimiced. For example:

CodebookVector21&comma;i1.0+0.25i0.25&comma;datatype=float8

RGenerateSignalsin2t&comma;t=2π..2π&comma;250&comma;quantization=Codebook&comma;truncation=nearest&comma;output=record&colon;

Rsignal

Rsignalplot

Compatibility

• 

The SignalProcessing:-GenerateSignal command was introduced in Maple 2022.

• 

For more information on Maple 2022 changes, see Updates in Maple 2022.

• 

The SignalProcessing:-GenerateSignal command was updated in Maple 2023.

• 

The quantization option was introduced in Maple 2023.

• 

For more information on Maple 2023 changes, see Updates in Maple 2023.

See Also

SignalProcessing

SignalProcessing[BandPower]

SignalProcessing[FFT]

SignalProcessing[GenerateGaussian]

SignalProcessing[HammingWindow]

SignalProcessing[Periodogram]

SignalProcessing[PowerSpectrum]

SignalProcessing[Quantize]

SignalProcessing[SignalPlot]

Statistics[Sample]