# Fourier transform does not produce the correct result

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

    Np=20;
n=0:1:Np-1;
s1=[sin(2*pi/Np*n)];
h1=freqz(s1);
figure(1);
plot(abs(h1));


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

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

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})\$$).