1、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.1 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = -5; n2 = 15; n = [n1:n2]; x1 = 3 * impseq(-2,n1,n2) + 2 * impseq(0,n1,n2) - impseq(3,n1,n2) + 5 * impseq(7,n1,n2); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.1') set(gcf,'Color','white'); stem(n,x1); title('x1 Sequence'); xlabel('$n$', 'interpreter', 'latex', 'fontsize', 15); ylabel('x1(n)', 'fontsize', 15); grid on;
运行结果:
2、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.2 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = -10; n2 = 10; n = [n1:n2]; x2 = exp(-5) * impseq(-10,n1,n2) + exp(-4) * impseq(-8,n1,n2) + exp(-3)*impseq(-6,n1,n2); x2 = x2 + exp(-2)*impseq(-4,n1,n2) + exp(-1)*impseq(-2,n1,n2) + exp(0) * impseq(0,n1,n2); x2 = x2 + exp(-1)*impseq(2,n1,n2) + exp(-2)*impseq(4,n1,n2) + exp(-3)*impseq(6,n1,n2); x2 = x2 + exp(-4)*impseq(8,n1,n2) + exp(-5)*impseq(10,n1,n2); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.2') set(gcf,'Color','white'); stem(n,x2); title('x2 Sequence'); xlabel('n'); ylabel('x2(n)'); grid on;
运行结果:
3、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.3 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = -5; n2 = 25; n = [n1:n2]; x3 = 10*stepseq(0,n1,n2) + (-5)*stepseq(5,n1,n2) + (-10)*stepseq(10,n1,n2)+ 5*stepseq(15,n1,n2); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.3') set(gcf,'Color','white'); stem(n,x3); title('x3 Sequence'); xlabel('n'); ylabel('x3(n)'); grid on;
运行结果:
4、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.4 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = -30; n2 = 30; n = [n1:n2]; x4 = exp(0.1*n) .* stepseq(-20,n1,n2) - exp(0.1*n) .* stepseq(10,n1,n2); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.4') set(gcf,'Color','white'); stem(n,x4); title('x4 Sequence'); xlabel('n'); ylabel('x4(n)'); grid on;
运行结果:
5、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.5 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = -200; n2 = 200; n = [n1:n2]; x5 = 5*(cos(0.49*pi*n) + cos(0.51*pi*n)); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.5') set(gcf,'Color','white'); stem(n,x5); title('x5 Sequence'); xlabel('n'); ylabel('x5(n)'); grid on;
运行结果:
6、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.6 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = -200; n2 = 200; n = [n1:n2]; x6 = 2 * cos(0.01*pi*n) .* cos(0.5*pi*n); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.6') set(gcf,'Color','white'); stem(n,x6); title('x6 Sequence'); xlabel('n'); ylabel('x6(n)'); grid on;
运行代码:
7、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.7 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = 0; n2 = 100; n = [n1:n2]; x7 = exp(-0.05*n) .* sin(0.1*pi*n + pi/3); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.7'); set(gcf,'Color','white'); stem(n,x7); title('x7 Sequence'); xlabel('n'); ylabel('x7(n)'); grid on;
运行结果:
8、代码:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Problem 2.1.8 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ n1 = 0; n2 = 100; n = [n1:n2]; x8 = exp(0.01*n) .* sin(0.1*pi*n); figure('NumberTitle', 'off', 'Name', 'Problem 2.1.8'); set(gcf,'Color','white'); stem(n,x8); title('x8 Sequence'); xlabel('n'); ylabel('x8(n)'); grid on;
运行结果: