welchpsd#

[f, Sxx] = welchpsd(x, fs, SegmentSize, OverlapSize, WindowName, nfft, OutputSmoothSize, dispout)

Description#

Calculate power spectral density using Welch’s method

Inputs#

x

Input data

fs=2;

Sampling frequency that data collected at in (Hz)

SegmentSize=256;

Segment size, data are divided into the segments each has a total element equal to SegmentSize

OverlapSize=0;
Number of data points that are overlaped with data in previous segments
OverlapSize is recomneded to be half of the SegmentSize
WindowName=’hamming’;
Window name, define if multiplying input data by window function or not (‘none’: not multiplying)
‘none’,’rectangular’,’triangular’,’welch’,’hanning’,’hamming’,’gaussian’,’blackman’,’nuttall’,’blackmanharris’
nfft=length(x);

Total number of points between 0 and fs that spectrum reports at is (nfft+1)

OutputSmoothSize=0;
Window size for smoothing calculated spectrum (0, 1 or 2: not smoothing, reports original periodogram)
If WindowName=’none’ and OutputSmoothSize>2, then WindowName=’hamming’
dispout=’no’;

Define to display outputs or not (‘yes’: display, ‘no’: not display)

Outputs#

f

Frequency in (Hz)

Sxx

Power spectral density using Welch’s method (m^2/Hz)

Examples#

x(:,1)=detrend(0.5.*cos(2*pi*0.2*linspace(0,1023.5,2048))+(-0.1+(0.1-(-0.1))).*rand(1,1024*2));
[f,Sxx]=welchpsd(x,2,256,128,'hamming',2048,0,'yes');

References#

Welch, P. (1967). The use of fast Fourier transform for the estimation of power spectra: a method based on time averaging over short, modified periodograms. IEEE Transactions on audio and electroacoustics, 15(2), 70-73.