PowerSpectrum - Maple Help

SignalProcessing

 PowerSpectrum
 compute the power spectrum of an array of samples

 Calling Sequence PowerSpectrum( A, options ) PowerSpectrum( Br, Bi, options )

Parameters

 A - rtable or list of numeric values for the signal or spectrum. Br - rtable or list of numeric values for the real parts of the signal or spectrum. Bi - rtable or list of numeric values for the imaginary parts of the signal or spectrum.

Options

 • container: (optional) Predefined rtable of float[8] datatype having the same dimensions as the input rtable(s) to store the power spectrum.
 • dimension: (optional) Integer, non-empty list of integers, all, or "all", which specifies the dimensions of the signal to which the Discrete Fourier Transform (DFT) is to be applied. The default is 1.
 • fftnormalization: (optional) One of none, symmetric, or full, indicates the normalization to be applied when using the DFT. The default is symmetric.
 • frequencyunit: (optional) Unit which specifies the unit of frequency. The default is Unit(Hz). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of frequency.
 • periodogramoptions: (optional) List of additional plot options to be passed when creating the periodogram. The default is [].
 • powerscale: (optional) Unit which indicates the scaling, if any, to be applied to the power spectrum. Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of power (see below for more details). The default is Unit(1).
 • samplerate: (optional) Positive numeric value for the sampling rate. The default is 1.0.
 • temperendpoints: (optional) Either true or false, specifies whether the power spectrum is to be tempered at the endpoints. The default is false.
 • timeunit: (optional) Unit which specifies the unit of time. The default is Unit(s). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of time.
 • variety: (optional) Either signal or fft, specifies if the data passed is a signal or the DFT of a signal. The default is fft.
 • window: (optional) 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 (optional) Either true or false, indicates if the windowing function is to be normalized. The default is true.
 • output: (optional) The type of output. The supported options are:
 – frequencies: Returns a Vector of float[8] datatype containing the frequencies.
 – periodogram: Returns a periodogram which displays the power spectrum versus the frequencies.
 – power: Returns an rtable of float[8] datatype containing the power spectrum. This is the default.
 – times: Returns a Vector of float[8] datatype containing the times.
 – 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.

Description

 • The PowerSpectrum(A) command computes the power spectrum of the rtable or list A, and returns the result in an rtable of datatype float[8] having the same dimensions as A.
 • To determine the power spectrum of a 1-D signal:
 1 Apply a window, if any, to the signal.
 2 Compute the DFT of the windowed signal.
 3 Square the magnitudes of the elements.
 • When variety = signal, the size of all transform dimensions cannot be less than two.
 • When temperendpoints=true, the input has one or two dimensions, there is exactly one transform dimension, and the transform dimension has size no less than three, then the endpoints of the power spectrum in the transform dimension are halved.
 • The PowerSpectrum(Br,Bi) command computes the same result as the PowerSpectrum(A) command, but the real and imaginary parts of the complex numbers are stored, respectively, in Br and Bi. Of course, Br and Bi must have the same dimensions and be coercible to datatype float[8].
 • The rtable subtype returned by the PowerSpectrum command will be the same as the first rtable passed, or an Array if a list was the first passed. For example, if A is a row Vector, then PowerSpectrum(A) will be a row Vector, and if Br is a Matrix, then PowerSpectrum(Br,Bi) will be a Matrix.
 • The value of window, when not passed as a list, should be the name or string, with or without the Window suffix, that corresponds to the windowing command. For example, to use a Hamming window, you can pass window=Hamming or window="HammingWindow". In both cases, the command SignalProcessing[HammingWindow] will be used internally. Similarly, you can pass window=["Exponential",0.5] or window=[ExponentialWindow,0.5] to use SignalProcessing[ExponentialWindow] with parameter value 0.5.
 • To apply a window to a Vector $V$ of length $n$, the window is first applied to another Vector $W$ of size $n$ and filled with ones, and then $V$ is multiplied element-wise by $W$. When windownormalization=true, $W$ is first normalized with respect to its Root Mean Square (RMS).
 • A window can only be applied when the input has one or two dimensions, and there is exactly one transform dimension.
 • To scale the power spectrum with the powerscale option, units which are dimensionally equivalent to the following are accepted:
 • 1: No further scaling is performed.
 • 1/Hz: The power spectrum is divided by $r=\mathrm{samplerate}$.
 • 1/rad/Hz: power spectrum is divided by $2\mathrm{\pi }r$.
 • dB: Each element $u$ of power spectrum is replaced with $10{\mathrm{Typesetting}:-\mathrm{_Hold}\left(\left[\mathrm{%log}\right]\right)}_{10}\left(u\right)$.
 • dB/Hz: Each element $u$ of power spectrum is replaced with $10{\mathrm{Typesetting}:-\mathrm{_Hold}\left(\left[\mathrm{%log}\right]\right)}_{10}\left(\frac{u}{r}\right)$.
 • dB/rad/Hz: Each element $u$ of power spectrum is replaced with $10{\mathrm{Typesetting}:-\mathrm{_Hold}\left(\left[\mathrm{%log}\right]\right)}_{10}\left(\frac{u}{2\mathrm{\pi }r}\right)$.
 • The frequencies and times Vectors can only be computed when there is exactly one transform dimension. If this is the case, the frequencies and times Vectors are of the same size as the transform dimension, say $n$, and have components defined by, respectively, ${F}_{i}=\frac{\left(i-1\right)r}{n}$ and ${T}_{i}=\frac{i-1}{r}$, where $r=\mathrm{samplerate}$.
 • The samplerate option can also include a unit of frequency. If a unit is provided, and it differs from frequencyunit, then the sample rate will be converted to use the same unit as frequencyunit.
 • A periodogram can only be created when the input has one or two dimensions, and there is exactly one transform dimension. In the two-dimensional case, the periodogram is a plot Array, with the separate pltos being the periodograms corresponding to the separate channels defined by the transform dimension.
 • If A or Br is an rtable of type AudioTools:-Audio and variety=signal, the sample rate is inferred from the attributes. Should samplerate also be passed, it will be overridden.
 • Before the code performing the computation runs, any input containers are converted to datatype complex[8] (for the calling sequence with A) or float[8] (for the calling sequence with Br and Bi) if they do not have this datatype already. For this reason, it is most efficient if input containers have this datatype beforehand.
 • The input rtables cannot have an indexing function, must use rectangular storage, and have the same order (C_order or Fortran_order).
 • If the container=C option is provided, then the results are stored in C and C is returned. With this option, no additional memory is allocated to store the result.
 • As the underlying implementation of the SignalProcessing package is a module, it is also possible to use the form SignalProcessing:-PowerSpectrum to access the command from the package. For more information, see Module Members.
 • The PowerSpectrum command is not thread safe.

