attenuates the effect of noise on a signal and estimates the power spectrum
Welch( signal, options )
1-D rtable or list of data
overlapsize: Non-negative integer which specifies the target minimum overlap size of the segments. The default is 0.
samplerate: Positive numeric value for the sampling rate. The default is 1.0.
segmentsize: Positive integer for the size of the overlapping segments. The default is the largest power of 2 that is not larger than the size of signal.
fftnormalization: One of none, symmetric, or full, indicates the normalization to be applied when using the Fast Fourier Transform (FFT). The default is symmetric.
temperendpoints: Either true or false, specifies whether the power spectrum is to be tempered at the endpoints. The default is false.
window: Either a list, name, or string, specifies the windowing command to be applied to the overlapping segments. 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.
frequencyunit: Unit which specifies the unit of frequency for the periodogram. 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.
datapowerscale: Unit which indicates the scaling, if any, to be applied to the power spectrum Vector. 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/Hz).
plotpowerscale: Unit which indicates the scaling, if any, to be applied to the power spectrum in the periodogram. 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(dB/rad/Hz).
periodogramoptions: Additional plot options to be passed when creating the periodogram. The default is .
output: The type of output. The supported options are:
frequencies: Returns a Vector, of float datatype and length the same as signal, containing the frequencies.
power: Returns a Vector of float datatype containing the power spectrum. This is the default.
periodogram: Returns a periodogram which displays the power spectrum versus the frequencies.
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 Welch command takes a 1-D rtable or list signal, and applies Welch's Method to attenuate the effect of noise on the signal, at the expense of frequency resolution, and estimate the power spectrum.
The power spectrum is estimated using the following steps:
Divide the signal into segments of equal size with equal or nearly equal overlaps.
Apply the windowing procedure to each segment.
Take the Discrete Fourier Transform (DFT) of each windowed segment.
Compute the power spectra of each transformed segment.
Compute the estimated overall power spectrum, by averaging the segment power spectra, and scaling the average based on the windowing function and number of segments. Note: The Matrix of all the segment DFTs is known as a Short-Time Fourier Transform (STFT).
The values of a=overlapsize, b=segmentsize, and n=numelems⁡signal must satisfy 2≤n, 0≤a, 2≤b, a<b, and b≤n.
Since the DFT will be computed for each segment, it is suggested that, for larger signal lengths, segmentsize be a power of 2 and no less than 4, so that the FFT will be utilized.
The passed value of overlapsize is used to determine the number c of overlapping segments of size b=segmentsize. The values of b and c determine the smallest possible overlap size p and the excess number q of overlaps of size p+1. If we denote n=numelems⁡signal, then bc=n+p⁢c−1−q+p+1⁢q for the 1<c case. When c=1, there are no overlaps and the power spectrum is computed directly from the original signal.
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 power spectrum Vector is determined element-wise from a DFT Vector by squaring the absolute values of each component. When the DFT originated from a real-valued signal, the second half of elements of the power spectrum are discarded (due to symmetry), and the remaining elements of the power spectrum are doubled in value. To scale a power spectrum with the datapowerscale and plotpowerscale options, 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: The power spectrum is divided by 2⁢π⁢r.
dB: Each element u of the power spectrum is replaced with 10⁢Typesetting:-_Hold⁡%log10⁡u.
dB/Hz: Each element u of the power spectrum is replaced with 10⁢Typesetting:-_Hold⁡%log10⁡ur.
dB/rad/Hz: Each element u of the power spectrum is replaced with 10⁢Typesetting:-_Hold⁡%log10⁡u2⁢π⁢r.
The frequencies Vector has components defined by Fi=i−1⁢rb, where b=segmentsize and r=samplerate. If signal is complex-valued, then both the power spectrum Vector P and F have size b. When signal is real-valued, on the other hand, P and F will both have size m=b2+1.
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.
If frequencyunit is different than Unit(Hz), then the labels of the periodogram will use frequencyunit rather than Unit(Hz).
When temperendpoints=true, the endpoints of the overall power spectrum, determined by the method described above, are halved.
If signal is an rtable of type AudioTools:-Audio, the sample rate is inferred from the attributes. Should samplerate also be passed, it will be overridden.
Maple will attempt to coerce the provided signal to a 1-D Vector of either float or complex datatype, and an error will be thrown if this is not possible. For this reason, it is most efficient for the passed input to use this datatype.
The input signal cannot have an indexing function, and must use rectangular storage.
The Welch command is not thread safe.
First, define the number of points, start and end times, sample rate, and standard deviation for white noise:
n ≔ 8192
a ≔ 0
b ≔ 2⁢Pi
r ≔ evalf⁡n−1b−a
σ ≔ 2.0
Second, create Vectors for the times, pure signal, and noisy signal:
g ≔ cos⁡10⁢Pi⁢t+3⁢cos⁡20⁢Pi⁢t+2⁢cos⁡60⁢Pi⁢t
T,X ≔ GenerateSignal⁡g,t=a..b,n,output=times,signal
Y ≔ GenerateSignal⁡g,t=a..b,n,noisetype=additive,noisedeviation=σ,output=signal
Now, let's compare plots of the signals and power spectra:
plots:-display⁡Array⁡dataplot⁡T,X,style=line,view=0..2⁢Pi,−40..40,title=Original Signal,dataplot⁡T,Y,style=line,view=0..2⁢Pi,−40..40,title=Noisy Signal
plots:-display⁡Array⁡Welch⁡X,samplerate=r,segmentsize=n,output=periodogram,periodogramoptions=title=Periodogram of Original Signal,Welch⁡Y,samplerate=r,segmentsize=n,output=periodogram,periodogramoptions=title=Periodogram of Noisy Signal
Finally, apply Welch's Method with a choice of parameter values, and return the periodogram:
Consider the following complex-valued signal:
sample_rate ≔ 5000
num_points ≔ 5001
generator ≔ t→5⁢cos⁡1000⁢Pi⁢t−3⁢I⁢sin⁡2000⁢Pi⁢t
Times,Signal ≔ GenerateSignal⁡generator,sample_rate,num_points,output=times,signal
Here, we will produce a table of possible Welch periodograms using the available scalings:
Scales ≔ 1,1Hz,1rad⁢Hz,dB,dBHz,dBrad⁢Hz
Periodograms ≔ seq⁡Welch⁡Signal,samplerate=sample_rate,segmentsize=64,overlapsize=32,plotpowerscale=scale,output=periodogram,scale=Scales:
The Welch command can also be used to find the power spectrum without attenuation or overlapping segments, by choosing the segment size to be equal to the signal size:
The SignalProcessing[Welch] command was introduced in Maple 2021.
For more information on Maple 2021 changes, see Updates in Maple 2021.
Download Help Document
What kind of issue would you like to report? (Optional)