DFT Matlab function

  • MATLAB
  • Thread starter drdizzard
  • Start date
  • #1
18
0
I've been asked to write a function (.m file) in Matlab to calculate the discrete fourier transform coefficient for an arbitrary function x. So far this is what I've done:

function a = mydft(x,N)
%MYDFT Calculates the discrete fourier transform
%usage:
%[a]=mydft(x)
%x=[ x[0] x[1] ... x[N-1] ] - vector containing discrete time sequence
%a=[ a_0 a_1 ... a_N-1 ] - vector of discrete time Fourier Series
%coefficients, k=0,...,N-1
for k=0:N-1
for m=0:N-1
w=exp(-j*2*pi/N.*m.*k);
end
a=sum(x(m).*w);
end
end

when I use it on a signal given to me and then plot kw_hat vs. |a| I get a plot that looks nothing like what I do for the same signal by hand. I don't think I'm getting the correct DFT coefficients out of this function

This is the first time I've used Matlab so I'm not very familiar with it and would appreciate any advice.
 

Answers and Replies

Related Threads on DFT Matlab function

  • Last Post
Replies
1
Views
3K
  • Last Post
Replies
2
Views
791
  • Last Post
Replies
2
Views
25K
Replies
1
Views
2K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
2
Views
6K
  • Last Post
Replies
2
Views
5K
  • Last Post
Replies
3
Views
3K
Top