Examples

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

Example 1

 > $a≔\mathrm{Array}\left(\left[1.+I,2.-3.I,4.,-1.I\right],'\mathrm{datatype}'='\mathrm{complex}'\left[8\right]\right)$
 $\left[\begin{array}{cccc}1.0+1.0{}I& 2.0-3.0{}I& 4.0+0.0{}I& 0.0-1.0{}I\end{array}\right]$ (1)
 > $\mathrm{PowerSpectrum}\left(a\right)$
 $\left[\begin{array}{cccc}2.0& 13.0& 16.0& 1.0\end{array}\right]$ (2)
 > $c≔\mathrm{Array}\left(1..\mathrm{numelems}\left(a\right),'\mathrm{datatype}'='\mathrm{float}'\left[8\right]\right):$
 > $\mathrm{PowerSpectrum}\left(a,'\mathrm{container}'=c\right)$
 $\left[\begin{array}{cccc}2.0& 13.0& 16.0& 1.0\end{array}\right]$ (3)
 > $c$
 $\left[\begin{array}{cccc}2.0& 13.0& 16.0& 1.0\end{array}\right]$ (4)

Example 2

 > $r≔\mathrm{Array}\left(\left[1.,2.,4.,0.\right],'\mathrm{datatype}'='\mathrm{float}'\left[8\right]\right)$
 $\left[\begin{array}{cccc}1.0& 2.0& 4.0& 0.0\end{array}\right]$ (5)
 > $i≔\mathrm{Array}\left(\left[1.,-3.,0.,-1.\right],'\mathrm{datatype}'='\mathrm{float}'\left[8\right]\right)$
 $\left[\begin{array}{cccc}1.0& -3.0& 0.0& -1.0\end{array}\right]$ (6)
 > $\mathrm{PowerSpectrum}\left(r,i\right)$
 $\left[\begin{array}{cccc}2.0& 13.0& 16.0& 1.0\end{array}\right]$ (7)
 > $\mathrm{PowerSpectrum}\left(r,i,'\mathrm{container}'=c\right)$
 $\left[\begin{array}{cccc}2.0& 13.0& 16.0& 1.0\end{array}\right]$ (8)
 > $c$
 $\left[\begin{array}{cccc}2.0& 13.0& 16.0& 1.0\end{array}\right]$ (9)

