Reply by Sergio Dominguez May 14, 20032003-05-14

Hi! checking this again, I have come out with the following doubt,

Using Dr. Valozic example, N=2^12;
P2=2*4*atan(1);
t=[0:P2/N:P2];
x=sin(2*t);
f=1/(t(3)-t(2));
[xs,fxs]=pwelch(x,N,f);

sum(x.^2)/N

%% ans =

%% 0.50000000000000

trapz(fxs,xs)

%% ans =

%% 0.50000033017621

[xs,fxs]=pwelch(x,hanning(N),0,2^13,f);
trapz(fxs,xs)

%% ans =

%% 0.49999864462520

%% But if we do,

win=hanning(N+1);
sum((win'.*x).^2)/N

%% ans =

%% 0.18754476030737 %% So, the parseval theorem when although the function was windowed still
%% applies to the non-windowed series??

%% The second question is what happens when we add a DC value,, how this adds to
the power spectrum value, for example N=2^12;
P2=2*4*atan(1);
t=[0:P2/N:P2];
x=sin(2*t)+3;
f=1/(t(3)-t(2));
[xs,fxs]=pwelch(x,N,f);

sum(x.^2)/N

%% ans =

%% 9.50219726562497

trapz(fxs,xs)

%% ans =

%% 6.19739184524543

[xs,fxs]=pwelch(x,hanning(N),0,2^13,f);
trapz(fxs,xs)

%% ans =

%% 7.99809853529597 Therefore I really do not know how should it be added the DC value.

Can someone give me a hand with this? I am really stucked.

Thanks!

Sergio
A las 12:28 del 18 de Feb de 2003, Jeff Brower <> dijo:
> Predrag Valozic-
>
> Also keep in mind that the 1/N scaling is for the time domain data length, not
> necessarily for full FFT length. For example, if time data set is 10, and FFT
length
> is 8 (zero filling = 54), then scale value is 1/10 for accurate amplitude
scaling in
> f-domain.
>
> In the general case, if a window is used, then I think the accurate scaling
factor,
> for example to see same linear magnitude amplitude value in f domain as Vpp in
time
> domain for a sine wave, is sum(window values)/N, where N = window length.
>
> Jeff Brower
> DSP sw/hw engineer
> Signalogic
>
> > There are few reasons, fft and Parseval theorem doesn't fit:
> > 1. 1/N scaling is missing in fft Matlab algorithm
> > 2. One sided and two sided spectrums
> > 3. Relation between signal period and N
> > 4. Window function.
> >
> > 1. If one do a simple test:
> > N;
> > P2=2*4*atan(1);
> > t=[0:P2/N:P2];
> > x=sin(2*t);
> > Xt(x,N);
> > Xas(X)
> > Xa =
> > Columns 1 through 7
> > 0.0000 0.0000 8.0000 0.0000 0.0000 0.0000 0.0000
> > Columns 8 through 14
> > 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
> > Columns 15 through 16
> > 8.0000 0.0000
> > It is obvious, that 1/N is missing because the correct value is 0.5.
> > If one does scaling, then Parsaval theorem is fulfilled.
> > Xa = Xa/N
> > Xa =
> > Columns 1 through 7
> > 0.0000 0.0000 0.5000 0.0000 0.0000 0.0000 0.0000
> > Columns 8 through 14
> > 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000
> > Columns 15 through 16
> > 0.5000 0.0000
> >
> > 2. Amplitude of a single sided spectral component is twice the amplitude in
> > FFT spectrum.
> >
> > 3. If the signal period is not N or N/2, or N/3 ... the slight difference is
> > possible.
> >
> > 4. If window function is implemented, then the Parsaval theorem stands for
> > modified signal.
> >
> > Best regards,
> >
> > Predrag Valozic
> >
> > ----- Original Message -----
> > From: Sergio Dominguez <>
> > To: Ervin <>
> > Cc: <>
> > Sent: 2003. velja 17 09:57
> > Subject: Re: [matlab] spectrum and fft
> >
> > > OK, I understand what you mean, but it is different for every
> > implementation,
> > > not for every transform you do, is that right?? I mean, has not the people
> > > from matlab determined what is the scaling factor for their
> > implementation,
> > > because in the single example they give of it they scale it by the number
> > of
> > > points, which does not give the right scaling. Does it?
> > >
> > > Basically what I am trying to do is to estimate the spectrum of a time
> > series
> > > (using spectrum or psd) and test the parseval theorem. Has anyone been
> > working
> > > with the spectrum with coherents results?
> > >
> > > Sergio
> > >
> > >
> > > A las 05:25 del 15 de Feb de 2003, Ervin <> dijo:
> > > > Helo Sergio!
> > > > Basically every FFT algorithm implemented on the
> > > > computer has a problem with it. It doesnt do scaling
> > > > properly, so you have to play with it, until you find
> > > > out what scales it uses.
> > > > Cheers!
> > > > Ervin
> > > > --- Sergio Dominguez <> wrote:
> > > > > Hi all!
> > > > >
> > > > > Has anybody found anything strange working with the
> > > > > spectrum and fft functions
> > > > > implemented in matlab??
> > > > >
> > > > > The frecuency behaviour is OK, but there is some
> > > > > scaling factor missing.
> > > > > Basically I do not get the parseval theorem to apply
> > > > > when I find the spectrum
> > > > > with matlab, and if I do a fft of some functions the
> > > > > initial values are not
> > > > > correct.
> > > > >
> > > > > Anybody seen something like this?
> > > > >
> > > > > Thanks,
> > > > >
> > > > > Sergio
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > > > =====
> > > > Ervin

--
Gross, adj.:
When your grandmother kisses you goodnight and slips you some tongue.