title: Fourier transform of simple sin wave in matlab
body: <p>I try to show spectrum of simple sin wave as we know a single sin wave with fixed frequency must have on peak in its spectrum I write this code but I can't get this one peak what is wrong in my code:</p>
  
  <pre><code>clc
  nsteps=200;%number of signal elements in time domain
  i=sqrt(-1);
  NFREQS=100;%number of elements in frequency domain
  ddx=1e-9;
  dt=ddx/(6e8);%separation between each time domain elements
  lambdai=150e-9;
  lambdaf=500e-9;
  freqi=3e8/lambdai;
  freqf=3e8/lambdaf;
  freq=zeros(1,NFREQS);
  for j=1:NFREQS
  freq(j)=freqi-j*(freqi-freqf)/NFREQS;%desired frequency domain
  end
  arg=2*pi*freq*dt;
  et=zeros(nsteps,1);
      for j=1:nsteps
         et(j)=sin(2*pi*3e15*j*dt);%sin wave in time domain
      end
  e=zeros(NFREQS,1);
  for n=1:NFREQS
  for j=1:nsteps  
   e(n)=e(n)+et(j)*exp(-i*arg(n)*n);%sin wave in frequency domain
  end
  end
  lambda=linspace(lambdai,lambdaf,NFREQS);
  plot(lambda,abs(e))
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/i5sUs.png" alt="The result is here"></p>