Example 3

 > $m≔\mathrm{Array}\left(1..2,1..2,\left[\left[1.+I,2.-I\right],\left[-3.+2.,-4.+2I\right]\right],'\mathrm{datatype}'='\mathrm{complex}'\left[8\right]\right)$
 $\left[\begin{array}{cc}1.0+1.0{}I& 2.0-1.0{}I\\ -1.0+0.0{}I& -4.0+2.0{}I\end{array}\right]$ (10)
 > $\mathrm{PowerSpectrum}\left(m\right)$
 $\left[\begin{array}{cc}2.0& 5.0\\ 1.0& 20.0\end{array}\right]$ (11)
 > $n≔\mathrm{Array}\left(1..2,1..2,'\mathrm{datatype}'='\mathrm{float}'\left[8\right]\right):$
 > $\mathrm{PowerSpectrum}\left(m,'\mathrm{container}'=n\right)$
 $\left[\begin{array}{cc}2.0& 5.0\\ 1.0& 20.0\end{array}\right]$ (12)
 > $n$
 $\left[\begin{array}{cc}2.0& 5.0\\ 1.0& 20.0\end{array}\right]$ (13)

Example 4

 • Consider the following signal:
 > $\mathrm{num_points}≔4096$
 ${\mathrm{num_points}}{≔}{4096}$ (14)
 > $\mathrm{sample_rate}≔\mathrm{evalhf}\left(\frac{\mathrm{num_points}-1}{2\mathrm{\pi }}\right)$
 ${\mathrm{sample_rate}}{≔}{651.739491961311387}$ (15)
 > $\mathrm{Times}≔\mathrm{Vector}\left(\mathrm{num_points},i↦\mathrm{evalhf}\left(\frac{i-1}{\mathrm{sample_rate}}\right),'\mathrm{datatype}'='\mathrm{float}\left[8\right]'\right)$
 ${{\mathrm{_rtable}}}_{{36893628626787217404}}$ (16)
 > $\mathrm{Signal}≔\mathrm{Vector}\left(\mathrm{num_points},i↦\mathrm{evalhf}\left(3\cdot \mathrm{sin}\left(200\cdot \mathrm{Times}\left[i\right]\right)-I\cdot \mathrm{cos}\left(500\cdot \mathrm{Times}\left[i\right]\right)\right),'\mathrm{datatype}'='\mathrm{complex}\left[8\right]'\right)$
 ${{\mathrm{_rtable}}}_{{36893628626787219204}}$ (17)
 • Now, apply a Hamming window to the signal, and return everything in a record:
 > $R≔\mathrm{PowerSpectrum}\left(\mathrm{Signal},'\mathrm{samplerate}'=\mathrm{sample_rate},'\mathrm{variety}'='\mathrm{signal}','\mathrm{window}'='\mathrm{Hamming}','\mathrm{powerscale}'='\frac{\mathrm{dB}}{\mathrm{Hz}}','\mathrm{output}'='\mathrm{record}'\right):$
 • Periodogram:
 > $R\left['\mathrm{periodogram}'\right]$

Example 5

 • The PowerSpectrum command can produce multiple periodograms from two-dimensional input. Here, each column represents separate channels:
 > $n≔1024$
 ${n}{≔}{1024}$ (18)
 > $a≔0$
 ${a}{≔}{0}$ (19)
 > $b≔2\mathrm{\pi }$
 ${b}{≔}{2}{}{\mathrm{\pi }}$ (20)
 > $\mathrm{fs}≔\mathrm{evalhf}\left(\frac{n-1}{b-a}\right)$
 ${\mathrm{fs}}{≔}{162.815506783008942}$ (21)
 > $T≔\mathrm{Vector}\left['\mathrm{column}'\right]\left(n,i↦\mathrm{evalhf}\left(\frac{i-1}{\mathrm{fs}}\right),'\mathrm{datatype}'='\mathrm{float}\left[8\right]'\right)$
 ${{\mathrm{_rtable}}}_{{36893628626787212812}}$ (22)
 > $A≔⟨\mathrm{Vector}\left['\mathrm{column}'\right]\left(n,i↦\mathrm{sin}\left(100\cdot T\left[i\right]\right),'\mathrm{datatype}'='\mathrm{float}\left[8\right]'\right)|\mathrm{Vector}\left['\mathrm{column}'\right]\left(n,i↦\mathrm{cos}\left(2000\cdot T\left[i\right]\right),'\mathrm{datatype}'='\mathrm{float}\left[8\right]'\right)⟩$
 ${{\mathrm{_rtable}}}_{{36893628626787206676}}$ (23)
 > $\mathrm{PowerSpectrum}\left(A,'\mathrm{samplerate}'=\mathrm{fs},'\mathrm{variety}'='\mathrm{signal}','\mathrm{dimension}'=1,'\mathrm{output}'='\mathrm{periodogram}','\mathrm{powerscale}'='\frac{\mathrm{dB}}{\mathrm{Hz}}'\right)$

 > 

Compatibility

 • The SignalProcessing[PowerSpectrum] command was introduced in Maple 17.
 • For more information on Maple 17 changes, see Updates in Maple 17.
 • The SignalProcessing[PowerSpectrum] command was updated in Maple 2021.