📄 conv_ovlap.m
字号:
% Computation linear convolution using overlap-add method
clear
n=0:29;
x=[1 2 0.5 2 2 0.5 4 4 3 0.5 3 1 2 1 0 2 3 3 0.5 2 3 4 1 2 0 0 0 0 0 0];
h=[4 3 5 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
N=4;M=6;
c=zeros(1,30);
c1=c;c2=c;c3=c;c4=c;
j0=x([1:6]);j1=x([7:12]);j2=x([13:18]);j3=x([19:24]);
j0=[j0,zeros(1,24)];
j1=[j1,zeros(1,24)];
j2=[j2,zeros(1,24)];
j3=[j3,zeros(1,24)];
%==========================================================
L=10;
RN=u(n)-u(n-L);
for k=1:4;
hs=h([1:10]);
l=length(n);
v=zeros(1,L);
hs=[hs,hs,hs];o=hs;
hs=fliplr(hs);
d=ones(1,length(n));
subplot(411)
stem(n,x,'.');title('分段卷积演示')
subplot(412)
stem(n,h,'.');ylabel('h((n))N');
for i=0:L-1;
subplot(413)
stem(n,hs.*RN,'r.');
ylabel('h((n-m))N');
if k==1, a=j0; end
if k==2, a=j1; end
if k==3, a=j2; end
if k==4, a=j3; end
subplot(411)
stem(n,a,'.');title('分段卷积演示')
w=hs(l);
for p=1:l-1; hs(l-p+1)=hs(l-p); end
hs(1)=w;
subplot(414)
if k==1, stem(n,c1,'.'), end
if k==2, stem(n,c2,'.'), end
if k==3, stem(n,c3,'.'), end
if k==4, stem(n,c4,'.'), end
ylabel('循环卷积y(n)');
if k==1, pause, end
b=hs.*RN; e=a.*b; g=e*d';
if k==1, c1(i+1)=g; end
if k==2, c2(i+1)=g; end
if k==3, c3(i+1)=g; end
if k==4, c4(i+1)=g; end
end
end
for i=0:M-1;
w=c2(l);
for p=1:l-1;
c2(l-p+1)=c2(l-p);
end
c2(1)=w;
end
for i=0:2*M-1
w=c3(l);
for p=1:l-1;
c3(l-p+1)=c3(l-p);
end
c3(1)=w;
end
for i=0:3*M-1
w=c4(l);
for p=1:l-1;
c4(l-p+1)=c4(l-p);
end
c4(1)=w;
end
c=c1+c2+c3+c4;
figure(2)
subplot(611),stem(n,c1,'.');ylabel('y1')
title('Computation of linear convolution using overlap add method')
subplot(612),stem(n,c2,'.');ylabel('y2')
subplot(613),stem(n,c3,'.');ylabel('y3')
y=conv(h,x);y=y([1:30]);
subplot(615),stem(n,c,'m.');ylabel('y')
subplot(614),stem(n,c4,'.');ylabel('y4')
subplot(616),stem(n,y,'r.');ylabel('y')
figure(3)
x1=x.*(u(n)-u(n-M));
x2=x.*(u(n-M)-u(n-2*M));
x3=x.*(u(n-2*M)-u(n-3*M));
x4=x.*(u(n-3*M)-u(n-4*M));
x5=x.*(u(n-4*M)-u(n-5*M));
subplot(611),stem(n,x,'.');
title('The short sequences xk(n)')
subplot(612),stem(n,x1,'.');
subplot(613),stem(n,x2,'.');
subplot(614),stem(n,x3,'.');
subplot(615),stem(n,x4,'.');
subplot(616),stem(n,o.*RN,'r.');
xlabel('Time index n')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -