image thumbnail

FFT for input sequence of any length

by

 

This program can calculate FFT of a sequence of length 2^n, where n < ∞

anyinputfft.m
x1=input('enter  d seqns')
N=length(x1);
x=0:N-1;
c=dec2bin(x);
c1=double(c);
c2=fliplr(c1);
c3=char(c2);
d=bin2dec(c3);
d12=d+1;
input=[];
for i=1:N
    k1=d12(i);
   input=[input x1(k1)];
end
r=input;
M=log(N)/log(2);
 WN=exp(-j*2*pi/N);
 
  for i=1:M
m=i
t=[0:1:2^(m-1)-1];
k=(N/2^m).*t;
WNK=WN.^k ;

bs=2^m
       
       for i3=1:N/bs
           for L=1:bs/2
   
     r(m+1,bs*i3-bs+L)=r(m,bs*i3-bs+L)+r(m,bs*i3-bs+L+bs/2)*WNK(1,L);
     r(m+1,bs*i3-bs+L+bs/2)=r(m,bs*i3-bs+L)-r(m,bs*i3-bs+L+bs/2)*WNK(1,L);
           end
       end
  end
  
  for tz=1:N
      f(1,tz)=r(M+1,tz);
  end
  
 % stem(f)
  n = 0:1:N-1;
k = 0:1:N-1;
  stem3(k,real(f),imag(f))
hold on
plot3(n,real(f),imag(f),'r')
hold off
view(-39.5,62)
xlabel('k')
ylabel('Real Xk')
zlabel('Imaginar Xk')

Contact us