EE342: MATLAB M-FILE FOR PLOTTING DISCRETE-TIME IMPULSE AND STEP FUNCTIONS

MATLAB M-File example1.m:
%
% File Name:  example1.m
%
% Description: M-file demonstrating how to plot discrete-time impulse
%              and step functions.
%

clear;				     % clear memory
figure(1); clf;			     % open and clear figure 1

k = -5:10;			     % discrete-time variable

delta = (k >= 0) - (k >= 1);	     % define and plot delta[k]
subplot(2,2,1);
stem(k,delta,'filled');
xlabel('k'); ylabel('\delta[k]');
title('Discrete-Time Impulse');

shifted_delta = (k >= 2) - (k >= 3); % define and plot delta[k-2]
subplot(2,2,2);
stem(k,shifted_delta,'filled');
xlabel('k'); ylabel('\delta[k-2]');
title('Shifted Discrete-Time Impulse');

u = (k >= 0);			     % define and plot u[k]
subplot(2,2,3);
stem(k,u,'filled');
xlabel('k'); ylabel('u[k]');
title('Discrete-Time Step');

shifted_u = (k >= 2);		     % define and plot u[k-2]
subplot(2,2,4);
stem(k,shifted_u,'filled');
xlabel('k'); ylabel('u[k-2]');
title('Shifted Discrete-Time Step');
MATLAB Plot Generated: