📄 cconv1.m
字号:
%==========================================================================
% Name:cconvdemo
% The program is used to demonstrate the convolution of two continuou-time
% signals
% Please expressed the signals in terms of the unit step function.
% For example:e(t)=exp(-2*t).*u(t).
%==========================================================================
clear;
t0=input('请输入信号的起始时间(建议取-t0—t0),t0=:');
t1=t0;t0=-t0;
p=.05;
t=t0:p:t1;
x=input('请输入激励信号:');
h=input('请输入系统冲激响应:');
f=p*conv(x,h);%卷积计算
%将卷积的结果取得和两个输入的信号一样长,以便在相同的坐标中绘制其图形并方便比较。
l=length(f);
m=2*t0:p:t0-p;
n=t1+p:p:2*t1;
m1=zeros(1,abs(t0/p));
n1=zeros(1,abs(t1/p));
lm=length(m1);
ln=length(n1);
f=f([lm+1:l-ln]);
c=u(-t); %移位窗
%计算移位长度
hl=fliplr(h);
l=length(hl);
k0=min(find(hl))+length(find(hl));
v0=min(find(f));
w0=min(find(x));
if k0<=w0
q=50;
else
q=k0-w0+50;
end
%
for i=1:q
y=hl(1);
for j=1:l-1
hl(j)=hl(j+1);c(j)=c(j+1);
end
hl(l)=y;c(l)=0;
end
%
%以下程序绘制激励信号和系统冲激响应的波形
clf;
subplot(3,1,1)
plot(t,x);hold on;plot(t,h,'r');
text(.5*t1,.8*max(x),'激励信号e(t):');
%下段程序实现移位动画
b=q+length(find(f));
for i=1:b
for j=l-1:-1:1
hl(j+1)=hl(j);
c(j+1)=c(j);
end
c(1)=1;
hl(1)=0;
pause(0);
subplot(3,1,2);
plot(t,hl,'r');hold on;text(.5*t1,.8*max(h),'系统冲激响应h(t):');plot(t,x);
hold off;
subplot(3,1,3);
plot(t,c.*f,'r');axis([t0,t1,min(f),max(f)]);text(.5*t1,.8*max(f),'系统响应r(t):');
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -