You are on page 1of 28

adfaenflkejflkewfj%%

% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')
Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end
%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end
%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function y = ramp(t, m, ad)
N = length(t);%%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end %%
% Example 2.12
%%
clear all; clf
Ts=0.01;Tend=2
t=0:Ts:Tend;M=6
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(1)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{64}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=4
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(2)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{16}(t)')

Ts=0.01;Tend=2
t=0:Ts:Tend;M=2
h0=ustep(t,0)-ustep(t,-1);N=2^M
y=h0/N;
for k=1:N-1,
y=y+(1/N)*(ustep(t,-k/N)-ustep(t,-1-k/N));
end
t1=0:Ts:(length(y)-1)*Ts;
figure(3)
plot(t1,y);axis([0 2 0 1.1]); grid; xlabel('t (sec)');
ylabel('y_{2}(t)')

function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

%%
% Example 2.17 -- Convolution using MATLAB
%%
% example 2_17
clear all; clf
Ts=0.01; delay=1; Tend=2.5; t=0:Ts:Tend;
% (a)
x1=ustep(t,0)-ustep(t,-delay); h1=ustep(t,0)-ustep(t,-2*delay);
% (b)
x2=ramp(t,1,0)+ramp(t,-2,-1)+ramp(t,1,-2); h2=x2;
% (c)
x3=exp(-2*t); h3=exp(-10*t);
y1=Ts*conv(x1,h1); % (a)
y2=Ts*conv(x2,h2); % (b)
y3=Ts*conv(x3,h3); % (c)
t1=0:Ts:length(y1)*Ts-Ts;
t2=0:Ts:length(y2)*Ts-Ts;
t3=0:Ts:length(y3)*Ts-Ts;
figure(1)
subplot(311)
plot(t,x1); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_1(t)');
subplot(312)
plot(t,h1); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_1(t)');
subplot(313)
plot(t1,y1); axis([0 5 -0.1 1.1]); grid; ylabel('y_1(t)');
figure(2)
subplot(311)
plot(t,x2); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_2(t)');
subplot(312)
plot(t,h2); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_2(t)');
subplot(313)
plot(t2,y2); axis([0 5 -0.1 1.1]); grid; ylabel('y_2(t)');
figure(3)
subplot(311)
plot(t,x3); axis([0 2.5 -0.1 1.2]); grid;ylabel('x_3(t)');
subplot(312)
plot(t,h3); axis([0 2.5 -0.1 1.2]); grid;ylabel('h_3(t)');
subplot(313)
plot(t3,y3); axis([0 5 -0.1 1.1]); grid; ylabel('y_3(t)');
function 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
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end
y = zeros(1, N);
for i = 1:N
if t(i) >= -ad ------------ㅇ=lksdfnslkdfnkl
y(i) = m * (t(i) + ad);
end
end
end
function y=ustep(t,ad)
N=length(t);
y=zeros(1,N);
for i=1:N
if t(i)>= -ad
y(i) = 1;
end
end
end

You might also like