📄 cnvpl35n.m
字号:
function cnvplt35(xs,ys,tx,ty,ts)
%Support file for CONVPLOT for use with MATLAB 3.5
% ADSP Toolbox: Version 2.0
% For use with "Analog and Digital Signal Processing", 2nd Ed.
% Published by PWS Publishing Co.
%
% Ashok Ambardar, EE Dept. MTU, Houghton, MI 49931, USA
% http://www.ee.mtu/faculty/akambard.html
% e-mail: akambard@mtu.edu
% Copyright (c) 1998
if nargin<5,dx=abs(diff(tx));dy=abs(diff(ty));df=max([dx dy]);ts=df/50;end
ta=min(tx):ts:max(tx);
tb=min(ty):ts:max(ty);
%if length(ta)>length(tb)
% t=ta;
% x=eval(xs);
% t1=t;
% t=tb;
% y=eval(ys);
% t2=t;
%else
% t=tb;
% x=eval(ys);
% t1=t;
% t=ta;
% y=eval(xs);
% t2=t;
%end
t=ta;
x=eval(xs);
t1=t;
t=tb;
y=eval(ys);
t2=t;
d1=max(t1)-min(t1);
d2=max(t2)-min(t2);
ddif=abs(d2-d1);
tst=min(t1)+min(t2);
tend=max(t1)+max(t2);
t3=min(t1)+(0:ts:tend-tst);
mint=min(t1)-d2;
t1=tst+(0:ts:d1);
t3=(0:ts:d1+d2)+tst; %%%NEW
z=ts*conv(x,y);
yf=fliplr(y);
%For products
ze=0*t3;
tp=ze;
lx=length(x);
ly=length(y);
lmax=max(lx,ly);
lmin=min(lx,ly);
tp(1,1:lx)=t1;
xp=ze;
yp=ze;
xp(1,1:lx)=x;
yp(1,1:ly)=y;
%For plotting product function
limits=[max(x);max(y);min(x);min(y);max(x)*max(y);min(x)*min(y);min(z);max(z)];
limits=[limits;max(x)*min(y);min(x)*max(y)];%%NEW
prmax=max(limits);
prmin=min(limits);
if prmin>0,
prmin=0;
end
l=length(t3);
t1p=[t1(1) t1 t1(lx)];
x1p=[0 x 0];
t2f=(0:ts:d2)-d2+tst;
mm=20;
tj=max([1 fix(l/mm)]);
hold off;
subplot;
clg;
axis([tst-d2 tend prmin-(0.1*abs(prmin)) prmax+(0.1*abs(prmax))]);
% plot non-shifting function
plot(t1p,x1p,'g');
% annotate graph
title(['Product(magenta), Conv(yellow) starts at t = ' num2str(tst)])
xlabel('time of convolution')
hold on
ta1=t2f;
la1=length(ta1);
tb1=t3(1);
zb1=z(1);
lb1=length(tb1);
% plot initial location of shifted function
plot([ta1(1) ta1 ta1(la1)],[0 yf 0],'c2');
plot(t3(1),0,'c5');
% store initial location for during animation
ttt=[ta1(1) ta1 ta1(la1)];
yyy=[0 yf 0];
% plot initial product
plot([tb1(1) tb1 tb1(lb1)],[0 zb1 0],'c5');
plot(tb1(lb1),zb1(lb1),'*c5');
% store initial values.
t31=t3(1);
xp11=xp(1);
yp11=fliplr(yp(1));
pr1=xp11.*yp11;
tpr1=tp(1);
lp1=length(tpr1);
% plot initial product of functions
plot([tpr1(1) tpr1 tpr1(lp1)],[0 pr1 0],'c12');
% animation sequencer
for j=[1:tj:l l],
% computing location of shifted function
ta=t2f+(j-1)*ts;
la=length(ta);
% computing product of two functions
xp1=xp(1:j);
yp1=fliplr(yp(1:j));
pr=xp1.*yp1;
%%%NEW
ind1=max(1,j-ly+1);
ind2=min(j,lx);
tpr=tp(ind1:ind2);
pr=pr(ind1:ind2);
%%%%%%%%
% tpr=tp(1:j);
% if j>lmax,
% pr=pr(1:lmax);
% tpr=tpr(1:lmax);
% end
lp=length(tpr);
if lp==1,pr=0;end
% location of convolution marker
tb=t3(j);
zb=z(j);
% erase shifting function
plot([ta1(1) ta1 ta1(la)],[0 yf 0],'i');
% erase convolution result
% plot([tb1(1) tb1 tb1(lb1)],[0 zb1 0],'i');
% erase shifting marker
plot(t31,0,'*i');
% erase convolution marker
plot(tb1,zb1,'*i');
% erase product of two functions
plot([tpr1(1) tpr1 tpr1(lp1)],[0 pr1 0],'i');
% plot initial location of shifting function
plot(ttt,yyy,':c2');
% plot non-shifting function
plot(t1p,x1p,'c3');
% plot shifting function
plot([ta(1) ta ta(la)],[0 yf 0],'c2');
% plot product of two functions
plot([tpr(1) tpr tpr(lp)],[0 pr 0],'m');
% plot shifting marker
plot(tb,0,'*c2');
% plot convlution function
plot(t3(1:j),z(1:j),'c5');
% plot convolution marker
plot(tb,zb,'*c5');
% store old values
tpr1=tpr; pr1=pr; lp1=lp;
ta1=ta; tb1=tb; zb1=zb; t31=t3(j);
end
plot(t3,z,'c5'),hold off
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -