Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

DFT Matlab function

  1. Mar 4, 2010 #1
    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
    %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

    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.
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted

Similar Threads - Matlab function Date
Working with Edge function in MATLAB Mar 7, 2017
Matlab Does MatLab have this kind of function? Jan 15, 2017
Matlab error matrix function Apr 25, 2016
Matlab Plotting a 3d function Apr 1, 2016
Fit with implicit nonlinear function - Matlab Oct 19, 2015