MATLAB: Pulse Train FFT low resolution

fft

Hi,
I have written a code for pulse train and its FFT. However, my FFT resolution is bad. How can I make this better ?
fs=1e9 ; %sampling frequency
t=-0.1e-6:1/fs:7e-6; %time base
T=1e-6; %Period
D=0.5e-6 %Duration
N=40; %Number of pulses
d=[0:T:T*N];
y=pulstran(t,d,'rectpuls',D);
t=t+0.25e-6;
subplot(2,1,1)
plot(t,y);
title(['Rectangular Pulse width=', num2str(T),'s']);
xlabel('Time(s)');
ylabel('Amplitude');
L=length(y);
NFFT = 1024;
X = fftshift(fft(y,NFFT)); %FFT with FFTshift for both negative & positive frequencies
f = fs*(-NFFT/2:NFFT/2-1)/NFFT; %Frequency Vector
subplot(2,1,2)
plot(f,abs(X)/(L),'r');
title('Magnitude of FFT');
xlabel('Frequency (Hz)')
ylabel('Magnitude |X(f)|');

Best Answer

When using FFT, you should consider about "periodic boundary condition." In your original code, I don't think this condition was satisfied.
If my understanding is correct, your waveform in time domain repeats every 1000 samples. And if you want to obtain more frequency resolution, you should increase FFT length. So, based on your original code, you should change "NFFT = 7000;"
To enhance the performance, I would recommend adjusting sampling frequency to match the FFT length (NFFT) to 2^N.