Why does my dft plot of $\sin(x)$ look so strange? It goes to negative and then inverts closer to the edge.


enter image description here

  • 2
    $\begingroup$ imho you need to change real to abs $\endgroup$ Nov 4, 2023 at 17:14
  • $\begingroup$ i tried it helped fix the part of negative interval but that doesn't make any change to the peak: imgur.com/a/b9vFRWt $\endgroup$
    – Alexander
    Nov 4, 2023 at 17:30
  • $\begingroup$ it is need tapering beginning and end of the signal or make integer value for number of periods, mathworks.com/help/signal/ug/windows.html $\endgroup$ Nov 4, 2023 at 18:19
  • $\begingroup$ thank you! i think i get the idea $\endgroup$
    – Alexander
    Nov 4, 2023 at 18:27

1 Answer 1


There are two things you can try, depending on what you're aiming for.

If you want to see a sharp peak at frequency $\omega = 1$, as in the code in your question, then you need to increase the DFT resolution by increasing the number of samples in the signal. With x = 0:0.1:100, I get:

enter image description here

If you want to see a sharp peak without increasing the number of samples, you need to increase the signal's frequency. With y = sin(10*x) I get:

enter image description here

Note that in both cases what has been done is to increase the number of sine periods in the signal y. This is the key to obtaining a high-resolution spectrum using the DFT.

Other relevant concepts that are involved here are "spectral leakage" and "windowing". See Why does spectral leakage arise in an FFT? and What should be considered when selecting a windowing function when smoothing a time series? to learn more.


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.