⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example2_7.m

📁 经典《信号与系统》教程的matlab例程,对深入理解信号与系统相关概念有很大帮助
💻 M
字号:
%==========================================================================
% 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('请输入信号的起始时间(建议取0—-10):');
t1=4;%input('请输入信号的终止时间(建议取0—10):');
p=.01;
t=t0:p:t1;
x=u(t)-u(t-1);%input('请输入激励信号:');
h=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=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
%
%以下程序绘制激励信号和系统冲激响应的波形
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)]);
%下段程序实现移位动画
b=1.5*length(find(f));%d=0;e=0;r=0;v=0   %d,e,r为暂停开关
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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -