1 循环卷积
function[yn]=circularconvolution(xn,hn,N);
N=input("N=");
xn=[2 2 1 1 zeros(1,N-4)];
hn=[1 2 0 1 zeros(1,N-4)];
k=[0:1:N-1];
n=[0:1:N-1];
Wn=exp(-j*2*pi/N);
kn=k"*n;
Wn_kn=Wn.^kn;
Xk=xn*Wn_kn;
k=[0:1:N-1];
n=[0:1:N-1];
Wn=exp(-j*2*pi/N);
kn=k"*n;
Wn_kn=Wn.^kn;
Hk=hn*Wn_kn;
Yk=Xk.*Hk;
k=[0:1:N-1];
n=[0:1:N-1];
Wn=exp(-j*2*pi/N);
kn=k"*n;
Wn_kn=Wn.^(-kn);
yn1=(Yk*Wn_kn)/N;
yn=real(yn1);
输入N=4 ,6 ,8 ,10
结果[6 7 6 5][3 6 5 5 4 1][2 6 5 5 4 1 1 0][2 6 5 5 4 1 1 0 0 0]
当N 大于6时,循环卷积与线性卷积结果一致。
2
n=0:47;
xn1 = cos(n*pi/6);
xn2 = cos(n*pi/3);
hn=[-0.0322,-0.0531,-0.0450,0.0000,0.0750,0.1592,0.2251,
0.2500,0.2251,0.1592,0.0750,0.0000,-0.0450,-0.0531,-0.0322]
N=length(hn)+47;
xn=xn1+xn2;
h1n = [hn,zeros(1,47)];
x1n = [xn,zeros(1,14)];
k=[0:1:N-1];
n=[0:1:N-1];
Wn=exp(-j*2*pi/N);
kn=k"*n;
Wn_kn=Wn.^kn;
Xk = x1n*Wn_kn;
k=[0:1:N-1];
n=[0:1:N-1];
Wn=exp(-j*2*pi/N);
kn = k"*n;
Wn_kn = Wn.^kn;
Hk = h1n*Wn_kn;
Yk=Xk.*Hk;
k=[0:1:N-1];
n=[0:1:N-1];
Wn=exp(-j*2*pi/N);
kn=k"*n;
Wn_kn=Wn.^(-kn);
yn1 = (Yk*Wn_kn)/N;
yn = real(yn1);
stem(0:61,yn);
3
n=0:39; k=10;
xn=cos(pi*n/10)+cos(2*n*pi/5); hn=[1,1,1,1,1];
m=length(hn);
subplot(221)
stem(n,xn,".")
xlabel("n"); ylabel("Amplitude"); title("x(n)");
subplot(223)
stem(n,[hn,zeros(1,35)],".")
axis([0,40,0,1.2]);
xlabel("n"); ylabel("Amplitude"); title("h(n)");
xk_n1=xn(1:k); yk_n1=conv(hn,xk_n1);
add_zeros1=zeros(1,length(n)-length(yk_n1)+m-1);
yk_n1=[yk_n1,add_zeros1];
subplot(522)
stem(0:length(yk_n1)-1,yk_n1,".")
xlabel("n"); ylabel("Amplitude"); legend("y0")
xk_n2=xn(1+k:2*k); yk_n2=conv(hn,xk_n2);
add_zeros21=zeros(1,k);
add_zeros22=zeros(1,length(n)-length(yk_n2)-k+m-1);
yk_n2=[add_zeros21,yk_n2,add_zeros22];
subplot(524)
stem(0:length(yk_n2)-1,yk_n2,".")
xlabel("n"); ylabel("Amplitude");legend("y1")
xk_n3=xn(1+2*k:3*k); yk_n3=conv(hn,xk_n3);
add_zeros31=zeros(1,2*k);
add_zeros32=zeros(1,length(n)-length(yk_n3)-2*k+m-1);
yk_n3=[add_zeros31,yk_n3,add_zeros32];
subplot(526)
stem(0:length(yk_n3)-1,yk_n3,".")
xlabel("n"); ylabel("Amplitude"); legend("y2",2)
xk_n4=xn(1+3*k:4*k); yk_n4=conv(hn,xk_n4);
add_zeros4=zeros(1,k*3);
yk_n4=[add_zeros4,yk_n4];
subplot(528)
stem(0:length(yk_n4)-1,yk_n4,".")
xlabel("n"); ylabel("Amplitude"); legend("y3",2)
y1=yk_n1(k+1:k+m-1)+yk_n2(k+1:k+m-1);
y2=yk_n2(2*k+1:2*k+m-1)+yk_n3(2*k+1:2*k+m-1);
y3=yk_n3(3*k+1:3*k+m-1)+yk_n4(3*k+1:3*k+m-1);
yk=[yk_n1(1:k),y1,yk_n2(k+m:k*2),y2,yk_n3(2*k+m:3*k),y3,yk_n4(3*k+m:4*k)]; subplot(5,2,10)
stem(0:length(yk)-1,yk,".")
xlabel("n"); ylabel("Amplitude"); legend("y(n)",3) ;
循环卷积与线性卷积_dsp循环卷积与线性卷积相关文章: