Discussion:
[Scilab-users] discrete Fourier transform
haasejos
2013-03-21 15:41:23 UTC
Permalink
hello,
for signalanalysis I would like to use discrete Fourier transform (dft). To
see, how it works, I use the simple example below. Why is *XfA =
abs(Xf)*2/n* respectively why is XfA = abs(Xf) wrong?

clear; clc; xdel;

function y = f(x);
y = sin(x);
endfunction;
n = 200;
x=linspace(0,2*%pi,n);
y=f(x);

mat = [x',y'];
//disp(mat);
//plot2d(x , y);

//xtitle('DATA','n''','y''');

Xf=dft(y,-1);
XfA = abs(Xf)*2/n;
plot2d3([1:n/2]',XfA(1:n/2));




--
View this message in context: http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Serge Steer
2013-03-21 16:13:59 UTC
Permalink
Post by haasejos
hello,
for signalanalysis I would like to use discrete Fourier transform (dft). To
see, how it works, I use the simple example below. Why is *XfA =
abs(Xf)*2/n* respectively why is XfA = abs(Xf) wrong?
Why do you say that XfA = abs(Xf) is wrong
Note however. It is much more efficient using fft instead of dft.

Serge Steer
Post by haasejos
clear; clc; xdel;
function y = f(x);
y = sin(x);
endfunction;
n = 200;
x=linspace(0,2*%pi,n);
y=f(x);
mat = [x',y'];
//disp(mat);
//plot2d(x , y);
//xtitle('DATA','n''','y''');
Xf=dft(y,-1);
XfA = abs(Xf)*2/n;
plot2d3([1:n/2]',XfA(1:n/2));
--
View this message in context: http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
Stefan Du Rietz
2013-03-21 17:46:14 UTC
Permalink
On 2013-03-21 17:13, Serge Steer wrote:
--------------------
Post by Serge Steer
Post by haasejos
hello,
for signalanalysis I would like to use discrete Fourier transform (dft). To
see, how it works, I use the simple example below. Why is *XfA =
abs(Xf)*2/n* respectively why is XfA = abs(Xf) wrong?
Why do you say that XfA = abs(Xf) is wrong
Note however. It is much more efficient using fft instead of dft.
Serge Steer
Maybe haasejos meant and should have used XfA == abs(Xf)

Stefan
Post by Serge Steer
Post by haasejos
clear; clc; xdel;
function y = f(x);
y = sin(x);
endfunction;
n = 200;
x=linspace(0,2*%pi,n);
y=f(x);
mat = [x',y'];
//disp(mat);
//plot2d(x , y);
//xtitle('DATA','n''','y''');
Xf=dft(y,-1);
XfA = abs(Xf)*2/n;
plot2d3([1:n/2]',XfA(1:n/2));
--
http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
http://lists.scilab.org/mailman/listinfo/users
haasejos
2013-03-21 19:34:28 UTC
Permalink
good evening,
what I meant is, that XfA(2) should be "1". Because this value can be
understood as the amplitude of sin(x). But XfA(2) beeing calculated with
XfA=abs(Xf) (see example) returns "100". This is wrong, isn't it?
Josef



--
View this message in context: http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318p4026324.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Stefan Du Rietz
2013-03-21 20:02:51 UTC
Permalink
On 2013-03-21 20:34, haasejos wrote:
--------------------
Post by haasejos
good evening,
what I meant is, that XfA(2) should be "1". Because this value can be
understood as the amplitude of sin(x). But XfA(2) beeing calculated with
XfA=abs(Xf) (see example) returns "100". This is wrong, isn't it?
Josef
-->n = 200;
-->x=linspace(0,2*%pi,n);
-->y=sin(x);
-->Xf=dft(y,-1);
-->XfA = abs(Xf)*2/n;
-->XfA(2)
ans =
0.9974519

/Stefan
haasejos
2013-03-21 21:13:42 UTC
Permalink
-->n = 200;

-->x=linspace(0,2*%pi,n);

-->y=sin(x);

-->Xf=dft(y,-1);

-->XfA = abs(Xf); *please look at the difference! *
-->XfA(2)
ans =

99.745189



--
View this message in context: http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318p4026326.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Mike Page
2013-03-21 21:34:16 UTC
Permalink
Hi,

I think this is just a question of scaling. There is no "correct" scaling
for the FFT - just some different conventions. This is explained here
(http://www.mathworks.co.uk/matlabcentral/answers/15770-scaling-the-fft-and-
the-ifft).

The "correct" answer with Scilab would be exactly 100 (N/2) in your case,
but you have a small error because your waveform is not exactly periodic -
the first and last sample are the same, but you should have the last sample
being the one before the first sample for a complete cycle.

The following code does that:

-->n=201;

-->x=linspace(0,2*%pi,n);

-->x=x(1:200);

-->y=sin(x);

-->Xf=dft(y,-1);

-->XfA = abs(Xf);

-->XfA(2)
ans =

100.

HTH,
Mike.


-----Original Message-----
From: users-***@lists.scilab.org
[mailto:users-***@lists.scilab.org]On Behalf Of haasejos
Sent: 21 March 2013 21:14
To: ***@lists.scilab.org
Subject: Re: [Scilab-users] discrete Fourier transform


-->n = 200;

-->x=linspace(0,2*%pi,n);

-->y=sin(x);

-->Xf=dft(y,-1);

-->XfA = abs(Xf); *please look at the difference! *
-->XfA(2)
ans =

99.745189



--
View this message in context:
http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318p4026326.
html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at
Nabble.com.
_______________________________________________
users mailing list
***@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


-----
No virus found in this message.
Checked by AVG - www.avg.com
Version: 2013.0.3267 / Virus Database: 3160/6194 - Release Date: 03/21/13
haasejos
2013-03-22 17:43:11 UTC
Permalink
thanks a lot for your answers!



--
View this message in context: http://mailinglists.scilab.org/discrete-Fourier-transform-tp4026318p4026331.html
Sent from the Scilab users - Mailing Lists Archives mailing list archive at Nabble.com.
Loading...