Commit 2240a0c5 authored by 袁通's avatar 袁通
Browse files

add Problem 2.4 in LAB 2

parent 44b751ef
Loading
Loading
Loading
Loading

LAB2/P2_4_a.m

0 → 100644
+14 −0
Original line number Diff line number Diff line
% Problem 2.4(a)

x1 = [1 1 1 1 0 0 0 0 0 0];
nx1 = 0:1:9;

h1 = [1 -1 3 0 1];
h2 = [0 2 5 4 -1];
nh1 = 0:1:4;

subplot(3, 1, 1), stem(nx1, x1), title("x_1[n]");
subplot(3, 1, 2), stem(nh1, h1), title("h_1[n]");
subplot(3, 1, 3), stem(nh1, h2), title("h_2[n]");

saveas(gcf, "P2_4_a_out.png");
 No newline at end of file

LAB2/P2_4_b.m

0 → 100644
+17 −0
Original line number Diff line number Diff line
% Problem 2.4(b)

x1 = [1 1 1 1 0 0 0 0 0 0];
nx1 = 0:1:9;

h1 = [1 -1 3 0 1];
h2 = [0 2 5 4 -1];
nh1 = 0:1:4;

y1 = conv(x1, h1);
y2 = conv(h1, x1);
ny = nh1(1)+nx1(1):1:nh1(end)+nx1(end)

subplot(2,1,1), stem(ny, y1), title("y_1[n]=x_1[n]*h_1[n]");
subplot(2,1,2), stem(ny, y2), title("y_2[n]=h_1[n]*x_1[n]");

saveas(gcf, "P2_4_b_out.png")
 No newline at end of file

LAB2/P2_4_c.m

0 → 100644
+17 −0
Original line number Diff line number Diff line
% Problem 2.4(c)

x1 = [1 1 1 1 0 0 0 0 0 0];
nx1 = 0:1:9;

h1 = [1 -1 3 0 1];
h2 = [0 2 5 4 -1];
nh1 = 0:1:4;

y1 = conv(x1, h1+h2);
y2 = conv(x1, h1) + conv(x1, h2);
ny = nh1(1)+nx1(1):1:nh1(end)+nx1(end)

subplot(2,1,1), stem(ny, y1), title("y_1[n]=x_1[n]*(h_1[n]+h_2[n]");
subplot(2,1,2), stem(ny, y2), title("y_2[n]=x_1[n]*h_1[n]+x_1[n]*h_2[n]");

saveas(gcf, "P2_4_c_out.png")

LAB2/P2_4_d.m

0 → 100644
+18 −0
Original line number Diff line number Diff line
% Problem 2.4(d)

x1 = [1 1 1 1 0 0 0 0 0 0];
nx1 = 0:1:9;

h1 = [1 -1 3 0 1];
h2 = [0 2 5 4 -1];
nh1 = 0:1:4;

y1 = conv(conv(x1, h1), h2);
y2 = conv(x1, conv(h1, h2));

ny = nh1(1)+nx1(1):1:nh1(end)+nh1(end)+nx1(end)

subplot(2,1,1), stem(ny, y1), title("y_2[n]=(x_1[n]*h_1[n])*h_2[n]");
subplot(2,1,2), stem(ny, y2), title("y_1[n]=x_1[n]*(h_1[n]+h_2[n])");

saveas(gcf, "P2_4_d_out.png")

LAB2/P2_4_e.m

0 → 100644
+38 −0
Original line number Diff line number Diff line
% Problem 2.4(e)

x1 = [1 1 1 1 0 0 0 0 0 0];
nx1 = 0:1:9;

h1 = [1 -1 3 0 1];
h2 = [0 2 5 4 -1];
nh1 = 0:1:4;

he1 = h1;
he2 = [0 0 h1];
nhe2 = 1:1:6;

nye1 = nh1(1)+nx1(1):1:nh1(end)+nx1(end);
nye2 = nhe2(1)+nx1(1):1:nhe2(end)+nx1(end);

ye1 = conv(x1, he1);
ye1_inter = conv(he1, x1)
ye2 = conv(x1, he2);
ye2_inter = conv(he2, x1)

subplot(3,1,1);
hold on
stem(nye1, ye1);
stem(nye1, ye1_inter);

subplot(3,1,2);
hold on
stem(nye2, ye2);
stem(nye2, ye2_inter);

subplot(3,1,3);
hold on
stem(nye1, ye1);
stem(nye2, ye2);

saveas(gcf, "P2_4_e.png");
Loading