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

SignalProcessing

 GenerateSignal
 create a signal from an expression or procedure

 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 - numeric value for the finish time of the signal. finishtime must be larger than starttime. samplerate - positive numeric value for the sample rate of the signal size - integer, no smaller than 2; the number of points used in the discrete signal starttime - numeric value for the start time of the signal. starttime must be smaller than finishtime. timestep - positive numeric 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 numeric 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 numeric 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 numeric value (the time) is passed as input, the procedure must output either a real or complex numeric value. If callablegenerator, on the other hand, is passed, it must also take a single numeric value as input and output either a real or complex numeric 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=\mathrm{starttime}$, $b=\mathrm{finishtime}$, ${f}_{s}=\mathrm{samplerate}$, and $n=\mathrm{size}$. The time step, $\mathrm{Δt}$, is computed as $\mathrm{Δt}=\frac{b-a}{n-1}$ when includefinishtime=true, and $\mathrm{Δt}=\frac{b-a}{n}$ when includefinishtime=false. Moreover, we use the relationship $\mathrm{Δt}=\frac{1}{{f}_{s}}$, and the times Vector ends at $b$ and $b-\mathrm{Δ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, $\mathrm{Δf}$, is given by $\mathrm{Δf}=\frac{{f}_{s}}{n-1}$ and the untruncated frequencies Vector ends at ${f}_{s}$. When includesamplerate=false, on the other hand, $\mathrm{Δf}=\frac{{f}_{s}}{n}$ and the untruncated frequencies Vector ends at ${f}_{s}-\mathrm{Δf}$. Moreover, the frequency step size, $\mathrm{Δf}$, satisfies $\mathrm{Δf}=\frac{1}{b-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=⌊\frac{n}{2}⌋+1$.
 • Let $\mathrm{\sigma }=\mathrm{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 $\mathrm{\sigma }$, 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 $\frac{\mathrm{\sigma }}{\sqrt{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 ${n}_{0}=\mathrm{size}$, $m$ be 0 when mirror=none and 1 otherwise, $c=\mathrm{copies}$, and $e$ be 1 when includefinishtime=true and 0 otherwise. When the junction point is first added, the size becomes ${n}_{1}={n}_{0}+1-e$. Then, when mirroring is added, the size becomes ${n}_{2}={n}_{1}+m\left({n}_{1}-1\right)$, and when copies are added, the size becomes ${n}_{3}={n}_{2}+\left(c-1\right)\left({n}_{2}-1\right)$. Finally, when the final time is potentially removed, the adjusted size is ${n}_{4}={n}_{3}+e-1$. The output value of size is this ${n}_{4}$, and the returned value of finishtime is $a+\left(b-a\right)\left(m+1\right)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.

Examples

 > $\mathrm{with}\left(\mathrm{SignalProcessing}\right):$

Example 1

 • Create Vectors of size $100$ for the times and signal of $5\mathrm{sin}\left(t\right)+3$ over $0..2\mathrm{\pi }$, and record the sample rate:
 > $\mathrm{sample_rate},\mathrm{Times},\mathrm{Signal}≔\mathrm{GenerateSignal}\left(5\mathrm{sin}\left(t\right)+3,t=0..2\mathrm{Pi},100,'\mathrm{output}'=\left['\mathrm{samplerate}','\mathrm{times}','\mathrm{signal}'\right]\right)$

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 $\sqrt{{t}^{2}+1}\mathrm{cos}\left(2t\right)$, and then compute the signal-to-noise ratio. First, define the generator, sample rate, and number of points:
 > $\mathrm{generator}≔t→\sqrt{1+{t}^{2}}\mathrm{cos}\left(2t\right)$
 ${\mathrm{generator}}{≔}{t}{↦}\sqrt{{1}{+}{{t}}^{{2}}}{\cdot }{\mathrm{cos}}{}\left({2}{\cdot }{t}\right)$ (1)
 > $\mathrm{sample_rate}≔75.0$
 ${\mathrm{sample_rate}}{≔}{75.0}$ (2)
 > $\mathrm{size}≔{2}^{8}$
 ${\mathrm{size}}{≔}{256}$ (3)
 • Now, define the standard deviation for the additive noise, and create records for the pure and noisy signals with all the outputs:
 > $\mathrm{σ}≔0.5$
 ${\mathrm{\sigma }}{≔}{0.5}$ (4)
 > $\mathrm{Pure}≔\mathrm{GenerateSignal}\left(\mathrm{generator},\mathrm{sample_rate},\mathrm{size},'\mathrm{signalplotoptions}'=\left['\mathrm{color}'='\mathrm{blue}','\mathrm{title}'="Pure Signal Plot"\right],'\mathrm{periodogramoptions}'=\left['\mathrm{color}'='\mathrm{blue}','\mathrm{title}'="Pure Signal Periodogram"\right],'\mathrm{output}'='\mathrm{record}'\right):$
 > $\mathrm{Noisy}≔\mathrm{GenerateSignal}\left(\mathrm{generator},\mathrm{sample_rate},\mathrm{size},'\mathrm{noisetype}'='\mathrm{additive}','\mathrm{noisedeviation}'=\mathrm{σ},'\mathrm{signalplotoptions}'=\left['\mathrm{color}'='\mathrm{burgundy}','\mathrm{title}'="Noisy Signal Plot"\right],'\mathrm{periodogramoptions}'=\left['\mathrm{color}'='\mathrm{burgundy}','\mathrm{title}'="Noisy Signal Periodogram"\right],'\mathrm{output}'='\mathrm{record}'\right):$
 • We can compare the signals visually:
 > $\mathrm{plots}:-\mathrm{display}\left({\mathrm{Pure}}_{'\mathrm{signalplot}'},{\mathrm{Noisy}}_{'\mathrm{signalplot}'},'\mathrm{title}'="Pure and Noisy Signal Plots"\right)$
 > $\mathrm{plots}:-\mathrm{display}\left({\mathrm{Pure}}_{'\mathrm{periodogram}'},{\mathrm{Noisy}}_{'\mathrm{periodogram}'},'\mathrm{title}'="Pure and Noisy Signal Periodograms"\right)$
 • Finally, compute the signal-to-noise ratio:
 > $\mathrm{snr}≔\frac{\mathrm{BandPower}\left({\mathrm{Pure}}_{'\mathrm{signal}'},\mathrm{sample_rate}\right)}{\mathrm{BandPower}\left({\mathrm{Noisy}}_{'\mathrm{noise}'},\mathrm{sample_rate}\right)}$
 ${\mathrm{snr}}{≔}{12.0865403593847}$ (5)

Example 3

 • Procedures that define non-continuous expressions can also be used as generators:
 > $g≔\mathrm{unapply}\left(\mathrm{piecewise}\left(t<10,0,t<20,5,0\right),t\right)$
 ${g}{≔}{t}{↦}\left\{\begin{array}{cc}{0}& {t}{<}{10}\\ {5}& {t}{<}{20}\\ {0}& {\mathrm{otherwise}}\end{array}\right\$ (6)
 • Now, define the start time, finish time, number of points, and time step:
 > $a≔0$
 ${a}{≔}{0}$ (7)
 > $b≔30$
 ${b}{≔}{30}$ (8)
 > $n≔1024$
 ${n}{≔}{1024}$ (9)
 > $\mathrm{dt}≔\mathrm{evalhf}\left(\frac{b-a}{n-1}\right)$
 ${\mathrm{dt}}{≔}{0.0293255131964809401}$ (10)
 • Finally, display the signal plot and (truncated) periodogram:
 > $R≔\mathrm{GenerateSignal}\left(g,a,\mathrm{dt},n,'\mathrm{truncate}'='\mathrm{true}','\mathrm{signalplotoptions}'=\left['\mathrm{thickness}'=5\right],'\mathrm{output}'='\mathrm{record}'\right):$
 > ${R}_{'\mathrm{signalplot}'}$
 > ${R}_{'\mathrm{periodogram}'}$

Example 4

 • Complex signals can be generated and plotted:
 > $R≔\mathrm{GenerateSignal}\left(\mathrm{cos}\left(t\right)+I\mathrm{sin}\left(2t\right),t=-3\mathrm{Pi}..3\mathrm{Pi},256,'\mathrm{output}'='\mathrm{record}'\right):$
 > ${R}_{'\mathrm{signalplot}'}$

 > ${R}_{'\mathrm{periodogram}'}$

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\mathrm{cos}\left(t\right)$
 ${g}{≔}{t}{↦}{10}{+}{3}{\cdot }{\mathrm{cos}}{}\left({t}\right)$ (11)
 > $a≔0$
 ${a}{≔}{0}$ (12)
 > $b≔10\mathrm{Pi}$
 ${b}{≔}{10}{}{\mathrm{\pi }}$ (13)
 > $n≔256$
 ${n}{≔}{256}$ (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:
 > $\mathrm{GenerateSignal}\left(g,a..b,n,'\mathrm{window}'='\mathrm{none}','\mathrm{signalplotoptions}'=\left['\mathrm{title}'="Signal Plot Without Window"\right],'\mathrm{output}'='\mathrm{signalplot}'\right)$
 > $\mathrm{GenerateSignal}\left(g,a..b,n,'\mathrm{window}'='\mathrm{Hamming}','\mathrm{windownormalization}'='\mathrm{false}','\mathrm{signalplotoptions}'=\left['\mathrm{title}'="Signal Plot With Unnormalized Hamming Window"\right],'\mathrm{output}'='\mathrm{signalplot}'\right)$
 > $\mathrm{GenerateSignal}\left(g,a..b,n,'\mathrm{window}'='\mathrm{Hamming}','\mathrm{windownormalization}'='\mathrm{true}','\mathrm{signalplotoptions}'=\left['\mathrm{title}'="Signal Plot With Normalized Hamming Window"\right],'\mathrm{output}'='\mathrm{signalplot}'\right)$

Example 6

 • Signals with multiple copies and symmetry can be created:
 > $\mathrm{GenerateSignal}\left(2t,t=0..5,3,'\mathrm{mirror}'='\mathrm{symmetric}','\mathrm{output}'='\mathrm{signalplot}'\right)$
 > $\mathrm{GenerateSignal}\left(2t+4tI,t=0..5,200,'\mathrm{copies}'=5,'\mathrm{jumps}'='\mathrm{true}','\mathrm{output}'='\mathrm{signalplot}'\right)$

 > $\mathrm{GenerateSignal}\left(5+\sqrt{1-{\left(t-1\right)}^{4}},t=0..2,200,'\mathrm{mirror}'='\mathrm{antisymmetric}','\mathrm{copies}'=4,'\mathrm{output}'='\mathrm{signalplot}'\right)$

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≔\frac{t}{1+t}$
 ${g}{≔}\frac{{t}}{{1}{+}{t}}$ (15)
 > $a≔0$
 ${a}{≔}{0}$ (16)
 > $b≔1$
 ${b}{≔}{1}$ (17)
 > $n≔11$
 ${n}{≔}{11}$ (18)
 • Define the time step, sample rate, and frequency step for when the right endpoint is included:
 > $\mathrm{dt1}≔\mathrm{evalhf}\left(\frac{b-a}{n-1}\right)$
 ${\mathrm{dt1}}{≔}{0.100000000000000006}$ (19)
 > $\mathrm{fs1}≔\mathrm{evalhf}\left(\frac{1}{\mathrm{dt1}}\right)$
 ${\mathrm{fs1}}{≔}{10.}$ (20)
 > $\mathrm{df1}≔\mathrm{evalhf}\left(\frac{\mathrm{fs1}}{n-1}\right)$
 ${\mathrm{df1}}{≔}{1.}$ (21)
 • Define also the time step, sample rate, and frequency step for when the right endpoint is not included:
 > $\mathrm{dt2}≔\mathrm{evalhf}\left(\frac{b-a}{n}\right)$
 ${\mathrm{dt2}}{≔}{0.0909090909090909116}$ (22)
 > $\mathrm{fs2}≔\mathrm{evalhf}\left(\frac{1}{\mathrm{dt2}}\right)$
 ${\mathrm{fs2}}{≔}{11.}$ (23)
 > $\mathrm{df2}≔\mathrm{evalhf}\left(\frac{\mathrm{fs2}}{n}\right)$
 ${\mathrm{df2}}{≔}{1.}$ (24)
 • Finally, compare the signal plots for the two cases:
 > $\mathrm{R1}≔\mathrm{GenerateSignal}\left(g,t=a..b,n,'\mathrm{includefinishtime}'='\mathrm{true}','\mathrm{includesamplerate}'='\mathrm{true}','\mathrm{signalplotoptions}'=\left['\mathrm{title}'="Signal Plot with Finish Time Included"\right],'\mathrm{periodogramoptions}'=\left['\mathrm{title}'="Periodogram with Sample Rate Included"\right],'\mathrm{output}'='\mathrm{record}'\right):$
 > $\mathrm{DocumentTools}:-\mathrm{Tabulate}\left(\left[{\mathrm{R1}}_{'\mathrm{signalplot}'},{\mathrm{R1}}_{'\mathrm{periodogram}'}\right]\right):$

 > $\mathrm{max}\left({\mathrm{R1}}_{'\mathrm{times}'}\right)$
 ${1.}$ (25)
 > $\mathrm{max}\left({\mathrm{R1}}_{'\mathrm{frequencies}'}\right)$
 ${10.}$ (26)
 > $\mathrm{R2}≔\mathrm{GenerateSignal}\left(g,t=a..b,n,'\mathrm{includefinishtime}'='\mathrm{false}','\mathrm{includesamplerate}'='\mathrm{false}','\mathrm{signalplotoptions}'=\left['\mathrm{title}'="Signal Plot with Finish Time Not Included"\right],'\mathrm{periodogramoptions}'=\left['\mathrm{title}'="Periodogram with Sample Rate Not Included"\right],'\mathrm{output}'='\mathrm{record}'\right):$
 > $\mathrm{DocumentTools}:-\mathrm{Tabulate}\left(\left[{\mathrm{R2}}_{'\mathrm{signalplot}'},{\mathrm{R2}}_{'\mathrm{periodogram}'}\right]\right):$

 > $\mathrm{max}\left({\mathrm{R2}}_{'\mathrm{times}'}\right)$
 ${0.909090909090909}$ (27)
 > $\mathrm{max}\left({\mathrm{R2}}_{'\mathrm{frequencies}'}\right)$
 ${10.}$ (28)

Example 8

 • A signal can be generated with analogue-to-digital conversion mimiced. For example:
 > $\mathrm{Codebook}≔\mathrm{Vector}\left(21,i→-1.0+0.25\left(i-1\right),'\mathrm{datatype}'='{\mathrm{float}}_{8}'\right)$
 > $R≔\mathrm{GenerateSignal}\left(\mathrm{sin}\left(2t\right),t=-2\mathrm{Pi}..2\mathrm{Pi},250,'\mathrm{quantization}'=\left[\mathrm{Codebook},'\mathrm{truncation}'='\mathrm{nearest}'\right],'\mathrm{output}'='\mathrm{record}'\right):$
 > ${R}_{'\mathrm{signal}'}$
 > ${R}_{'\mathrm{signalplot}'}$

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.