Ok, this the corrected version of your program:
Fe=8E9; %Sampling frequency
N=8; %8 samples
df=Fe/N; %step
t=(0:N-1)/Fe; %the range
f0=1E9; %Frequency
x=2*sin(2*pi*f0*t)+2;
y=fft(x);
y2=fftshift
;
m=abs
;
Freq=(0:df:Fe-df);
figure(1),plot(t,x); %plot sinwave
figure(2),
plot(Freq, m);%plot DFT
And the plots that are generated are:
sine
fft
----------------
Now, if you increase the number of points to N= 16, these are the results:
sine
fft
----------------
If you increase the number of points to N= 64, these are the results:
sine
fft
----------------
Now, let's comment:
1. In your program, the second plot command is modified and it is plotted
m vs.
Freq
2. The number of N=8 points gives the frequency resolution of Fs/N=1GHz. This is too large since in reality you have two components in spectrum separated by 1GHz range, and FFT can not separate them (as you can see on the first FFT plot, you don't see two peaks in the 0-4GHz range, just one)
3. If you increase the number of points to N=16, it gives the frequency resolution of Fs/N=0,5GHz, and now the two components are separated in FFT, but still touching each other.
4. If you increase the number of points to N=64, it gives the frequency resolution of Fs/N=0,125GHz, and now the two components are completely separated in FFT (and this picture looks much like the one that you posted).
Conclusions:
1. If the number of points N in FFT is increased, you get the finer resolution and better separation of close components.
2. The larger the number of points N is, the more computational operations is needed for calculating FFT.
---
So, the number of point for FFT really depends on the application, and is the result of compromice between Conclusion_1 and Conclusion_2.
Hope that this clarifies a little.
Regards