生成并用stem函数画出这几个序列。
1、代码:
%% ------------------------------------------------------------------------%% Output Info about this m-filefprintf('\n***********************************************************\n');fprintf('Problem 2.4.1 \n\n');time_stamp = datestr(now, 31);[wkd1, wkd2] = weekday(today, 'long');fprintf(' Now is %20s, and it is %7s \n\n', time_stamp, wkd2);%% ------------------------------------------------------------------------%%%% x(n)={2,4,-3,1,-5,4,7} -3:3%% * %% x1(n) = 2x(n-3) + 3x(n+4) - x(n)x = [2,4,-3,1,-5,4,7]n = [-3:3][x11,n11] = sigshift(x,n,3)[x12,n12] = sigshift(x,n,-4)[x13,n13] = sigshift(x,n,0);[x1,n1] = sigadd(2 * x11, n11, 3 * x12, n12);[x1,n1] = sigadd(x1, n1, -x13, n13)figureset(gcf,'Color','white');stem(n,x); title('x(n)');xlabel('n'); ylabel('x');grid on;figureset(gcf,'Color','white');stem(n11,x11); title('x11(n)=x(n-3)');xlabel('n'); ylabel('x11(n)');grid on;figureset(gcf,'Color','white');stem(n12,x12); title('x12 = x(n+4)');xlabel('n'); ylabel('x11(n)');grid on;figureset(gcf,'Color','white');stem(n1,x1); title('x1 = 2x(n-3) + 3x(n+4) -x(n))');xlabel('n'); ylabel('x1(n)');grid on;
运行结果:
2、代码:
%% ------------------------------------------------------------------------%% Output Info about this m-filefprintf('\n***********************************************************\n');fprintf('Problem 2.4.2 \n\n');time_stamp = datestr(now, 31);[wkd1, wkd2] = weekday(today, 'long');fprintf(' Now is %20s, and it is %7s \n\n', time_stamp, wkd2);%% ------------------------------------------------------------------------%%%% x(n)={2,4,-3,1,-5,4,7} -3:3%% * %% x2(n) = 4x(4+n) + 5x(n+5) + 2x(n)x = [2,4,-3,1,-5,4,7]n = [-3:3][x11,n11] = sigshift(x,n,-4)[x12,n12] = sigshift(x,n,-5)[x13,n13] = sigshift(x,n,0);[x1,n1] = sigadd(4*x11, n11, 5*x12,n12);[x1,n1] = sigadd(x1,n1,2*x13,n13)figureset(gcf,'Color','white');stem(n,x); title('x(n)');xlabel('n'); ylabel('x');grid on;figureset(gcf,'Color','white');stem(n11,x11); title('x11(n)=x(4+n)');xlabel('n'); ylabel('x11(n)');grid on;figureset(gcf,'Color','white');stem(n12,x12); title('x12 = x(n+5)');xlabel('n'); ylabel('x11(n)');grid on;figureset(gcf,'Color','white');stem(n1,x1); title('x1 = 4x(4+n) + 5x(n+5) +2x(n))');xlabel('n'); ylabel('x1(n)');grid on;
运行结果:
3、代码:
%% ------------------------------------------------------------------------%% Output Info about this m-filefprintf('\n***********************************************************\n');fprintf('Problem 2.4.3 \n\n');time_stamp = datestr(now, 31);[wkd1, wkd2] = weekday(today, 'long');fprintf(' Now is %20s, and it is %7s \n\n', time_stamp, wkd2);%% ------------------------------------------------------------------------%%%% x(n)={2,4,-3,1,-5,4,7} -3:3%% * %% x3(n) = x(n+3)x(n-2) + x(1-n)x(n+1)n = [-3:3];x = [2,4,-3,1,-5,4,7];[x11,n11] = sigshift(x,n,-3); [x12,n12] = sigshift(x,n,2); [x13,n13] = sigfold(x,n); [x13,n13] = sigshift(x13,n13,1);[x14,n14] = sigshift(x,n,-1);[x21,n21] = sigmult(x11, n11, x12,n12);[x22,n22] = sigmult(x13, n13, x14,n14);[x3,n3] = sigadd(x21,n21,x22,n22);figureset(gcf,'Color','white');subplot(3,1,1); stem(n,x); title('x(n)'); xlabel('n'); ylabel('x');grid on;subplot(3,1,2); stem(n11,x11);title('x(n+3)');xlabel('n'); ylabel('x');grid on;subplot(3,1,3); stem(n12,x12);title('x(n-2)');xlabel('n'); ylabel('x');grid on;figureset(gcf,'Color','white');subplot(3,1,1); stem(n,x); title('x(n)'); xlabel('n'); ylabel('x');grid on;subplot(3,1,2); stem(n13,x13);title('x(1-n)');xlabel('n'); ylabel('x');grid on;subplot(3,1,3); stem(n14,x14);title('x(n+1)');xlabel('n'); ylabel('x');grid on;figureset(gcf,'Color','white');subplot(2,1,1); stem(n21,x21);title('x(n+3)x(n-2)');xlabel('n'); ylabel('x');grid on; subplot(2,1,2); stem(n12,x12); title('x12 = x(n+5)');title('x(n+3)');xlabel('n'); ylabel('x');grid on;xlabel('n'); ylabel('x11(n)');grid on;figureset(gcf,'Color','white');stem(n3,x3); title('x1 = 4x(4+n) + 5x(n+5) +2x(n))');xlabel('n'); ylabel('x1(n)');grid on;
运行结果:
4、代码:
%% ------------------------------------------------------------------------%% Output Info about this m-filefprintf('\n***********************************************************\n');fprintf('Problem 2.4.4 \n\n');time_stamp = datestr(now, 31);[wkd1, wkd2] = weekday(today, 'long');fprintf(' Now is %20s, and it is %7s \n\n', time_stamp, wkd2);%% ------------------------------------------------------------------------%%%% x(n)={2,4,-3,1,-5,4,7} -3:3%% * %% x4(n) = 2exp(0.5n)x(n) + cos(0.1pi*n)x(n+2)n = [-10:10];x = [zeros(1, 7), 2, 4, -3, 1, -5, 4, 7, zeros(1,7)];x11 = exp(0.5*n);x12 = cos(0.1*pi*n);[x13,n13] = sigshift(x,n,-2);[x21,n21] = sigmult(2*x11, n, x, n);[x22,n22] = sigmult(x12, n, x13, n13);[x4,n4] = sigadd(x21, n21, x22, n22);%x4 = 2*exp(0.5*n)*x(n) + cos(0.1*pi*n)*x11(n11);figureset(gcf,'Color','white');subplot(3,1,1); stem(n, x); title('x(n)'); xlabel('n'); ylabel('x');grid on;subplot(3,1,2); stem(n, x11);title('exp(0.5n)'); xlabel('n'); ylabel('x');grid on;subplot(3,1,3); stem(n, x12);title('cos(0.1\pin)');xlabel('n'); ylabel('x');grid on;figureset(gcf,'Color','white');subplot(3,1,1); stem(n,x); title('x(n)'); xlabel('n'); ylabel('x');grid on;subplot(3,1,2); stem(n21, x21);title('2exp(0.5n)*x(n)'); xlabel('n'); ylabel('x');grid on;subplot(3,1,3); stem(n22, x22);title('cos(0.1\pin)*x(n+2)');xlabel('n'); ylabel('x');grid on;figureset(gcf,'Color','white');stem(n4,x4); title('x4(n) = 2exp(0.5n)x(n) + cos(0.1pi*n)x(n+2)');xlabel('n'); ylabel('x4(n)');grid on;
运行结果: