?? covdemo.m
字號:
%==========================================================================
% Name:cconvdemo
% The program 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=-4;%input('請輸入信號的起始時間(建議取0—-10):');
t1=4;%input('請輸入信號的終止時間(建議取0—10):');
p=.01;
t=t0:p:t1;
x=u(t+1)-u(t-1);%input('請輸入激勵信號:');
h=0.5*t.*(u(t)-u(t-2));%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=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
%
q=ceil(l/2);
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),'Ha(t):');
%下段程序實現移位動畫
b=length(find(f));%d=0;e=0;r=0;v=0 %d,e,r為暫停開關
e=u(-t);
for i=1:b
for j=l-1:-1:1
y=hl(l);
if i<q
hl(j+1)=hl(j);hl(1)=y;e(1)=1;e(j+1)=e(j);
else hl(j+1)=hl(j);hl(1)=0;e(1)=1;e(j+1)=e(j);
end
c(j+1)=c(j);
end
c(1)=1;
%hl(1)=0;
pause(0.0000);
subplot(3,1,2);
plot(t,hl.*e,'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 + -