%序列 x = [3,11,7,0,-1,4,2]; h=[2,3,0,-5,2,1] %用兩種方法求兩者的線性卷積y clc; %清屏 clear all; x = [3,11,7,0,-1,4,2]; %x的序列 nx = [0:length(x)-1]; %x的序列對應的長度 h=[2,3,0,-5,2,1]; %h序列 nh = [0:length(h)-1]; %h序列對應的長度 y = conv(x,h); %利用conv函數進行x,h的卷積 ny = [0:1:length(y)-1]; %函數卷積y的長度 subplot(1,3,1); %分為1行3列 stem(nx,x); %x序列的圖像 xlabel('n'); ylabel('幅度'); title('X'); subplot(1,3,2); %h序列的圖像 stem(nh,h); xlabel('h'); ylabel('幅度'); title('h'); subplot(1,3,3); %線性卷積的序列 stem(ny,y); xlabel('y'); ylabel('幅度'); title('線性卷積');