《DSP using MATLAB》Problem 5.27
阿新 • • 發佈:2018-08-11
rcu bubuko ylabel alt this xlabel -- 運行 color
代碼:
%% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Output Info about this m-file fprintf(‘\n***********************************************************\n‘); fprintf(‘ <DSP using MATLAB> Problem 5.27 \n\n‘); banner(); %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ % ------------------------------------------------------------------- % % ------------------------------------------------------------------- N = 4; n1 = [0:3]; x1 = [1, 3, 2, -1]; n2 = [0:3]; x2 = [2, 1, 0, -1]; % ----------------------------------- % 1st way to Linear-Convolution % ----------------------------------- [y1, ny1] = conv_m(x1, n1, x2, n2); % -------------------------------------------- % 2nd way ---- circular conv(FREQ domain) % -------------------------------------------- N2 = length(x1)+length(x2)-1; y2 = circonvf(x1, x2, N2); ny2 = ny1; % --------------------------------------- % 3rd way --- Cir Conv (TIME domain) % --------------------------------------- N3 = length(x1)+length(x2)-1; y3 = circonvt(x1, x2, N3); ny3 = ny1; N4 = 5; y4 = circonvt(x1, x2, N4); ny4 = [0:N4-1]; figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.27 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=4‘); 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=4‘); grid on; figure(‘NumberTitle‘, ‘off‘, ‘Name‘, ‘P5.27 Convolution‘) set(gcf,‘Color‘,‘white‘); subplot(2,2,1); stem(ny1, y1); xlabel(‘n‘); ylabel(‘y1(n)‘); title(‘Linear-Conv y1(n), N=7‘); grid on; subplot(2,2,2); stem(ny2, y2); %axis([-N/2, N/2, -0.5, 50.5]); xlabel(‘n‘); ylabel(‘y2(n)‘); title(‘Cir-Conv(FREQ domain) y2(n), N=7‘); 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(TIME domain) y3(n), N=7‘); grid on; subplot(2,2,4); stem(ny4, y4); %axis([-N/2, N/2, -0.5, 50.5]); xlabel(‘n‘); ylabel(‘y4(n)‘); title(‘Cir-Conv(TIME domain) y4(n), N=5‘); grid on;
運行結果:
上圖中,y1是長度為7的線性卷積結果,y4是5點圓周卷積結果。
《DSP using MATLAB》Problem 5.27