《DSP using MATLAB》Problem 5.31

时间:2022-06-08 16:15:45

《DSP using MATLAB》Problem 5.31

第3小题:

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.31 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % -------------------------------------------------------------
% x3(n) --- N-point circular convolution of x1(n) an x2(n)
% x4(n) --- Linear convolution
% e(n) --- error sequence
% ------------------------------------------------------------- N = 15;
n1 = [0:9];
x1 = 0.8.^n1;
N1 = length(x1); n2 = [0:9];
x2 = (-0.8).^n2;
N2 = length(x2); % --------------------------------------------
% 1st way ---- time domain
% --------------------------------------------
y1 = circonvt(x1, x2, N)
ny1 = [0:N-1]; % --------------------------------------------
% 2nd way ---- DFT method
% -------------------------------------------- y2 = circonvf(x1, x2, N);
ny2 = [0:N-1]; % --------------------------------------------
% 3rd way --- circulant matrix
% -------------------------------------------- y3 = circonvt_v3(x1, x2, N);
ny3 = [0:N-1]; % ---------------------------------------
% Linear convolution
% --------------------------------------- [y4, ny4] = conv_m(x1, n1, x2, n2); e1 = y1 - y4(1:N); figure('NumberTitle', 'off', 'Name', 'P5.31.3 x1(n) and x2(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(n1, x1);
xlabel('n'); ylabel('x1(n)');
title('x1(n)=0.8^n N=10'); grid on;
subplot(2,1,2); stem(n2, x2);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('n'); ylabel('x2(n)');
title('x2(n)=(-0.8)^n N=10'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.31.3 Cir-Conv and Linear-Conv')
set(gcf,'Color','white');
subplot(2,2,1); stem(ny1, y1);
xlabel('n'); ylabel('y1(n)');
title('Cir-Conv (Time domain), y1(n)'); grid on;
subplot(2,2,2); stem(ny2, y2);
%axis([0, N, 0, 1]);
xlabel('n'); ylabel('y2(n)');
title('Cir-Conv (DFT method), y2(n)'); grid on;
subplot(2,2,3); stem(ny3, y3);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('n'); ylabel('y3(n)');
title('Cir-Conv (circulant matrix), y3(n)'); grid on;
subplot(2,2,4); stem(ny4, y4);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('n'); ylabel('y4(n)');
title('Linear-Conv, y4(n)'); grid on;

  运行结果:

《DSP using MATLAB》Problem 5.31

这两个序列的圆周卷积结果(3种方法)、线性卷积结果

《DSP using MATLAB》Problem 5.31

《DSP using MATLAB》Problem 5.31

《DSP using MATLAB》Problem 5.31

其它小题的图这里不放了,大致步骤见文中程序。