当n?1时:
1 0 0 取和得到圆卷积为6。
当n?2时: 1 1 1 取和得到圆卷积为6。
当n?3时: 1 2 2 取和得到圆卷积为6。
当n?4时: 1 3 3 取和得到圆卷积为6。
画出波形如下:
1 0 0 1 3 3 1 2 2 1 1 1 1 0 0 1 0 0 1 3 3 1 2 2 1 1 1 1 0 0 1 0 0 1 3 3 1 2 2 1 1 1 1 0 0 1 0 0
四、仿真实验
Matlab程序设计如下:
编写的循环卷积程序:
方法一:直接根据定义计算,程序编辑如下:
function y=circonv1(x1,x2,N) if length(x1)>N
error('N must not be less than length of x1') end
if length(x2)>N
error('N must not be less than length of x2') end
x1=[x1,zeros(1,N-length(x1))]; x2=[x2,zeros(1,N-length(x2))]; n=[0:1:N-1];
x2=x2(mod(-n,N)+1); H=zeros(N,N); for n=1:1:N
H(n,:)=cd(x2,n-1,N); end
y=x1*H';
function y=cd(x,m,N) if length(x)>N error end
x=[x zeros(1,N-length(x))]; n=[0:1:N-1]; n=mod(n-m,N); y=x(n+1);
方法二:根据性质先分别求两个序列的N点DFT,并相乘,然后取IDFT以得到循环卷积
function y=circonv2(x1,x2,N) if length(x1)>N error('N must not be less than length of x1') end
if length(x2)>N error('N must not be less than length of x2') end
X1k=fft(x1,N); X2k=fft(x2,N);
Yk=X1k.*X2k; y=ifft(Yk);
if((all(imag(x1)==0))&&(all(imag(x2)==0))) y=real(y); end
编写的主程序:
n=[0:1:4];m=[0:1:4];
N1=length(n);N2=length(m); xn=ones(1,5); hn=[0,0,1,2,3]; y1n=conv(xn,hn);
y2n=circonv2(xn,hn,N1+N2-1); y3n=circonv1(xn,hn,N1); ny1=[0:1:length(y1n)-1]; ny2=[0:1:length(y3n)-1]; subplot(3,1,1); stem(ny1,y1n); subplot(3,1,2); stem(ny1,y2n); subplot(3,1,3); stem(ny2,y3n);
运行结果如下:
图表 1实验结果
与理论结果一致。
五、实验小结
通过本次实验理解并掌握了循环卷积与线性卷积的概念,也掌握了两者之间的关系。学会了matlab中线性卷积函数,以及如何编写循环卷积。在仿真过程中出现了一些问题,由于matlab提供线性卷积函数,则只需要自己编写循环卷积,在编写过程中,没有注意到matlab中的大小写的严格区别,导致程序运行错误。经过反复检查之后发现了错误,经改正后得到了正确的运行结果。收获很大。