SignalProcessing
GenerateSignal
create a signal from an expression or procedure
Calling Sequence
Parameters
Options
Description
Examples
Compatibility
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 )
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
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.
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=b−an−1 when includefinishtime=true, and Δt=b−an 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=fsn−1 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=1b−a.
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+1−e. Then, when mirroring is added, the size becomes n2=n1+m⁢n1−1, and when copies are added, the size becomes n3=n2+c−1⁢n2−1. Finally, when the final time is potentially removed, the adjusted size is n4=n3+e−1. The output value of size is this n4, and the returned value of finishtime is a+b−a⁢m+1⁢c, 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.
with⁡SignalProcessing:
Example 1
Create Vectors of size 100 for the times and signal of 5⁢sin⁡t+3 over 0..2⁢π, and record the sample rate:
sample_rate,Times,Signal≔GenerateSignal⁡5⁢sin⁡t+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+1⁢cos⁡2⁢t, and then compute the signal-to-noise ratio. First, define the generator, sample rate, and number of points:
generator≔t↦sqrt⁡1+t2⋅cos⁡2⋅t
generator≔t↦1+t2⋅cos⁡2⋅t
sample_rate≔75.0
size≔28
size≔256
Now, define the standard deviation for the additive noise, and create records for the pure and noisy signals with all the outputs:
σ≔0.5
Pure≔GenerateSignal⁡generator,sample_rate,size,signalplotoptions=color=blue,title=Pure Signal Plot,periodogramoptions=color=blue,title=Pure Signal Periodogram,output=record:
Noisy≔GenerateSignal⁡generator,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:-display⁡Puresignalplot,Noisysignalplot,title=Pure and Noisy Signal Plots
plots:-display⁡Pureperiodogram,Noisyperiodogram,title=Pure and Noisy Signal Periodograms
Finally, compute the signal-to-noise ratio:
snr≔BandPower⁡Puresignal,sample_rateBandPower⁡Noisynoise,sample_rate
snr≔12.08654036
Example 3
Procedures that define non-continuous expressions can also be used as generators:
g≔unapply⁡piecewise⁡t<10,0,t<20,5,0,t
g≔t↦0t<105t<200otherwise
Now, define the start time, finish time, number of points, and time step:
a≔0
b≔30
n≔1024
dt≔b−an−1
dt≔10341
Finally, display the signal plot and (truncated) periodogram:
R≔GenerateSignal⁡g,a,dt,n,truncate=true,signalplotoptions=thickness=5,output=record:
Rsignalplot
Rperiodogram
Example 4
Complex signals can be generated and plotted:
R≔GenerateSignal⁡cos⁡t+I⁢sin⁡2⁢t,t=−3⁢π..3⁢π,256,output=record:
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:
g≔t↦10+3⋅cos⁡t
b≔10⁢π
n≔256
Now, plot three signals, one with no window applied, one with an unnormalized Hamming window applied, and one with a normalized Hamming window applied:
GenerateSignal⁡g,a..b,n,window=none,signalplotoptions=title=Signal Plot Without Window,output=signalplot
GenerateSignal⁡g,a..b,n,window=Hamming,windownormalization=false,signalplotoptions=title=Signal Plot With Unnormalized Hamming Window,output=signalplot
GenerateSignal⁡g,a..b,n,window=Hamming,windownormalization=true,signalplotoptions=title=Signal Plot With Normalized Hamming Window,output=signalplot
Example 6
Signals with multiple copies and symmetry can be created:
GenerateSignal⁡2⁢t,t=0..5,3,mirror=symmetric,output=signalplot
GenerateSignal⁡2⁢t+4⁢t⁢I,t=0..5,200,copies=5,jumps=true,output=signalplot
GenerateSignal⁡5+sqrt⁡1−t−14,t=0..2,200,mirror=antisymmetric,copies=4,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:
g≔t1+t
b≔1
n≔11
Define the time step, sample rate, and frequency step for when the right endpoint is included:
dt1≔b−an−1
dt1≔110
fs1≔1dt1
fs1≔10
df1≔fs1n−1
df1≔1
Define also the time step, sample rate, and frequency step for when the right endpoint is not included:
dt2≔b−an
dt2≔111
fs2≔1dt2
fs2≔11
df2≔fs2n
df2≔1
Finally, compare the signal plots for the two cases:
R1≔GenerateSignal⁡g,t=a..b,n,includefinishtime=true,includesamplerate=true,signalplotoptions=title=Signal Plot with Finish Time Included,periodogramoptions=title=Periodogram with Sample Rate Included,output=record:
DocumentTools:-Tabulate⁡R1signalplot,R1periodogram:
max⁡R1times
1.
max⁡R1frequencies
10.
R2≔GenerateSignal⁡g,t=a..b,n,includefinishtime=false,includesamplerate=false,signalplotoptions=title=Signal Plot with Finish Time Not Included,periodogramoptions=title=Periodogram with Sample Rate Not Included,output=record:
DocumentTools:-Tabulate⁡R2signalplot,R2periodogram:
max⁡R2times
0.909090909090909
max⁡R2frequencies
Example 8
A signal can be generated with analogue-to-digital conversion mimiced. For example:
Codebook≔Vector⁡21,i↦−1.0+0.25⋅i−0.25,datatype=float8
R≔GenerateSignal⁡sin⁡2⁢t,t=−2⁢π..2⁢π,250,quantization=Codebook,truncation=nearest,output=record:
Rsignal
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[BandPower]
SignalProcessing[FFT]
SignalProcessing[GenerateGaussian]
SignalProcessing[HammingWindow]
SignalProcessing[Periodogram]
SignalProcessing[PowerSpectrum]
SignalProcessing[Quantize]
SignalProcessing[SignalPlot]
Statistics[Sample]
Download Help Document