Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Fast numerical estimation of the power spectral density or the cross spectral density
ResourceFunction["WelchSpectralEstimate"][data,rate] estimates the data power spectral density at a given rate. | |
ResourceFunction["WelchSpectralEstimate"][data1,data2,rate] estimates the data cross spectral density at a given rate. |
"SegmentSize" | Automatic | the number of datapoints to use in a Fourier transform |
"OverlapOffset" | Automatic | the offset between segments to average or a fraction of the possible offset (defaults to half of the "SegmentSize") |
FourierParameters | {0,1} | Fourier convention parameters |
"Window" | Automatic | the spectral window to apply to the data (if appropriate, the HannWindow will be chosen) |
"OneSided" | True | True to evaluate only the first half of the Fourier transform, otherwise False for evaluating the whole range |
"Reduction" | Mean | the function to average the segments together |
"DensityScaling" | True | True for scaling as a density, False for spectrogram scaling |
"Detrend" | "Constant" | the level of detrending to apply to the data segments, before transformation |
Calculate the spectral density of a random data sample:
In[1]:= |
Out[2]= |
Evaluate the Cross Spectral Density (CSD) of two sinusoidal, noisy datasets and display amplitude and phase:
In[3]:= |
Out[6]= |
Compare the influence of different spectral windows on the PSD:
In[7]:= |
Out[9]= |
"SegmentSize" sets number of data points from which to calculate the Fourier transform; smaller numbers means more averaging but lower resolution:
In[10]:= |
Out[11]= |
"OverlapOffset" allows to set the distance of the starting point between two partitioned segments; a smaller integer number means closer overlaps and thus more averaging:
In[12]:= |
Out[13]= |
"OverlapOffset" also allows the specification of an overlap fraction of the number of data points minus the segment size, as a real number between zero and one:
In[14]:= |
Out[15]= |
Set the FourierParameters option for the respective Fourier transforms:
In[16]:= |
Out[17]= |
Use the "Window" option to specify windowing functions:
In[18]:= |
Out[19]= |
A list can be applied as the window function, provided the length is equal to its segment size:
In[20]:= |
Out[23]= |
Set a custom function as the window:
In[24]:= |
Out[25]= |
The "Detrend" option can be used to detrend the initial data segments before transformations occur. The option can be specified with string arguments for constant or linear detrends:
In[32]:= |
Out[33]= |
A list of integers can be specified instead which polynomial orders should be detrended:
In[34]:= |
Out[35]= |
Investigate the frequency response on white noise data for different kind of filters:
In[36]:= |
Out[40]= |
Estimate the system transfer function of a set state and its measured response:
In[41]:= |
Out[48]= |
Even for complex input, the "OneSided" option will still remain True by default and thus return only the front of the Fourier transform:
In[49]:= |
Out[49]= |
Estimate the uncertainty of the Fourier deviations by just choosing a different reduction function:
In[50]:= |
Out[51]= |
This work is licensed under a Creative Commons Attribution 4.0 International License