compute the power spectrum of an array of samples
PowerSpectrum( A, options )
PowerSpectrum( Br, Bi, options )
rtable or list of numeric values for the signal or spectrum
rtable or list of numeric values for the real parts of the signal or spectrum
rtable or list of numeric values for the imaginary parts of the signal or spectrum
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.
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:
Apply a window, if any, to the signal.
Compute the DFT of the windowed signal.
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=samplerate.
1/rad/Hz: power spectrum is divided by 2⁢π⁢r.
dB: Each element u of power spectrum is replaced with 10⁢Typesetting:-_Hold⁡%log10⁡u.
dB/Hz: Each element u of power spectrum is replaced with 10⁢Typesetting:-_Hold⁡%log10⁡ur.
dB/rad/Hz: Each element u of power spectrum is replaced with 10⁢Typesetting:-_Hold⁡%log10⁡u2⁢π⁢r.
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, Fi=i−1⁢rn and Ti=i−1r, where r=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.
a ≔ Array⁡1.+I,2.−3.⁢I,4.,−1.⁢I,'datatype'='complex'8
c ≔ Array⁡1..numelems⁡a,'datatype'='float'8:
r ≔ Array⁡1.,2.,4.,0.,'datatype'='float'8
i ≔ Array⁡1.,−3.,0.,−1.,'datatype'='float'8
m ≔ Array⁡1..2,1..2,1.+I,2.−I,−3.+2.,−4.+2⁢I,'datatype'='complex'8
n ≔ Array⁡1..2,1..2,'datatype'='float'8:
Consider the following signal:
Signal,sample_rate ≔ GenerateSignal⁡3⁢sin⁡200⁢t−I⁢cos⁡500⁢t,t=0..2⁢Pi,4096,'output'='signal','samplerate'
Now, apply a Hamming window to the signal, and return everything in a record:
R ≔ PowerSpectrum⁡Signal,'samplerate'=sample_rate,'variety'='signal','window'='Hamming','powerscale'='dBHz','output'='record':
The PowerSpectrum command can produce multiple periodograms from two-dimensional input. Here, each column of Matrix A represents separate channels:
n ≔ 1024
a ≔ 0
b ≔ 2⁢Pi
X,fs ≔ GenerateSignal⁡sin⁡100⁢t,t=a..b,n,'output'='signal','samplerate'
Y ≔ GenerateSignal⁡cos⁡2000⁢t,t=a..b,n,'output'='signal'
A ≔ X|Y
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.
Download Help Document