?? example2_7.m
字號(hào):
%==========================================================================
% Name:ccovdemo
% 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;close all;
t0=-4;%input('請(qǐng)輸入信號(hào)的起始時(shí)間(建議取0—-10):');
t1=4;%input('請(qǐng)輸入信號(hào)的終止時(shí)間(建議取0—10):');
p=.01;
t=t0:p:t1;
x=u(t)-u(t-1);%input('請(qǐng)輸入激勵(lì)信號(hào):');
h=t.*(u(t)-u(t-2));%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));
q=51;
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),'h(t):');
axis([t0,t1,1.1*min(h),1.2*max(h)]);
%下段程序?qū)崿F(xiàn)移位動(dòng)畫
b=1.5*length(find(f));%d=0;e=0;r=0;v=0 %d,e,r為暫停開關(guān)
e=u(-t);z=0;
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');axis([t0,t1,1.1*min(h),1.2*max(h)]);
hold on;
%text(.5*t1,.8*max(hl),'HR(w):');
plot(t,x);
hold off;
subplot(3,1,3);
plot(t,c.*f,'r');
axis([t0,t1,1.1*min(f),1.2*max(f)]);%text(.5*t1,.8*max(f),'H(w):');
if max(c.*f)==max(f)&z==0
z=1;pause
end
end
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -