?? cconv1.m
字號(hào):
%==========================================================================
% 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('請(qǐng)輸入信號(hào)的起始時(shí)間(建議取-t0—t0),t0=:');
t1=t0;t0=-t0;
p=.05;
t=t0:p:t1;
x=input('請(qǐng)輸入激勵(lì)信號(hào):');
h=input('請(qǐng)輸入系統(tǒng)沖激響應(yīng):');
f=p*conv(x,h);%卷積計(jì)算
%將卷積的結(jié)果取得和兩個(gè)輸入的信號(hào)一樣長(zhǎng),以便在相同的坐標(biāo)中繪制其圖形并方便比較。
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); %移位窗
%計(jì)算移位長(zhǎng)度
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
%
%以下程序繪制激勵(lì)信號(hào)和系統(tǒng)沖激響應(yīng)的波形
clf;
subplot(3,1,1)
plot(t,x);hold on;plot(t,h,'r');
text(.5*t1,.8*max(x),'激勵(lì)信號(hào)e(t):');
%下段程序?qū)崿F(xiàn)移位動(dòng)畫(huà)
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),'系統(tǒng)沖激響應(yīng)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),'系統(tǒng)響應(yīng)r(t):');
end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -