function y=myFFT(x,n,w)
% Fast Fourier transform of a vector x
% using the Danielson-Lanczos algorithm.
% The length of x, n, must be a power of 2
% w=exp(2*pi*i/n)
% See algorithm 12.1 on p.500 of Heath
% K. Ming Leung, 02/13/03
% This version is fully vectorized

if n==1
    y(1)=x(1);
else
    k=0:(n/2)-1;
    % actually no need to separately form these 2 vectors
    p(k+1)=x(2*k+1); % even-numbered elements
    s(k+1)=x(2*k+2); % odd-numbered elements
    q=myFFT(p,n/2,w*w);
    t=myFFT(s,n/2,w*w);
    k=0:n-1;
    y(k+1)=q(mod(k,n/2)+1)+w.^k.*t(mod(k,n/2)+1);
end