《DSP using MATLAB》Problem 5.30

时间:2022-04-21 08:38:49

《DSP using MATLAB》Problem 5.30

代码:

%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
%% Output Info about this m-file
fprintf('\n***********************************************************\n');
fprintf(' <DSP using MATLAB> Problem 5.29 \n\n'); banner();
%% ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % --------------------------------------------------------
% x1(n) and x2(n) ---- N-point sequence
% y(n) = x1(n) Cir-Conv x2(n)
% --------------------------------------------------------
N = 8;
n1 = [0:N-1];
x1 = [9, 4, -1, 4, -4, -1, 8, 3];
N1 = length(x1); n2 = [0:N-1];
x2 = [-5, 6, 2, -7, -5, 2, 2, -2];
N2 = length(x2); sum_x1 = sum( x1( min(n1)+1 : max(n1)+1 ) )
sum_x2 = sum( x2( min(n2)+1 : max(n2)+1 ) ) answer = sum_x1 * sum_x2 % --------------------------------------------
% 1st way TIME domain
% --------------------------------------------
%N = 10;
n = [0:N-1]; y1 = circonvt(x1, x2, N);
sum_y1 = sum( y1( min(n)+1 : max(n)+1 ) ) % --------------------------------------------
% 2nd way ---- circular conv(FREQ domain)
% --------------------------------------------
y2 = circonvf(x1, x2, N);
sum_y2 = sum( y2( min(n)+1 : max(n)+1 ) ) % --------------------------------------------
% 3rd way --- Cir Conv (Circulant Matrix)
% --------------------------------------------
y3 = circonvt_v3(x1, x2, N);
sum_y3 = sum( y3( min(n)+1 : max(n)+1 ) ) figure('NumberTitle', 'off', 'Name', 'P5.29 x1(n) and x2(n)')
set(gcf,'Color','white');
subplot(2,1,1); stem(n1, x1);
xlabel('n'); ylabel('x1(n)');
title('x1(n) N=8'); 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) N=8'); grid on; figure('NumberTitle', 'off', 'Name', 'P5.29 Cir-Conv, N=8')
set(gcf,'Color','white');
subplot(3,1,1); stem(n, y1);
xlabel('n'); ylabel('y1(n)');
title('Time Domain, y1(n)'); grid on;
subplot(3,1,2); stem(n, y2);
%axis([0, N, 0, 1]);
xlabel('n'); ylabel('y2(n)');
title('FREQ domain, y2(n)'); grid on;
subplot(3,1,3); stem(n, y3);
%axis([-N/2, N/2, -0.5, 50.5]);
xlabel('n'); ylabel('y3(n)');
title('Circulant Matrix, y3(n)'); grid on;

  运行结果:

《DSP using MATLAB》Problem 5.30

圆周卷积结果,3种计算方法。

《DSP using MATLAB》Problem 5.30

《DSP using MATLAB》Problem 5.30