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

Online Help

All Products    Maple    MapleSim


SignalProcessing

  

PowerSpectrum

  

compute the power spectrum of an array of samples

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

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[8] 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[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] 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 10log10u.

• 

dB/Hz: Each element u of power spectrum is replaced with 10log10ur.

• 

dB/rad/Hz: Each element u of power spectrum is replaced with 10log10u2π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=i1rn and Ti=i1r, 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[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.

• 

The PowerSpectrum command is not thread safe.

Examples

withSignalProcessing:

Example 1

aArray1.+I,2.3.I,4.,1.I,datatype=complex8

a

(1)

PowerSpectruma

(2)

cArray1..numelemsa,datatype=float8:

PowerSpectruma,container=c

(3)

c

(4)

Example 2

rArray1.,2.,4.,0.,datatype=float8

r

(5)

iArray1.,3.,0.,1.,datatype=float8

i

(6)

PowerSpectrumr,i

(7)

PowerSpectrumr,i,container=c

(8)

c

(9)

Example 3

mArray1..2,1..2,1.+I,2.I,3.+2.,4.+2I,datatype=complex8

m

(10)

PowerSpectrumm

(11)

nArray1..2,1..2,datatype=float8:

PowerSpectrumm,container=n

(12)

n

(13)

Example 4

• 

Consider the following signal:

Signal,sample_rateGenerateSignal3sin200tIcos500t,t=0..2π,4096,output=signal,samplerate

• 

Now, apply a Hamming window to the signal, and return everything in a record:

RPowerSpectrumSignal,samplerate=sample_rate,variety=signal,window=Hamming,powerscale=dBHz,output=record:

• 

Periodogram:

Rperiodogram

Example 5

• 

The PowerSpectrum command can produce multiple periodograms from two-dimensional input. Here, each column of Matrix A represents separate channels:

n1024

n1024

(14)

a0

a0

(15)

b2π

b2π

(16)

X,fsGenerateSignalsin100t,t=a..b,n,output=signal,samplerate

YGenerateSignalcos2000t,t=a..b,n,output=signal

AX|Y

PowerSpectrumA,samplerate=fs,variety=signal,dimension=1,output=periodogram,powerscale=dBHz

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.

See Also

SignalProcessing

SignalProcessing[BandPower]

SignalProcessing[Magnitude]

SignalProcessing[MeanFrequency]

SignalProcessing[MUSIC]

SignalProcessing[Periodogram]

SignalProcessing[SpectralEntropy]

SignalProcessing[Welch]