MATLAB: Fourier Transformation of dirac comb

dirac combfftfourier transformationimpuls functionsignal processing

Hello guys,
in my code I generated a dirac comb and its FFT with:
%Time Signal
CarrierFrequenz=100; %frequency of the impulse in Hz
fs=CarrierFrequenz*10; % sample frequency (10 times higher than Carrier Frequency)
L=fs; %length signal
t=0:1/fs:1; % time vector
y=zeros(size(t));
y(1:fs/CarrierFrequenz:end)=1; %dirac comb
subplot(3,1,1)
plot(t,y); %time signal
xlabel('time(s)')
ylabel('P1')
%Frequency signal
Y = fft(y);
P2 = abs(Y/L);
subplot(2,1,2)
f = (fs*(-L/2:((L/2)-1))/L); %frequency domain
plot(f,P2(1:end-1))
title(' Amplitude Spectrum of S(t) FFT')
xlabel('f(Hz)')
ylabel('|P1(f)|')
and it generates the following plot:
Signal processing says:
So I wonder why the amplitudes in the frequency spectrum have this stair form and their magnitudes are way less than in the time domain.
Would be more than happy if s.o. could help me with that.
Best regards
Johannes

Best Answer

There is one too many points in the signal y. If you
plot([y y])
and zoom in you'll see the pulse at sample 1001 immediately followed by a pulse at sample 1002. So the underlying infinte length sequence isn't the infinite length sequnece in your question. But if you make y one sample shorter, then the underlying infinite sequence is the sequence in your question and it yields the expected result, at least with respect to eliminating the spreading (spectral leakaage) and non-constant peaks in the frequency domain. I didn't look carefully at the scaling.
CarrierFrequenz=100; %frequency of the impulse in Hz
fs=CarrierFrequenz*10; % sample frequency (10 times higher than Carrier Frequency)
L=fs; %length signal
t=0:1/fs:1; % time vector
t = t(1:end-1); % this line changed

y=zeros(size(t));
y(1:fs/CarrierFrequenz:end)=1; %dirac comb
subplot(3,1,1)
plot(t,y); %time signal
xlabel('time(s)')
ylabel('P1')
%Frequency signal
Y = fft(y);
P2 = abs(Y/L);
subplot(2,1,2)
f = (fs*(-L/2:((L/2)-1))/L); %frequency domain
plot(f,P2(1:end)) % this line changed
title(' Amplitude Spectrum of S(t) FFT')
xlabel('f(Hz)')
ylabel('|P1(f)|')