How to Plot Summation of Shifted impulses in MATLAB?
According to the features of the unit impulse function $\delta(t)$; at t = 0, the function goes toward infinity. Actually, the unit impulse function is meaningful with its area which is 1.
Additionally, MATLAB don’t show the famous arrow notation of the unit impulse function. Instead, it shows an invisible line which can be noticed where the function increases into infinity, i.e. the time value on the time axis where the function increases into infinity is blank. This can be seen from the figure.
On the other hand, the unit sample function $\delta[n]$ value is defined with the area of the unit impulse function which is 1.
We can obtain h[n] function by sampling h(t) function. But, what about those inifinities?
So, let’s do some gamble!
If we code h(t) function in MATLAB, it will actually be a row vector. In this row vector, we can change those infinities with ones in order to sample the function correctly. This process will require a for loop and an if statement.
The MATLAB source code for the complete process is given below:
t = -10: 1: 10; % Time range

Ts = 1; % Sampling period

syms k; % Symbol assingment for summation

function_1 = (t + 1) .* symsum(dirac(t - k), k, 1, 5); % Summation

subplot(2, 1, 1);
plot(t, function_1, &quot;r&quot;, &quot;LineWidth&quot;, 3);
xlabel(&quot;Time (s)&quot;);
ylabel(&quot;h(t)&quot;);
title(&quot;h(t) Time Function&quot;);

for a = 1: length(function_1) - 1 % For loop-if statement duo for replacing infinity results with unit sample function
    if function_1(a) == Inf
       function_1(a) = 1;
    end
end

function_2 = (t + 1) .* function_1; % Complete function to be sampled

n = t / Ts; % Sample range

subplot(2, 1, 2);
stem(n, function_2, &quot;ro&quot;, &quot;LineWidth&quot;, 3);
xlabel(&quot;Samples [n]&quot;);
ylabel(&quot;h[n]&quot;);
title(&quot;h[n] Sample Function&quot;);

According to the figure, sampling process has gone well and it matches with analysis that I’ve done on the paper.

Actually, there may be other approaches for the replacements of the infinities with ones but this one does the trick well.