Re: [Scilab-users] fourier series and fft

2016-09-24 Thread Samuel Gougeon

Le 22/09/2016 23:09, paul.carr...@free.fr a écrit :

dear all

I'm novice in Fourier series and other and my question is probably 
naive (sorry for this) => I'm wondering if scilab can directly 
calculate the Fourier coefficient a0, a_k and b_k ?


I'm currently doing it "by hand" is order to familiarise myself with 
it (and I'm looking at the same time to documents on  FFT use and 
rules to refind the 2 natural frequencies of the example here bellow), 
but it seems I'll need to code the coefficient calculations ... Am I 
right ?

.
Doing that is the main purpose of fft().
fft() returns the (bilateral) complex coefficients c_k of the series.
a_k and b_k are easily computed from them.

// Example #1: n  =  100;
x  =  linspace(0,  1,  n+1);
x  =  x(1:n);
y  =  sin(2*%pi*x);
ft  =  fft(y);
ft  =  clean(ft);
c  =  ft/n;
c0  =  c(1)
// c(k) = ft(k+1)
// c(-k) = ft(n+1-k)

a0  =  c0 // average
a  =  (c(2:(n/2))  +  c(n:-1:(n/2+2)))  // a_k = c_k + c_(-k)
b  =  %i*(c(2:n/2)  -  c(n:-1:n/2+2)) // b_k = %i*(c_k - c_(-k))
// Example #2:
n = 100; x = linspace(0, 2, n+1); x = x(1:n); y  =  2*sin(2  *  %pi  *  x)  -  
3*cos(%pi  *  x);
ft  =  fft(y);
ft  =  clean(ft);
c  =  ft/n;
c0  =  c(1)
a0  =  c0
a  =  (c(2:(n/2))  +  c(n:-1:(n/2+2)))
b  =  %i*(c(2:n/2)  -  c(n:-1:n/2+2))

--> a = (c(2:(n/2)) + c(n:-1:(n/2+2)))
 a  =
 column 1 to 22
  -3.   0.   0.   0.   0.   0.   0.  ...
 // here is the "-3" coeff of the first even cos() harmonic

--> b = %i*(c(2:n/2) - c(n:-1:n/2+2))
 b  =
 column 1 to 22
   0.   2.   0.   0.   0.   0.   0.  ...
 // here is the "3" coeff of the second odd sin() harmonic

Anyway, the full x-range is considered as the period.
If it is not actually the case, some artefacts appear in the results.
To avoid them, it is mandatory to sample /x/ over a multiple of its 
"natural" period.
Example #1: The period of sin(2*%pi*x) is 2*pi, this is why x must be 
sampled from 0 to 1.

Example #2: The period of 2*sin(2 * %pi * x) - 3*cos(%pi * x)is also 2*pi,
  this is why x must be sampled from 0 to 2 (in the 
cos() argument).


HTH
Samuel

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] fourier series and fft

2016-09-23 Thread paul . carrico
sound interesting ... many thanks for the information 


Paul 

- Mail original -

De: "Rafael Guerra"  
À: "Users mailing list for Scilab"  
Envoyé: Vendredi 23 Septembre 2016 13:57:31 
Objet: Re: [Scilab-users] fourier series and fft 



Hi Paul, 

Fyi, Tom Co's simple tutorial: http://www.chem.mtu.edu/~tbco/cm416/fft1.pdf 
shows how to obtain the Fourier coefficients via the fft 

Regards, 
Rafael 

-Original Message- 
From: users [mailto:users-boun...@lists.scilab.org] On Behalf Of 
paul.carr...@free.fr 
Sent: Friday, September 23, 2016 8:45 AM 
To: t...@wescottdesign.com; Users mailing list for Scilab 
 
Subject: Re: [Scilab-users] fourier series and fft 

Thanks Tim for this answer; well I notice I need to "dig" deeper on that topic 

Paul 

- Mail original -


De: "Tim Wescott " < t...@wescottdesign.com > 
À: "Users mailing list for Scilab" < users@lists.scilab.org > 
Envoyé : Jeudi 22 Septembre 2016 23:17:27 
Objet: Re: [Scilab-users] fourier series and fft 

Hey Paul: 

If you mean the Fourier series of a continuous-time periodic signal (or 
a continuous-time function of finite scope), then no, Scilab doesn't do 
that, because the FFT is different from the Fourier Series. If you have 
a signal that's symbolically defined as f(t) over some span of time, 
then Maxima may help you get a symbolic definition of the Fourier 
Series. 

The FFT is essentially the Fourier series of a sampled-time periodic (or 
finite-scope) signal, so if that sampled-time signal is a sufficiently 
accurate approximation of your continuous-time signal, and if your a0, 
a_k and b_k are defined to match the way that Scilab does the FFT , then 
the real part of the FFT are the a coefficients, and the imaginary part 
are the b coefficients. 

