1.4 Representation Using Basic Signals 93
% t: time support
% m: slope of ramp
% ad : advance (positive), delay (negative) factor
% USE: y = ramp(t,m,ad)
N = length(t);
y = zeros(1,N);
for i = 1:N,
if t(i)>= -ad,
y(i) = m * (t(i)+ad);
end
end
function y = ustep(t,ad)
% generation of unit step
% t: time
% ad : advance (positive), delay (negative)
% USE y = ustep(t,ad)
N = length(t);
y = zeros(1,N);
for i = 1:N,
if t(i)>= -ad,
y(i) = 1;
end
end
Analytically,
n y(t)=0 fort<−3 and fort>3, so the chosen support− 5 ≤t≤5 displays the signal in a
region where the signal occurs.
n For− 3 ≤t≤−1,y(t)is 3r(t+ 3 )= 3 (t+ 3 ), which is 0 att=−3 and 6 att=−1.
n For− 1 ≤t≤0,y(t)is 3r(t+ 3 )− 6 r(t+ 1 )= 3 (t+ 3 )− 6 (t+ 1 )=− 3 t+3, which is 6 att=
−1 and 3 att=0.
n For 0≤t≤3,y(t)is 3r(t+ 3 )− 6 r(t+ 1 )+ 3 r(t)=− 3 t+ 3 + 3 t=3.
n Fort≥3 the signal is 3r(t+ 3 )− 6 r(t+ 1 )+ 3 r(t)− 3 u(t− 3 )= 3 − 3 =0.
These coincide with the signal shown in Figure 1.8. n
nExample 1.17
Consider the following script that uses the functionsrampandustepto generate a signaly(t). Obtain
analytically the formula for the signaly(t). Write a function to compute and plot the even and odd
components ofy(t).
clear all; clf
t = -5:0.01:5;
y1 = ramp(t,2,2.5);
y2 = ramp(t,-5,0);