next up previous contents
Next: Blackman-Tukey method Up: Introduction to power spectral Previous: other links   Contents

Sample matlab code for periodogram

It helped my understanding to actually write my own periodogram PSD estimation function for Matlab. Matlab's built in function has too many options and details that obscure the concepts.

function [x, p] = genPSD( signal, NumDataPoints, ScanRate, window_fun)
halfn = floor(NumDataPoints / 2)+1;
deltaf = 1 / ( NumDataPoints / ScanRate);
%do the actual work
z = fft(signal .* feval(window_fun, NumDataPoints) , NumDataPoints);
%compensate for the norm of the window
z = z' * (NumDataPoints / norm(feval(window_fun,NumDataPoints),1)); 
%generate the vector of frequencies
xfreq = (0:(halfn-1)) * deltaf;
x = xfreq';
%generate PSD
psd = abs(z ./ NumDataPoints) .^ 2 / deltaf;
% convert from 2 sided spectrum to one sided spectrum (assuming that the input is a real signal)
p(1) = psd(1) ;
p(2:(halfn-1)) = psd(2:(halfn-1)) * 2;
p(halfn) = psd(halfn) ;



" . $row['Name'] . " Posted on " . $row['DateTime']; echo "
"; echo $row['Comment']; echo "

"; } echo "
"; ?> Leave a comment on this page:

Name: (optional)
To prove you are not a robot, what is 2+3?

Creative Commons License
This work by Daniel Kiracofe (daniel dot kiracofe at gmail dot com) is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License./' $I