I am trying to calculate the absolute value of a certain sinusoid to see how MATLAB calculates the Fourier Transform by using the freqz() command. Here is my Matlab code


And the plotted result is: enter image description here

My question is: My theoretical plot should only show one "bar". Why doesn't it do that? Is my code wrong?

  • \$\begingroup\$ You only have a small interval, so the sine wave is truncated. Theory assumes it goes to infinity. \$\endgroup\$
    – Chu
    Feb 26, 2019 at 14:20
  • \$\begingroup\$ How many sine wave cycles did your math consider? \$\endgroup\$
    – Andy aka
    Feb 26, 2019 at 14:20
  • 3
    \$\begingroup\$ The transformed window does not contain an exact multiple of the desired singular frequency \$\endgroup\$
    – uglyoldbob
    Feb 26, 2019 at 14:26
  • 1
    \$\begingroup\$ Mário, sure you want freqz and not just abs(fft)? \$\endgroup\$ Feb 26, 2019 at 15:02
  • 1
    \$\begingroup\$ Have you read the documentation for freqz? \$\endgroup\$
    – TimWescott
    Feb 26, 2019 at 15:36

1 Answer 1


As @MarcusMüller indicated, you need to use fft instead of freqz:

Replace h1=freqz(s1); with h1=fft(s1)/Np; Also, to interpret the result, it would be better to replace plot(abs(h1)); with stem(n,abs(h1));.

In your example, the signal is exactly one period of a sine wave with amplitude 1, so you should get a spike at n=1 and n=19 with amplitude one half. The amplitude of 1 is split over two frequencies. The n=19 corresponds to a negative frequency n=-1 (a sine wave is the sum of two complex exponentials, one with a positive frequency and one with a negative frequency: \$\sin(\omega t) = \frac{1}{2 j}(e^{j \omega t} - e^{-j \omega t})\$).

If you would want to plot a single-sided FFT (this has only positive frequencies and would provide an amplitude of one at n=1 in your example), have a look at the Matlab documentation for fft, example Noisy Signal.


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.