📄 conv_fre_win.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;close all,
t0=-pi;%input('请输入信号的起始时间(建议取0—-10):');
t1=pi;%input('请输入信号的终止时间(建议取0—10):');
p=2*pi/512;N=31;
t=t0:p:t1;
x=u(t+0.3*pi)-u(t-0.3*pi);%input('请输入激励信号:');
h=sin((t*N+eps)/2)./sin((t+eps)/2)/N;%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/pi,x);hold on;plot(t/pi,h,'r');
axis([t0/pi,t1/pi,1.1*min(h),1.2*max(h)]);
%下段程序实现移位动画
b=length(find(f));%d=0;e=0;r=0;v=0 %d,e,r为暂停开关
e=u(-t);z=0;a=1;
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.0000000);
subplot(3,1,2);
plot(t/pi,hl.*e,'r');axis([t0/pi,t1/pi,1.1*min(h),1.2*max(h)]);hold on;plot(t/pi,x);
hold off;
subplot(3,1,3);
plot(t/pi,c.*f*N,'r');axis([t0/pi,t1/pi,1.1*min(f*N),1.2*max(f*N)]);
if max(c.*f)==max(f)&z==0&a==1
z=1;pause
end
if min(c.*f)==min(f)&a==1&z==1
a=1, pause
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -