fast Fourier transform.
fast Fourier transform.
x=fft(a ,-1) or x=fft(a) x=fft(a,1) or x=ifft(a) x=fft(a,-1,dim,incr) x=fft(a,1,dim,incr)
real or complex vector or real or complex matrix (2-dim fft)
real or complex vector or real or complex matrix (2-dim fft).
positive integer
positive integer
x=fft(a,-1) or
x=fft(a) gives a direct
transform.
If a is a vector a single variate direct FFT
is computed that is:

(the -1 argument refers to the sign of the
exponent..., NOT to "inverse"),
If a is a matrix or or
a multidimensionnal array a multivariate direct
FFT is performed.
a=fft(x,1) or
a=ifft(x)performs the inverse
transform normalized by 1/n.
If a is a vector a
single variate inverse FFT is computed

If a is a matrix or or a multidimensionnal
array a multivariate inverse FFT is performed.
x=fft(a,-1,dim,incr) allows to perform an
multidimensional fft.
If a is a real or complex vector implicitly indexed by
j1,j2,..,jp i.e. a(j1,j2,..,jp) where
j1 lies in 1:dim(1), j2 in
1:dim(2),... one gets a p-variate FFT by calling p times
fft as follows
where dimk is the dimension of the current variable
w.r.t which one is integrating and incrk is the increment
which separates two successive jk elements in
a.
In particular,if a is an mxn matrix,
x=fft(a,-1) is equivalent to the two instructions:
If the fftw module has been loaded into
Scilab this function uses that library (http://www.fftw.org/). On the
other case the fft function is based on the Fortran routines fft842.f
(Cooley-Tukey algorithm for vectors of size n=2^m) and dfftbi.f (for
other sizes) .
//Frequency components of a signal //---------------------------------- // build a noides signal sampled at 1000hz containing to pure frequencies // at 50 and 70 Hz sample_rate=1000; t = 0:1/sample_rate:0.6; N=size(t,'*'); //number of samples s=sin(2*%pi*50*t)+sin(2*%pi*70*t+%pi/4)+grand(1,N,'nor',0,1); y=fft(s); //the fft response is symmetric we retain only the first N/2 points f=sample_rate*(0:(N/2))/N; //associated frequency vector n=size(f,'*') clf() plot(f,abs(y(1:n))) | ![]() | ![]() |
//Using explicit formula for discrete Fourier transform //------------------------------------------------ function xf=DFT(x, flag); n=size(x,'*'); //Compute the n by n Fourier matrix if flag==1 then,//backward transformation am=exp(2*%pi*%i*(0:n-1)'*(0:n-1)/n); else //forward transformation am=exp(-2*%pi*%i*(0:n-1)'*(0:n-1)/n); end xf=am*matrix(x,n,1);//dft xf=matrix(xf,size(x));//reshape if flag==1 then,xf=xf/n;end endfunction //Comparison with the fast Fourier algorithm a=rand(1,1000); norm(DFT(a,1) - fft(a,1)) norm(DFT(a,-1) - fft(a,-1)) timer();DFT(a,-1);timer() timer();fft(a,-1);timer() | ![]() | ![]() |