stem
. An example of its use follows:
ramp = 1:10; stem(ramp)Here is an example to plot y[n] = 2n for n = 0 to n = 5:
nn = 0:5; yy = 2 .^ nn; stem(nn,yy)Note the use of the period in front of the arithmetic operation ^. The .^ operator means to operate on each element in the vector argument(s) separately. You can get more information on the stem function by typing
help stem
It might help to convolve two short rectangular pulses of different lengths, e.g. length two samples and length three samples, to see the trend.
Appendix E in the course reader, on pages E-2 and E-3, contains a worked example of convolving two discrete-time rectangular pulses of the same length to produce a triangular pulse.
The convolution result will be a trapezoid when L1 is not equal to L2. The plateau in the trapezoid will have | L1 - L2 | + 1 samples in it, which can be rewritten as max(L1, L2) - min(L1, L2) + 1. As a sanity check, when L1 = L2, the convolution result is a triangular pulse and the plateau in the trapezoid would be one sample long.
/ t for 0 ≤ t < 5 x(t) = | \ 10-t for 5 ≤ t < 10We can write this as formula by using a rectangular pulse to enforce each interval:
x(t) = t ( u(t) - u(t-5) ) + (10-t) ( u(t-5) - u(t-10) )We can then convert this to Matlab code:
t = -1 : 0.01 : 11; x = t .* ( stepfun(t,0) - stepfun(t,5) ) + (10-t) .* ( stepfun(t,5) - stepfun(t,10) ); plot(t,x);
y[0] = x[0] + y[-1]The only initial condition is y[-1]. We then set n = 1:
y[1] = x[1] + y[0]There are no initial conditions in the expression for y[1].