From: EUIX Wang on
"Wayne King" <wmkingty(a)gmail.com> wrote in message <hnbp8s$23t$1(a)fred.mathworks.com>...
> "EUIX Wang" <kuhanw(a)gmail.com> wrote in message <hnbksd$jcv$1(a)fred.mathworks.com>...
> > When using the periodogram function matlab states in its help file that
> >
> > "periodogram uses an nfft-point FFT of the windowed data (x.*window) to compute the periodogram. If the value you specify for nfft is less than the length of x, then x.*window is wrapped modulo nfft. If the value you specify for nfft is greater than the length of x, then x.*window is zero-padded to compute the FFT."
> >
> > Now what exactly does the first part mean? I understand how zero padding works what is wrapped modulo?
> >
> > Also does this work if your value of nfft is not a integer multiple of your number of data points? For example if I have 1000 data points and I pick nfft=210. Then does matlab zero pad the data with 50 extra zeros when executing periodogram?
>
> Hi, what it means is that it divides the data into nonoverlapping segments of length NFFT, possibly padding the last one with zeros if a case like you describe holds. Then it stacks those segments and adds them together to form a length NFFT segment. So for example:
>
> X=1:20;
> NFFT=10;
> Y = buffer(X,NFFT);
> Y=sum(Y,2);
>
> Hope that helps,
> Wayne


Hey thanks for the reply but I think I am still missing something. Tell me if I am understanding this correctly. If for example I have a dataset of 1000 points and using nfft=210. Is matlab using datawrap on the 1000 points, thus creating 210 points and then applying the periodogram function to that 210 point dataset (that is periodogram(data210,[],210,Fs))?

Because I tried that and compared it to taking the periodogram directly (periodogram(data1000,[],210,Fs)) and while the shape seems to be the same the two data sets seem to differ by some factor. I am posting this pretty late but perhaps it has to do some with the sampling frequency Fs?
From: EUIX Wang on
I did a little bit of tinker and I think the factor is N/nfft, where N is the total number of points. I say I think because the exact decimal places don't always match up. Although I am not sure if that is because of precision issues in matlab. However I am not where to come up with this extra factor just yet. It's getting late so I will think about it tomorrow.
From: Wayne King on
"EUIX Wang" <kuhanw(a)gmail.com> wrote in message <hncp15$k6m$1(a)fred.mathworks.com>...
> I did a little bit of tinker and I think the factor is N/nfft, where N is the total number of points. I say I think because the exact decimal places don't always match up. Although I am not sure if that is because of precision issues in matlab. However I am not where to come up with this extra factor just yet. It's getting late so I will think about it tomorrow.

Hi, It sounds like it's definitely just the scaling factor from your description. In your code are you using 1/Fs as part of the scaling factor? I think you'll find that the scaling is

1/(Fs*N) where N is the length of the input series (before wrapping). Then, for the one-sided PSD estimate, you scale everything except DC by 2. For example:

reset(RandStream.getDefaultStream);
x=randn(10,1);
N = length(x);
nfft=5;
Fs=1000;
%Periodogram with nfft less than segment length
[Pxx,Fxx]=periodogram(x,[],nfft,Fs);
% Pxx is 0.0039 0.0061 0.0077
% now the brute force way
% wrapping the windowed time data with datawrap()
% same as sum(buffer(x,5),2)
X=datawrap(x,nfft);
xdft=fft(X,5);
Pwr = xdft.*conj(xdft);
% Scaling
Pwr = (1/(Fs*N))*Pwr;
% select the bins for one-sided estimate
Pwr=Pwr(1:(nfft+1)/2);
% scale for one-sided estimate 2*everything but DC
Pwr(2:end)=2*Pwr(2:end);
% compare Pwr and Pxx

Hope that helps,
Wayne