Page 1 of 1

Using Pwelch to determine power spectral density in MATLAB

Posted: Wed May 29, 2024 12:06 pm
by amh
1.Using Welch's overlapped segment averaging estimator.
Notes:
  • When x is a vector, it is treated as a single channel. When x is a matrix, the PSD is computed independently for each column and stored in the corresponding column of pxx.
  • If x is real-valued, pxx is a one-sided PSD estimate. If x is complex-valued, pxx is a two-sided PSD estimate.
  • By default, x is divided into the longest possible segments to obtain as close to but not exceed 8 segments with 50% overlap.
  • Each segment is windowed with a Hamming window.
  • The modified periodograms are averaged to obtain the PSD estimate. If you cannot divide the length of x exactly into an integer number of segments with 50% overlap, x is truncated accordingly.

Code: Select all

[pxx,f]= pwelch(x)

2. Uses the input vector or integer, window, to divide the signal into segments
Notes;
  • If window is a vector, pwelch divides the signal into segments equal in length to the length of window.
  • The modified periodograms are computed using the signal segments multiplied by the vector, window.
  • If window is an integer, the signal is divided into segments of length window.
  • The modified periodograms are computed using a Hamming window of length window.

Code: Select all

pxx = pwelch(x,window)
3. Uses noverlap samples of overlap from segment to segment.

Rules:
  • noverlap must be a positive integer smaller than window if window is an integer.
  • noverlap must be a positive integer less than the length of window if window is a vector.
  • If you do not specify noverlap, or specify noverlap as empty, the default number of overlapped samples is 50% of the window length.

Code: Select all

pxx = pwelch(x,window,noverlap)
4. Specifies the number of discrete Fourier transform (DFT) points to use in the PSD estimate.
Note:
The default nfft is the greater of 256 or the next power of 2 greater than the length of the segments.

Code: Select all

pxx = pwelch(x,window,noverlap,nfft)

What is nfft?

Posted: Thu May 30, 2024 6:03 am
by amh
  • NFFT is one of the abbreviations used for Non-Uniform Fast Fourier Transform
  • NFFT can be any positive value, but FFT computations are typically much more efficient when the number of samples can be factored into small primes.
The execution time for fft depends on the length of the transform. It is fastest for powers of two. It is almost as fast for lengths that have only small prime factors. It is typically several times slower for lengths that are prime or which have large prime factors.
It is thus common to compute the FFT for the power of 2 which is greater or equal to the number of samples of the signal y. This is what NFFT = 2^nextpow2(L) does (in the Example from Matlab documentation y is constructed to have a length L). When NFFT > L the signal is zero padded to the NFFT length.
nfft = min 256 / 2^nextpow2(L)
Sources:

- MATLAB Documentation
-https://stackoverflow.com/questions/294 ... -in-matlab