 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: Predefined rtable of float datatype having the same dimensions as the input rtable(s) to store the power spectrum.
 • dimension: 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: One of none, symmetric, or full, indicates the normalization to be applied when using the DFT. The default is symmetric.
 • frequencyunit: 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: List of additional plot options to be passed when creating the periodogram. The default is [].
 • powerscale: 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: Positive numeric value for the sampling rate. The default is 1.0.
 • temperendpoints: Either true or false, specifies whether the power spectrum is to be tempered at the endpoints. The default is false.
 • timeunit: 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: Either signal or fft, specifies if the data passed is a signal or the DFT of a signal. The default is fft.
 • 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. The default is true.
 • output: periodogram': Returns a periodogram which displays the power spectrum versus the frequencies.
 – power: Returns an rtable of float datatype containing the power spectrum. This is the default.
 – times: Returns a Vector of float 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 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.
 • 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] is 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}}_{10}\right]\right)\left(u\right)$.
 • dB/Hz: Each element $u$ of power spectrum is replaced with $10\mathrm{Typesetting}:-\mathrm{_Hold}\left(\left[{\mathrm{%log}}_{10}\right]\right)\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}}_{10}\right]\right)\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 plots 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 (for the calling sequence with A) or float (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.
 • 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}'}_{8}\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}'}_{8}\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}'}_{8}\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}'}_{8}\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}'}_{8}\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}'}_{8}\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{Signal},\mathrm{sample_rate}≔\mathrm{GenerateSignal}\left(3\mathrm{sin}\left(200t\right)-I\mathrm{cos}\left(500t\right),t=0..2\mathrm{Pi},4096,'\mathrm{output}'=\left['\mathrm{signal}','\mathrm{samplerate}'\right]\right)$ • 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}_{'\mathrm{periodogram}'}$  Example 5

 • The PowerSpectrum command can produce multiple periodograms from two-dimensional input. Here, each column of Matrix A represents separate channels:
 > $n≔1024$
 ${n}{≔}{1024}$ (14)
 > $a≔0$
 ${a}{≔}{0}$ (15)
 > $b≔2\mathrm{Pi}$
 ${b}{≔}{2}{}{\mathrm{\pi }}$ (16)
 > $X,\mathrm{fs}≔\mathrm{GenerateSignal}\left(\mathrm{sin}\left(100t\right),t=a..b,n,'\mathrm{output}'=\left['\mathrm{signal}','\mathrm{samplerate}'\right]\right)$ > $Y≔\mathrm{GenerateSignal}\left(\mathrm{cos}\left(2000t\right),t=a..b,n,'\mathrm{output}'='\mathrm{signal}'\right)$ > $A≔⟨X|Y⟩$ > $\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.