Path: news.mathworks.com!not-for-mail
From: "Honglei Chen" <hchen@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: pwelch PSD estimator syntax, please someone?
Date: Fri, 26 Oct 2007 18:23:08 -0400
Organization: The MathWorks, Inc.
Lines: 113
Message-ID: <fftpce$ch$1@fred.mathworks.com>
References: <1193355397.539932.8230@57g2000hsv.googlegroups.com>
Reply-To: "Honglei Chen" <hchen@mathworks.com>
NNTP-Posting-Host: chenh.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1193437390 401 144.212.109.36 (26 Oct 2007 22:23:10 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 26 Oct 2007 22:23:10 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198
Xref: news.mathworks.com comp.soft-sys.matlab:434829



Hi Mario,



In general, if you use 8 segments to estimate the spectrum in a 1024 sample 
data series without overlap, each segment's length is



P = 1024/8 = 128.



However, when you allow Welch's method to calculate the spectrum using 
overlapped data segments, each segment can be longer.  Essentially, with an 
overlap of 50%, there will be 9 ½-length segments to divide the entire 
series. Therefore, the length of each data segment, P, becomes



P = 1024/(9*0.5) = 227.



This also leads to the fact that the number of overlap points, M, is given 
by 113 instead of 64.



So, as you observed, pwelch(x,[],[],[],4) is actually the same as 
pwelch(x,227,113,25,4).



Hope this helps,



Honglei



<Dutchice@gmail.com> wrote in message 
news:1193355397.539932.8230@57g2000hsv.googlegroups.com...
> Hi all!
>
> I sometimes feel MATLAB Help documentation really comes examples
> short! :(
>
> My question is the following;
> I know that the pwelch estimator syntax for a discrete time series
> vector x is as follows:
> [Pxx,f] = pwelch(x,window,noverlap,nfft,fs)
> and that when written as:
> [Pxx,f] = pwelch(x,[],[],[],fs)
> MATLAB will let for:
> window: hamming(P)
> noverlap: M
> nfft: N
> fs: Fs
> where the defaults are:
> P: number of samples needed to cut the record sample length into 8
> segments
> M: number of samples overlapping between two adjacent segments in
> order to overlap 50%
> N: 256
> fs: 1 (sampling rate in hertz)
>
> For my case, vector x has the following characteristics:
> Sample record lenght: 1024 samples
> sampling rate: 4 Hz
> Sample input type: Real-valued
>
> So this means that with the following syntax:
> [Pxx,f] = pwelch(x,[],[],[],4)
> MATLAB should compute:
> P = 1024/8 = 128
> M = 128*0.5 = 64
> N = 256
> fs = 4
>
> Now would someone be able to explain please, how come when plotting as
> follows;
> [Pxx1,f1] = pwelch(x,[],[],[],4)
> [Pxx2,f2] = pwelch(x,hamming(128),64,256,4)
> loglog(f1,Pxx1,'b',f2,Pxx2,'r')
>
> or also;
>
> pwelch(x,[],[],[],4)
> figure
> pwelch(x,hamming(128),64,256,4)
>
> the two plots JUST don't fall on each other neatly as if there was
> only one plot!? :|
> Very very curiously enough they do match perfect, one on other when;
>
> [Pxx1,f1] = pwelch(x,[],[],[],4)
> [Pxx2,f2] = pwelch(x,hamming(227),113,256,4)
> loglog(f1,Pxx1,'b',f2,Pxx2,'r')
>
> Can someone please explain why? (scaling of the two Pxx1 & Pxx2 to
> match the variance of x didn't and shouldn't either make any
> difference)
> Download link for vector x is here: 
> http://rapidshare.com/files/65194703/OceanWaveData.dat.html
>
> Cheers,
>
> Mario
>