《DSP using MATLAB》Problem 4.8

代码:

%% ----------------------------------------------------------------------------
%%            Output Info about this m-file
fprintf('
***********************************************************
');
fprintf('        <DSP using MATLAB> Problem 4.8 

');

banner();
%% ----------------------------------------------------------------------------


%% -----------------------------------------------------
%%             x3(n)=x1(n)*x2(n)
%%          sigma(x3)=[sigma(x1)] [sigma(x2)]
%% -----------------------------------------------------
num = 10;
x1 = 0 + (2-0)*rand(1, 2*num+1);
n1 = [-num:num];
sum_x1 = sum(x1(:))

x2 = 0 + (2-0)*rand(1, 2*num+1);
n2 = [-num:num];
sum_x2 = sum(x2(:))

figure('NumberTitle', 'off', 'Name', 'Problem 4.8 Sequence x1 and x2');
set(gcf,'Color','white'); 
%hist(x1,x_axis); 
subplot(2,1,1); stem(n1, x1);
title('Uniformly Distributed Random Numbers x1(n)');
xlabel('n'); ylabel('x1(n)'); grid on;
subplot(2,1,2); stem(n2, x2);
title('Uniformly Distributed Random Numbers x2(n)');
xlabel('n'); ylabel('x2(n)'); grid on;


[x3, n3] = conv_m(x1, n1, x2, n2);
sum_x3 = sum(x3(:))
sum_chk = sum_x1 * sum_x2

figure('NumberTitle', 'off', 'Name', 'Problem 4.8 Sequence x3');
set(gcf,'Color','white'); 
%hist(x1,x_axis); 
%subplot(2,1,1); 
stem(n3, x3);
title('Sequence x3(n)=x1*x2 ');
xlabel('n'); ylabel('x3(n)'); grid on;

  运行结果:

牢记: 1、如果你决定做某事,那就动手去做;不要受任何人、任何事的干扰。2、这个世界并不完美,但依然值得我们去为之奋斗。
原文地址:https://www.cnblogs.com/ky027wh-sx/p/8436672.html