DSPRelated.com
Forums

More on the spectrum

Started by Sergio Dominguez May 1, 2003
Hi everyone.

I got some more questions on the power spectrum. Basically, I have done my own
function (nothing very sofisticated) which detrends the signal, gets the number
of integer segments you can apply depending on the length of the fft window you
want to apply (passed as an argument), divides the input signal, window it with
a hanning window, multiplies the fft by its conjugate, overlaps with half the
nfft, averages and divides by the frecuency (i put the code below,
reeeeeeeally simple code).

The point is that now I have to find the percentage of the energy concentrated
below a determinate spectral peak. But I cannot integrate directly, cause the
signal is windowed (and maybe too because it is overlaped?, I am not pretty sure
of this last one).

So my question is, how you find the energy contained in that signal between 2
frecuencies so as to account for the windowing?? Does it really affect or
provided it is just some kind of "softening" of the signal to make believe the
fft that it is infinite I should not take it into account and I can integrate
directly.

Something else, what happens with the detrending and the mean square value that
we are lossing when I integrate? Shall I add it in both terms when calculating
the percentage of the energy containted between 2 frecuencies with respect to
the total energy?

Thank you very much for you answers. And if you have some references to papers
well the integration of the spectrum is well explained... well, I have not found
any,I guess it is too basic.

Cheers,

Sergio

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Code (without the argument checking and stuff):

function varargout = psds(x,nfft,Fs)

x = x(:);
xrend(x);
L = length(x);

win=hanning(nfft);

noverlap = nfft/2;

% Compute the number of segments
k = (L-noverlap)/(nfft-noverlap);
k = floor(k);
% Compute the periodogram power spectrum of each segment and average
% always compute the twosided power spectrum, we force Fs = 1 to get
% a spectrum not a spectral density

Sxx = zeros(nfft,1); % Initialize

xindx = 1;

for i = 1:k,
Sxx = Sxx + abs( fft( x(xindx:xindx+nfft-1).*win,nfft)/nfft).^2;
xindx = xindx + noverlap;
end

Sxx = Sxx/k; % Average the sum of the periodograms

% Generate the frequency vector in [rad/sample] at which Sxx was computed
w = (0:nfft-1)*Fs/nfft;

Sxx=Sxx./Fs;

varargout = {Sxx,w};