DSPRelated.com
Forums

Power Spectral density

Started by khmaies November 4, 2005
Dear All,
I am strugling writing a matlab code to present the PSD of a random
sequence of data.
I am not getting a smooth curve like I see it in some textbooks. Could
anyone help me with Matlab code where I can get the PSD graph which look
like a continues curve.
Thans a lot
Regards
khmaies
khmaies wrote:
> Dear All, > I am strugling writing a matlab code to present the PSD of a random > sequence of data. > I am not getting a smooth curve like I see it in some textbooks. Could > anyone help me with Matlab code where I can get the PSD graph which look > like a continues curve. > Thans a lot > Regards > khmaies
How much averaging are you doing?
"khmaies" <khmaies@gmail.com> wrote in message
news:xemdnf_pfeOyOfbenZ2dnUVZ_s2dnZ2d@giganews.com...
> > Dear All, > I am strugling writing a matlab code to present the PSD of a random > sequence of data. > I am not getting a smooth curve like I see it in some textbooks. Could > anyone help me with Matlab code where I can get the PSD graph which look > like a continues curve. > Thans a lot > Regards > khmaies
You won't get a smooth curve - even if you average unless the statistics are stationary. You can average like this P(i)=beta*P(i-1)+(1-beta)XX^ where ^ is complex conjugate of the freq vector X and beta is a forgetting factor. P is the periodogram or Spectral Density estimate at FFT frame i=1,2,3... McC
clc
close all
clear

% number of samples
N=1000;
% create data with filter
num=1;
den=[1 -0.5 0.2]
x=filter(num,den,randn(1,N));
% do LPC analysis to estimate inverse filter
[den_hat,num_hat]=lpc(x,2);
den_hat=real(den_hat);
num_hat=sqrt(num_hat);
% calculate non-parametric power spectrum
Sxx=abs(fft(x,2*N)./(2*N)).^2;
% calculate parametric power spectrum
Sxx_parametric=(abs(fft(impz(num_hat,den_hat,2*N))).^2)./(2*N);
% plot results
plot(Sxx);
hold;
plot(Sxx_parametric,'ro');
hold;






"khmaies" <khmaies@gmail.com> skrev i en meddelelse 
news:xemdnf_pfeOyOfbenZ2dnUVZ_s2dnZ2d@giganews.com...
> > Dear All, > I am strugling writing a matlab code to present the PSD of a random > sequence of data. > I am not getting a smooth curve like I see it in some textbooks. Could > anyone help me with Matlab code where I can get the PSD graph which look > like a continues curve. > Thans a lot > Regards > khmaies
>clc >close all >clear > >% number of samples >N=1000; >% create data with filter >num=1; >den=[1 -0.5 0.2] >x=filter(num,den,randn(1,N)); >% do LPC analysis to estimate inverse filter >[den_hat,num_hat]=lpc(x,2); >den_hat=real(den_hat); >num_hat=sqrt(num_hat); >% calculate non-parametric power spectrum >Sxx=abs(fft(x,2*N)./(2*N)).^2; >% calculate parametric power spectrum >Sxx_parametric=(abs(fft(impz(num_hat,den_hat,2*N))).^2)./(2*N);
Fourier transform of a random process is another random process :) what you need to do is perform the above several dozen times (at least) and then average the resulting FFTs - only then will you see the smoothness start to appear.
> Fourier transform of a random process is another random process :) > > what you need to do is perform the above several dozen times (at least) > and then average the resulting FFTs - only then will you see the > smoothness start to appear.
Yes, but LPC-analysis will give you a smooth approximation of the non-parametric power spectrum...
Lars Hansen wrote:
>>Fourier transform of a random process is another random process :) >> >>what you need to do is perform the above several dozen times (at least) >>and then average the resulting FFTs - only then will you see the >>smoothness start to appear. > > > > Yes, but LPC-analysis will give you a smooth approximation of the > non-parametric power spectrum... > > >
Are you saying that you don't need to average? There are lots of ways to smooth but they aren't necessarily accurate.
"Stan Pawlukiewicz" <spam@spam.mitre.org> wrote in message
news:dkiffa$ic7$1@newslocal.mitre.org...
> Lars Hansen wrote: > >>Fourier transform of a random process is another random process :) > >> > >>what you need to do is perform the above several dozen times (at least) > >>and then average the resulting FFTs - only then will you see the > >>smoothness start to appear. > > > > > > > > Yes, but LPC-analysis will give you a smooth approximation of the > > non-parametric power spectrum... > > > > > > > Are you saying that you don't need to average? > > There are lots of ways to smooth but they aren't necessarily accurate. >
Not if you use parametric methods. LPC is not so good at measuring zeros since it is an all-pole method. There are pole-zero techniques which require more computation. McC
>> > Not if you use parametric methods. LPC is not so good at measuring zeros > since it is an all-pole method. There are pole-zero techniques which > require > more computation. > > McC >
That's true, but you can just increase the order of the LPC-analysis to model the zeros... - but you are right...pole-zero techniques are probably more efficient
khmaies wrote:
> I am strugling writing a matlab code to present the PSD of a random > sequence of data. > I am not getting a smooth curve like I see it in some textbooks. Could > anyone help me with Matlab code where I can get the PSD graph which look > like a continues curve.
Try Rainbow ... http://digitalCalculus.com/page/593045 ... it has some 10+ algorithms for a PSD and these vary like crazy in their results. Finding key peak (i.e. frequencies) is hard in itself. Good luck hunting. Phil