x = [3, 11, 7, 0, -1, 4, 2]; nx = [-3:3]; h = [2, 3, 0, -5, 2, 1]; nh = [-1:4]; [y,ny] = conv_m(x,nx,h,nh)
结果:
下面展示一些具体步骤:
%% ------------------------------------------------------------------------ %% Output Info about this m-file fprintf(' *********************************************************** '); fprintf(' <DSP using MATLAB> Exameple 2.8 '); time_stamp = datestr(now, 31); [wkd1, wkd2] = weekday(today, 'long'); fprintf(' Now is %20s, and it is %7s ', time_stamp, wkd2); %% ------------------------------------------------------------------------ % Input sequence x = [3, 11, 7, 0, -1, 4, 2]; nx = [-3:3]; % Impulse Response sequence h = [2, 3, 0, -5, 2, 1]; nh = [-1:4]; [y,ny] = conv_m(x,nx,h,nh) figure('NumberTitle', 'off', 'Name', 'Exameple 2.8') set(gcf,'Color','white'); % x(k) and h(k) subplot(2, 2, 1); stem(nx, x); axis([-5, 5, -6, 12]); grid on; hold on; stem(nh+0.1, h, 'r:'); a = axis; text(a(2)+0.5, a(3), 'k'); text(-1.5, 11, 'Solid :x Dashed :h'); title('x(k) & h(k)'); hold off; % x(k) and h(-k) subplot(2, 2, 2); stem(nx, x);axis([-5, 5, -6, 12]); grid on; hold on; stem(-fliplr(nh)+0.1, fliplr(h), 'r:'); a = axis; text(a(2)+0.5, a(3), 'k'); text(-0.5, -1, 'n=0'); text(-1.5, 11, 'Solid :x Dashed :h'); title('x(k) and h(-k)'); hold off; % x(k) and h(-1-k) subplot(2, 2, 3); stem(nx, x);axis([-5, 5, -6, 12]); grid on; hold on; stem(-fliplr(nh)+0.1-1, fliplr(h), 'r:'); a = axis; text(a(2)+0.5, a(3), 'k'); text(-1-0.5, -1, 'n=-1'); text(-1.5, 11, 'Solid :x Dashed :h'); title('x(k) and h(-1-k)'); hold off; % x(k) and h(2-k) subplot(2, 2, 4); stem(nx, x);axis([-5, 5, -6, 12]); grid on; hold on; stem(-fliplr(nh)+0.1+2, fliplr(h), 'r:'); a = axis; text(a(2)+0.5, a(3), 'k'); text(2-0.5, -1, 'n=2'); text(-1.5, 11, 'Solid :x Dashed :h'); title('x(k) and h(2-k)'); hold off;
运行结果:
左上角是x(k)和h(k);右上角是x(k)和h(-k),对h(k)进行了反转;左下角是x(k)和h(-1-k),对h(k)进行了反转后再向左移一位;
右下角是x(k)和h(2-k),对h(k)进行了反转后再向右移两位;