首页 > 其他 > 详细

《DSP using MATLAB》Problem 2.4

时间:2017-11-19 11:03:05      阅读:365      评论:0      收藏:0      [点我收藏+]

技术分享图片

生成并用stem函数画出这几个序列。

1、代码:

%% ------------------------------------------------------------------------
%%            Output Info about this m-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> 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)


figure
set(gcf,‘Color‘,‘white‘);
stem(n,x); title(‘x(n)‘);
xlabel(‘n‘); ylabel(‘x‘);grid on;

figure
set(gcf,‘Color‘,‘white‘);
stem(n11,x11); title(‘x11(n)=x(n-3)‘);
xlabel(‘n‘); ylabel(‘x11(n)‘);grid on;

figure
set(gcf,‘Color‘,‘white‘);
stem(n12,x12); title(‘x12 = x(n+4)‘);
xlabel(‘n‘); ylabel(‘x11(n)‘);grid on;

figure
set(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-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> 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)

figure
set(gcf,‘Color‘,‘white‘);
stem(n,x); title(‘x(n)‘);
xlabel(‘n‘); ylabel(‘x‘);grid on;

figure
set(gcf,‘Color‘,‘white‘);
stem(n11,x11); title(‘x11(n)=x(4+n)‘);
xlabel(‘n‘); ylabel(‘x11(n)‘);grid on;

figure
set(gcf,‘Color‘,‘white‘);
stem(n12,x12); title(‘x12 = x(n+5)‘);
xlabel(‘n‘); ylabel(‘x11(n)‘);grid on;

figure
set(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-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> 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);

figure
set(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;

figure
set(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;

figure
set(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;

figure
set(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-file
fprintf(‘\n***********************************************************\n‘);
fprintf(‘        <DSP using MATLAB> 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);
figure
set(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;

figure
set(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;

figure
set(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;

  运行结果:

技术分享图片

技术分享图片

技术分享图片

 

《DSP using MATLAB》Problem 2.4

原文:http://www.cnblogs.com/ky027wh-sx/p/7859041.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!