If you gather up half a dozen books that include signal processing, 
especially if some are from applications areas a bit removed from 
"normal" signal processing, you'll find that everyone specifies their 
Fourier stuff differently. So what comes out of Scilab's FFT may not 
match _your_ definitions of a0, etc., but they match _someone's_. 

On Thu, 2016-09-22 at 23:09 +0200, paul.carr...@free.fr wrote: 
> dear all 
> 
> I'm novice in Fourier series and other and my question is probably 
> naive (sorry for this) => I'm wondering if scilab can directly 
> calculate the Fourier coefficient a0, a_k and b_k ? 
> 
> 
> I'm currently doing it "by hand" is order to familiarise myself with 
> it (and I'm looking at the same time to documents on FFT use and 
> rules to refind the 2 natural frequencies of the example here bellow), 
> but it seems I'll need to code the coefficient calculations ... Am I 
> right ? 
> 
> Thanks 
> 
> Paul 

___ 
users mailing list 
users@lists.scilab.org 
http://lists.scilab.org/mailman/listinfo/users 

___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] fourier series and fft

2016-09-23 Thread Rafael Guerra
Hi Paul,



Fyi, Tom Co's simple tutorial: http://www.chem.mtu.edu/~tbco/cm416/fft1.pdf

shows how to obtain the Fourier coefficients via the fft



Regards,

Rafael



-Original Message-
From: users [mailto:users-boun...@lists.scilab.org] On Behalf Of 
paul.carr...@free.fr
Sent: Friday, September 23, 2016 8:45 AM
To: t...@wescottdesign.com; Users mailing list for Scilab 

Subject: Re: [Scilab-users] fourier series and fft



Thanks Tim for this answer; well I notice I need to "dig" deeper on that topic



Paul



- Mail original -

De: "Tim Wescott" mailto:t...@wescottdesign.com>>

À: "Users mailing list for Scilab" 
mailto:users@lists.scilab.org>>

Envoyé: Jeudi 22 Septembre 2016 23:17:27

Objet: Re: [Scilab-users] fourier series and fft



Hey Paul:



If you mean the Fourier series of a continuous-time periodic signal (or

a continuous-time function of finite scope), then no, Scilab doesn't do

that, because the FFT is different from the Fourier Series.  If you have

a signal that's symbolically defined as f(t) over some span of time,

then Maxima may help you get a symbolic definition of the Fourier

Series.



The FFT is essentially the Fourier series of a sampled-time periodic (or

finite-scope) signal, so if that sampled-time signal is a sufficiently

accurate approximation of your continuous-time signal, and if your a0,

a_k and b_k are defined to match the way that Scilab does the FFT, then

the real part of the FFT are the a coefficients, and the imaginary part

are the b coefficients.



If you gather up half a dozen books that include signal processing,

especially if some are from applications areas a bit removed from

"normal" signal processing, you'll find that everyone specifies their

Fourier stuff differently.  So what comes out of Scilab's FFT may not

match _your_ definitions of a0, etc., but they match _someone's_.



On Thu, 2016-09-22 at 23:09 +0200, 
paul.carr...@free.fr<mailto:paul.carr...@free.fr> wrote:

> dear all

>

> I'm novice in Fourier series and other and my question is probably

> naive (sorry for this) => I'm wondering if scilab can directly

> calculate the Fourier coefficient a0, a_k and b_k ?

>

>

> I'm currently doing it "by hand" is order to familiarise myself with

> it (and I'm looking at the same time to documents on  FFT use and

> rules to refind the 2 natural frequencies of the example here bellow),

> but it seems I'll need to code the coefficient calculations ... Am I

> right ?

>

> Thanks

>

> Paul


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] fourier series and fft

2016-09-22 Thread paul . carrico
Thanks Tim for this answer; well I notice I need to "dig" deeper on that topic

Paul

- Mail original -
De: "Tim Wescott" 
À: "Users mailing list for Scilab" 
Envoyé: Jeudi 22 Septembre 2016 23:17:27
Objet: Re: [Scilab-users] fourier series and fft

Hey Paul:

If you mean the Fourier series of a continuous-time periodic signal (or
a continuous-time function of finite scope), then no, Scilab doesn't do
that, because the FFT is different from the Fourier Series.  If you have
a signal that's symbolically defined as f(t) over some span of time,
then Maxima may help you get a symbolic definition of the Fourier
Series.

The FFT is essentially the Fourier series of a sampled-time periodic (or
finite-scope) signal, so if that sampled-time signal is a sufficiently
accurate approximation of your continuous-time signal, and if your a0,
a_k and b_k are defined to match the way that Scilab does the FFT, then
the real part of the FFT are the a coefficients, and the imaginary part
are the b coefficients.

If you gather up half a dozen books that include signal processing,
especially if some are from applications areas a bit removed from
"normal" signal processing, you'll find that everyone specifies their
Fourier stuff differently.  So what comes out of Scilab's FFT may not
match _your_ definitions of a0, etc., but they match _someone's_.

On Thu, 2016-09-22 at 23:09 +0200, paul.carr...@free.fr wrote:
> dear all
> 
> I'm novice in Fourier series and other and my question is probably
> naive (sorry for this) => I'm wondering if scilab can directly
> calculate the Fourier coefficient a0, a_k and b_k ?
> 
> 
> I'm currently doing it "by hand" is order to familiarise myself with
> it (and I'm looking at the same time to documents on  FFT use and
> rules to refind the 2 natural frequencies of the example here bellow),
> but it seems I'll need to code the coefficient calculations ... Am I
> right ?
> 
> 
> 
> Thanks
> 
> 
> Paul
> 
> 
> #
> mode(0)
> 
> function y=f(x)
> y=2.*sin(2 * %pi * x) - 3.*cos(%pi * x);
> endfunction
> 
> periode = 2;
> number_of_periodes = 1;
> n = periode * number_of_periodes;
> 
> x = [0 : %pi/100 : n]';
> y = f(x);
> N = size(x,"*");
> 
> scf()
> plot2d(x,y);
> 
> a = fft(y,-1);
> ___
> users mailing list
> users@lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users
___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


Re: [Scilab-users] fourier series and fft

2016-09-22 Thread Tim Wescott
Hey Paul:

If you mean the Fourier series of a continuous-time periodic signal (or
a continuous-time function of finite scope), then no, Scilab doesn't do
that, because the FFT is different from the Fourier Series.  If you have
a signal that's symbolically defined as f(t) over some span of time,
then Maxima may help you get a symbolic definition of the Fourier
Series.

The FFT is essentially the Fourier series of a sampled-time periodic (or
finite-scope) signal, so if that sampled-time signal is a sufficiently
accurate approximation of your continuous-time signal, and if your a0,
a_k and b_k are defined to match the way that Scilab does the FFT, then
the real part of the FFT are the a coefficients, and the imaginary part
are the b coefficients.

If you gather up half a dozen books that include signal processing,
especially if some are from applications areas a bit removed from
"normal" signal processing, you'll find that everyone specifies their
Fourier stuff differently.  So what comes out of Scilab's FFT may not
match _your_ definitions of a0, etc., but they match _someone's_.

On Thu, 2016-09-22 at 23:09 +0200, paul.carr...@free.fr wrote:
> dear all
> 
> I'm novice in Fourier series and other and my question is probably
> naive (sorry for this) => I'm wondering if scilab can directly
> calculate the Fourier coefficient a0, a_k and b_k ?
> 
> 
> I'm currently doing it "by hand" is order to familiarise myself with
> it (and I'm looking at the same time to documents on  FFT use and
> rules to refind the 2 natural frequencies of the example here bellow),
> but it seems I'll need to code the coefficient calculations ... Am I
> right ?
> 
> 
> 
> Thanks
> 
> 
> Paul
> 
> 
> #
> mode(0)
> 
> function y=f(x)
> y=2.*sin(2 * %pi * x) - 3.*cos(%pi * x);
> endfunction
> 
> periode = 2;
> number_of_periodes = 1;
> n = periode * number_of_periodes;
> 
> x = [0 : %pi/100 : n]';
> y = f(x);
> N = size(x,"*");
> 
> scf()
> plot2d(x,y);
> 
> a = fft(y,-1);
> ___
> users mailing list
> users@lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users

-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432


___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users


[Scilab-users] fourier series and fft

2016-09-22 Thread paul . carrico
dear all 

I'm novice in Fourier series and other and my question is probably naive (sorry 
for this) => I'm wondering if scilab can directly calculate the Fourier 
coefficient a0, a_k and b_k ? 


I'm currently doing it "by hand" is order to familiarise myself with it (and 
I'm looking at the same time to documents on FFT use and rules to refind the 2 
natural frequencies of the example here bellow), but it seems I'll need to code 
the coefficient calculations ... Am I right ? 



Thanks 


Paul 


# 
mode ( 0 ) function y = f ( x ) y = 2. * sin ( 2 * %pi * x ) - 3. * cos ( %pi * 
x ) ; endfunction periode = 2 ; number_of_periodes = 1 ; n = periode * 
number_of_periodes ; x = [ 0 : %pi / 100 : n ] ' ; y = f ( x ) ; N = size ( x , 
" * " ) ; scf ( ) plot2d ( x , y ) ; a = fft ( y , - 1 ) ; ___
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users