0
$\begingroup$

I used MATLAB to produce a simple sine wave over time:

frequency=7
sampling_frequency=1000;
total_time=1-1/sampling_frequency;
step=1/1000;
theta=0;
time=0:step:total_time;

y=Amplitude*sin(2*pi*frequency*time+theta)

I then used the following code to fast fourier transform:

Y=fft(y);
ploty=Y/length(y);
stem(abs(ploty))

I was expecting to see one spike at 7 instead I am getting 2 and not even at 7. One is at 8 and the other at 994. I am totally confused as to why.

$\endgroup$

1 Answer 1

7
$\begingroup$

You see one at index 8 because MATLAB's indexing is one-based, not zero-based as the equations that describe the DFT are. You get two spikes because your input signal is real and is therefore conjugate-symmetric in the frequency domain. If you work out the math, you'll see that the Fourier transform of a $\sin$ has two spikes symmetric about zero frequency. In order to get a single spike, you need to use a complex exponential function at the same frequency instead.

$\endgroup$
2
  • 1
    $\begingroup$ That is excellent.. you just alleviated 3 hours of headache!! Thanks again!! Ur a star $\endgroup$
    – jayvina
    Mar 14, 2013 at 22:53
  • 1
    $\begingroup$ also might need to mention fftshift()? $\endgroup$
    – endolith
    Mar 15, 2013 at 16:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.