Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Problem with FFT Matlab code

Status
Not open for further replies.

snmeciut

Member level 4
Joined
Nov 30, 2002
Messages
71
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
348
Dear

I found a simple code for fft in below address

**broken link removed**

and converted in MATLAB code.(this is easy because matlab is as same as c code, but indeces start from 1 in matlab)

but my matlab function is not same as fft matlab fuction.

function X=DFT(x,N);
S=size(x);
X=[x,zeros(1,N-S(2))];
bit=log(N)/log(2);
N2=N/2;
k=0;
for n=0:N-2
if(n<k)
temp=X(k+1);
X(k+1)=X(n+1);
X(n+1)=temp;
end
m=N2;
while(m<=k)
k=k-m;
m=m/2;
end
k=k+m;
end
l2=1;
w=-1+0*i;
for loop=1:bit
l1=l2;
l2=l2*2;
u=1;
for n=0:l1-1
k=n;
while(k<N)
i1=k+l1+1;
temp=u*X(i1);
X(k+1)=X(k+1)+temp;
X(i1)=X(k+1)-temp;
k=k+l2;
end
u=u*w;
end
w=sqrt((1+real(w))/2)-sqrt((1-real(w))/2)*i;
end

Would you please help me to overcome this problem or send me a fft matlab code?

Best Rigards.
 

Re: Problem with fft

Why you want to write your own fft code in MATLAB ?:| There is a function fft () already existing.

Try these commands.

Demo .....(for a demo)
lookfor ........ ( say fft)
help..... (say fft)

i.e. type help fft

You will get it.
 

Re: Problem with fft

%FFT Discrete Fourier transform.
% FFT(X) is the discrete Fourier transform (DFT) of vector X. For
% matrices, the FFT operation is applied to each column. For N-D
% arrays, the FFT operation operates on the first non-singleton
% dimension.
%
% FFT(X,N) is the N-point FFT, padded with zeros if X has less
% than N points and truncated if it has more.
%
% FFT(X,[],DIM) or FFT(X,N,DIM) applies the FFT operation across the
% dimension DIM.
%
% For length N input vector x, the DFT is a length N vector X,
% with elements
% N
% X(k) = sum x(n)*exp(-j*2*pi*(k-1)*(n-1)/N), 1 <= k <= N.
% n=1
% The inverse DFT (computed by IFFT) is given by
% N
% x(n) = (1/N) sum X(k)*exp( j*2*pi*(k-1)*(n-1)/N), 1 <= n <= N.
% k=1
%
% See also FFT2, FFTN, FFTSHIFT, FFTW, IFFT, IFFT2, IFFTN.

% Copyright 1984-2005 The MathWorks, Inc.
% $Revision: 5.15.4.5 $ $Date: 2005/06/21 19:23:54 $

% Built-in function.
 

Re: Problem with fft

??? Input argument "x" is undefined.
this is the error ;
first input the sequence to it..
 

Re: Problem with fft

??? Input argument "x" is undefined.
this is the error ;
first input the sequence to it..
you need to save the function in a file (called DFT.m), add it to your path, and then from the command window call it as DFT(x,N); where x is an array in your workspace and N is the length of the array.
 
Last edited:

Re: Problem with fft

n=input('enter the length of the dft sequence');
x=input('enter the sequence');
y=fft(x,n);
k=0:1:length(y);
stem(k,abs(y));
disp ('result is');
disp('y');
disp(abs(y));

it works!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top