|
大家看看哪里有错误阿??
Function y=circonv1(x1,x2,N)
%realize circular convolution use direct method
%y=circonv(x1,x2,N)
%y: output sequence
%x1,x2: input sequences
%N: circulation length
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)=cirshiftd(x2,n-1,N);
end
Y=x1*H;
function y=circonv2(x1,x2,N)
%realize cicular convolution use dft method
%y= circonv2(x1,x2,N)
%y=: output sequence
%x1,x2: input sequences
%N: circulation length
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:15]; m=[0:1:7];
N1=length(n);N2=length(n);
xn=0.9.^n;
hn=ones(1,N2);
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(ny1,y2n);
subplot(3,1,3);
stem(ny2,y3n);
axis[0,25,0,6]; |