DSPRelated.com
Forums

spectrum and fft

Started by Sergio Dominguez February 15, 2003
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



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
>
> __________________________________________________
>
--
QOTD:
"I say, and without apology, hang the bitch."


Hi,

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
> >
> > __________________________________________________
> >
> --
> QOTD:
> "I say, and without apology, hang the bitch." > _____________________________________
> Note: If you do a simple "reply" with your email client, only the author
of this message will receive your answer. You need to do a "reply all" if
you want your answer to be distributed to the entire group.
>
> _____________________________________
> About this discussion group:
>
> To Join:
>
> To Post:
>
> To Leave:
>
> Archives: http://www.yahoogroups.com/group/matlab
>
> More DSP-Related Groups: http://www.dsprelated.com/groups.php3
>
> ">http://docs.yahoo.com/info/terms/



THank you very much for your very detailed answer, here I have some comments
back, sorry if they are too basic,

>
> There are few reasons, fft and Parseval theorem doesn't fit:
> 1. 1/N scaling is missing in fft Matlab algorithm

OK, I knew about this. this comes from the implementation of the fftw,in which
matlab is based. But as I am trying to use the spectrum functions already
implemented in matlab I thought it should be OK. The point is that they do not
scale it in their algorithms.

So, like this we get the values of the peaks right. But, what I do not
understand, is that if we try the same with x=exp(-t), the value of the first
point of the spectra should be one, right?

> 2. One sided and two sided spectrums
Please, correct me if I have it wrong.

In terms of amplitude it affects, but it would not affect in terms of
integration of the spectrum or parseval therem. And the scaling factor from
the twosided power spectrum to the single-sided would be of 4.

> 3. Relation between signal period and N

Windowing the function and making always the length of the window equal to the
length of the fft this should not affect.

> 4. Window function.

Of course!! I really had not thought about this. Furthermore having a window
function there is another scaling factor that would be
sum(window.^2)/length(window), right? Thank you very much again,

Sergio

--
Of course, most people eventually give up bowling for sex.
The balls are lighter and you don't have to change your shoes.


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