matlab连续卷积动画实现(gui编程)

一.代码运行结果

在这里插入图片描述

二.代码

function varargout = tianqi(varargin)
% TIANQI MATLAB code for tianqi.fig
%      TIANQI, by itself, creates a new TIANQI or raises the existing
%      singleton*.
%
%      H = TIANQI returns the handle to a new TIANQI or the handle to
%      the existing singleton*.
%
%      TIANQI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in TIANQI.M with the given input arguments.
%
%      TIANQI('Property','Value',...) creates a new TIANQI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before tianqi_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to tianqi_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help tianqi

% Last Modified by GUIDE v2.5 18-Oct-2020 21:54:40

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @tianqi_OpeningFcn, ...
                   'gui_OutputFcn',  @tianqi_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before tianqi is made visible.
function tianqi_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to tianqi (see VARARGIN)

% Choose default command line output for tianqi
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes tianqi wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = tianqi_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in pushbutton1.
% 绘制x图形
function pushbutton1_Callback(hObject, eventdata, handles)
res1=get(handles.edit1,'String');  %获取参数a(string)
res2=get(handles.edit2,'String');  %获取参数b(string)
if isempty(res1)
     msgbox('input a first','warn','warn');
    return
else
   a=str2double(res1);   %判断a是否为空值
end
if isempty(res2)
     msgbox('input b first','warn','warn');
    return
else
  b=str2double(res2);  %判断b是否为空值
end
choose_x=get(handles.popupmenu1,'value');  
%获取函数x类型
switch choose_x
    case 1   %门函数
         if b<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t_start=a-b/2;
t_end=a+b/2;  %门函数起点与终点
x_start=t_start-3;  %限定x坐标轴范围
x_end=t_end+3;
t=x_start:0.001:x_end;%定义时间向量
f=@(t) (t.*0+1).*(t>=t_start&t<=t_end);%使用函数句柄定义门函数,门高为1
yt=f(t);  %创建门函数
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes1); %画图像在坐标轴1
plot(t,yt);  %绘图
axis([x_start,x_end,0,y_end]);  %限定坐标轴范围
grid on;  %打开网格线
 case 2 %三角函数
       if b<=0
            msgbox('b should be positive','warn','warn');
            return
        end
        t_start=a-b/2;
t_end=a+b/2;   %三角函数起点与终点
x_start=t_start-3;  %限定x坐标轴范围
x_end=t_end+3;
t=x_start:0.001:x_end;%定义时间向量
t_center=(t_start+t_end)/2;
t_width=t_end-t_start;   %三角函数中心与宽度
a10=t_center;
b10=t_width;
f=@(t) ((2/b10).*t-(2*a10/b10)+1).*(t>=t_start&t<=t_center)+((-2/b10).*t+(2*a10/b10)+1).*(t>t_center&t<=t_end);
%使用函数句柄定义三角函数
yt=f(t);  %创建三角函数
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes1);   %画图像在坐标轴1
plot(t,yt);
axis([x_start,x_end,0,y_end]);
grid on;
    case 3 %阶跃函数
        if a==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        b10=b;
a10=a;
x_start=b10/a10-3;  %限定x坐标轴范围
x_end=b10/a10+3;
t=x_start:0.001:x_end;%定义时间向量
f=@(t) (t.*0+1).*((a10.*t-b10)>=0); %使用函数句柄定义阶跃函数
yt=f(t);  
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes1);
plot(t,yt);
axis([x_start,x_end,0,y_end]);
    case 4 %冲激函数
         if a==0
            msgbox('a can not be zero','warn','warn');
            return
         end
    syms f t;   
  b10=b;
a10=a;
f=dirac(a10*t-b10);  %定义冲激函数
x_start=b10/a10-3;  %限定x坐标轴范围
x_end=b10/a10+3;
tv=x_start:0.001:x_end;%定义时间向量
ft=double(subs(f,t,tv));  %用时间向量tv替代t
ft(find(ft==inf))=1;   %将冲激函数中无穷大量改为1
axes(handles.axes1);
plot(tv,ft);
axis([x_start x_end 0 1 ]);

    case 5 %单边指数
          if a==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a;
b10=b;
x_start=-3;  %限定x坐标轴范围
x_end=3;
t=x_start:0.001:x_end;%定义时间向量
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0); %使用函数句柄定义单边指数信号
yt=f(t);  
y_start=min(yt)*1.1;
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes1);
plot(t,yt);
axis([x_start,x_end,y_start,y_end]);
grid on;
    case 6 %单边正弦波
         if a==0
            msgbox('a can not be zero,due to some reasons that exist on sources codes','warn','warn');
            return
        end
        a10=a;
b10=b;
x_start=-pi/abs(a10)  ;  %限定x坐标轴范围
x_end=3*pi/abs(a) ;
t=x_start:0.001:x_end;%定义时间向量
f=@(t)  sin(a10.*t+b10).*(t>=0);
yt=f(t);  
y_end=max(yt)*1.1;%限定y坐标轴范围
y_start=min(yt)*1.1;
axes(handles.axes1);
plot(t,yt);
axis([x_start,x_end,y_start,y_end]);
grid on;
end
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in pushbutton2.
%绘制y图象
function pushbutton2_Callback(hObject, eventdata, handles)
res1=get(handles.edit3,'String');
res2=get(handles.edit4,'String');
if isempty(res1)
     msgbox('input a first','warn','warn');
    return
else
   a=str2double(res1);
end
if isempty(res2)
     msgbox('input b first','warn','warn');
    return
else
  b=str2double(res2);
end
choose_y=get(handles.popupmenu2,'value');
switch choose_y
    case 1   %门函数
         if b<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t_start=a-b/2;
t_end=a+b/2;
x_start=t_start-3;  %限定x坐标轴范围
x_end=t_end+3;
t=x_start:0.001:x_end;%定义时间向量
f=@(t) (t.*0+1).*(t>=t_start&t<=t_end);%使用函数句柄定义门函数,门高为1
yt=f(t);  %创建门函数
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes2);
plot(t,yt,'r');
axis([x_start,x_end,0,y_end]);
grid on;
 case 2 %三角函数
       if b<=0
            msgbox('b should be positive','warn','warn');
            return
        end
        t_start=a-b/2;
t_end=a+b/2;
x_start=t_start-3;  %限定x坐标轴范围
x_end=t_end+3;
t=x_start:0.001:x_end;%定义时间向量
t_center=(t_start+t_end)/2;
t_width=t_end-t_start;
a10=t_center;
b10=t_width;
f=@(t) ((2/b10).*t-(2*a10/b10)+1).*(t>=t_start&t<=t_center)+((-2/b10).*t+(2*a10/b10)+1).*(t>t_center&t<=t_end);
%使用函数句柄定义三角函数
yt=f(t);  %创建三角函数
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes2);
plot(t,yt,'r');
axis([x_start,x_end,0,y_end]);
grid on;
    case 3 %阶跃函数
        
         if a==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        b10=b;
a10=a;
x_start=b10/a10-3;  %限定x坐标轴范围
x_end=b10/a10+3;
t=x_start:0.001:x_end;%定义时间向量
f=@(t) (t.*0+1).*((a10.*t-b10)>=0);
yt=f(t);  
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes2);
plot(t,yt,'r');
axis([x_start,x_end,0,y_end]);
    case 4 %冲激函数
      

        
   if a==0
            msgbox('a can not be zero','warn','warn');
            return
        end
          syms f t;
  b10=b;
a10=a;
f=dirac(a10*t-b10);  %定义冲激函数
x_start=b10/a10-3;  %限定x坐标轴范围
x_end=b10/a10+3;
tv=x_start:0.001:x_end;%定义时间向量
ft=double(subs(f,t,tv));  %用时间向量tv替代t
ft(find(ft==inf))=1;
axes(handles.axes2);
plot(tv,ft,'r');
axis([x_start x_end 0 1 ]);
grid on;
    case 5 %单边指数
          if a==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a;
b10=b;
x_start=-3;  %限定x坐标轴范围
x_end=3;
t=x_start:0.001:x_end;%定义时间向量
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0);
yt=f(t);  
y_start=min(yt)*1.1;
y_end=max(yt)*1.1;%限定y坐标轴范围
axes(handles.axes2);
plot(t,yt,'r');
axis([x_start,x_end,y_start,y_end]);
grid on;
    case 6 %单边正弦波
         if a==0
            msgbox('a can not be zero,due to some reasons that exist on sources codes','warn','warn');
            return
        end
        a10=a;
b10=b;
x_start=-pi/abs(a10)  ;  %限定x坐标轴范围
x_end=3*pi/abs(a) ;
t=x_start:0.001:x_end;%定义时间向量
f=@(t)  sin(a10.*t+b10).*(t>=0);
yt=f(t);  
y_end=max(yt)*1.1;%限定y坐标轴范围
y_start=min(yt)*1.1;
axes(handles.axes2);
plot(t,yt,'r');
axis([x_start,x_end,y_start,y_end]);
grid on;

end
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on button press in pushbutton3.
%卷积运算
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global flag;
flag=1;
choose1=get(handles.popupmenu1,'value');
choose2=get(handles.popupmenu2,'value');
res1=get(handles.edit1,'String');
res2=get(handles.edit2,'String');
res3=get(handles.edit3,'String');
res4=get(handles.edit4,'String');
if isempty(res1)
     msgbox('input a first','warn','warn');
    return
else
   a1=str2double(res1);
end
if isempty(res2)
     msgbox('input b first','warn','warn');
    return
else
  b1=str2double(res2);
end
if isempty(res3)
     msgbox('input b first','warn','warn');
    return
else
  a2=str2double(res3);
end
if isempty(res4)
     msgbox('input b first','warn','warn');
    return
else
  b2=str2double(res4);
end
switch choose2   %函数y图形(g表示)
    case 1   %门函数
         if b2<=0
            msgbox('b should be positive','warn','warn');
            return
         end
  syms   x g2;
 g2=heaviside(x-(a2-b2/2))-heaviside(x-(a2+b2/2));%利用阶跃函数构建门函数
t2_start=a2-b2/2;  %门函数左边界
t2_end=a2+b2/2;  %门函数右边界
g=@(t) (t.*0+1).*(t>=t2_start&t<=t2_end)+0;%使用函数句柄定义门函数,门高为1
switch choose1 %函数x图形(f表示)
    case 1 %门函数
         if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t1_start=a1-b1/2;  %门函数左边界
t1_end=a1+b1/2;  %门函数右边界
x_start=t1_start+t2_start-3;  %坐标轴3左边界
x_end=t1_end+t2_end+3;   %坐标轴3右边界
y_start =-0.5;
if  b1>b2
    y_end=b2*1.1;
else
    y_end=b1*1.1;
end
f=@(t) (t.*0+1).*(t>=t1_start&t<=t1_end)+0;%使用函数句柄定义门函数,门高为1
   case 2 %三角函数
        if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
 t1_start=a1-b1/2;  %三角函数左边界
t1_end=a1+b1/2;   %三角函数右边界
x_start=t1_start+t2_start-3;  %坐标轴3左边界
x_end=t1_end+t2_end+3;  %坐标轴3右边界
y_start =-0.5;
if  (b1/2)>b2
    y_end=b2*1.1;
else
    y_end=(b1/2)*1.1;
end
t1_center=a1;   %三角函数中心
t1_width=b1;    %三角函数宽度
a=t1_center;
b=t1_width;
f=@(t) ((2/b).*t-(2*a/b)+1).*(t>=t1_start&t<=t1_center)+((-2/b).*t+(2*a/b)+1).*(t>t1_center&t<=t1_end);
    case 3 %阶跃函数
          if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
x1_start=b1/a1-3;  
x1_end=b1/a1+3; %阶跃函数左右边界
a=a1;
b=b1;
f=@(t) (t.*0+1).*((a.*t-b)>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-0.5;
y_end=b2*1.1;
    case 4 %冲激函数
         if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        syms f;
        syms tao;
      x1_start=b1/a1-3;  
x1_end=b1/a1+3;  %冲激函数左右边界
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-0.5;
if abs(a1)>1
    y_end=1.1;
else
y_end=round(1/abs(a1),1)*1.1;
end

x_of_f=x_start:0.01:x_end;%定义时间向量
 f=dirac(a1*tao-b1);  %定义冲激函数
 y_of_f=double(subs(f,tao,x_of_f));% 将tao替换为x_of_f
  y_of_f(find(  y_of_f==inf))=1;%将冲激函数中的无穷大改为1
    xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
    case 5 %单边指数信号
 if a1==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a1;
b10=b1;
x1_start=-3; 
x1_end=3;
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=min((a1<0)*a1*b2,a1*b2*(a1>0));
y_end=max((a1<0)*a1*b2,a1*b2*(a1>0));
      case 6 %单边正弦波
           if a2==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a1;
b10=b1;
x1_start=-pi/abs(a10)  ;  
x1_end=3*pi/abs(a10) ;
f=@(t)  sin(a10.*t+b10).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
end
case 2   %函数y图形三角函数
        syms x g2;
        t2_start=a2-b2/2;
t2_end=a2+b2/2;
t2_center=a2;
t2_width=b2;
a=t2_center;
b=t2_width;
g=@(t) ((2/b).*t-(2*a/b)+1).*(t>=t2_start&t<=t2_center)+((-2/b).*t+(2*a/b)+1).*(t>t2_center&t<=t2_end);
   g2=(heaviside(x-(a2-b2/2))-heaviside(x-a2))*(x-(a2-b2/2))*2/b2+(heaviside(x-a2)-heaviside(x-(a2+b2/2)))*(-x+(a2+b2/2))*2/b2;
switch choose1 %函数x图形(f表示)
    case 1 %门函数
         if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start-3;
x_end=t1_end+t2_end+3;
f=@(t) (t.*0+1).*(t>=t1_start&t<=t1_end)+0;%使用函数句柄定义门函数,门高为1
y_start=-0.5;
if (b2/2)>b1
    y_end=b1*1.1;
else
    y_end=(b2/2)*1.1;
end
case 2 %三角函数
        if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
 t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start-3;
x_end=t1_end+t2_end+3;
y_start=-0.5;
if (b2/2)>(b1/2)
    y_end=(b1/2)*1.1;
else
    y_end=(b2/2)*1.1;
end
t1_center=a1;
t1_width=b1;
a=t1_center;
b=t1_width;
f=@(t) ((2/b).*t-(2*a/b)+1).*(t>=t1_start&t<=t1_center)+((-2/b).*t+(2*a/b)+1).*(t>t1_center&t<=t1_end);
    case 3 %阶跃函数
          if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
x1_start=b1/a1-3;  
x1_end=b1/a1+3; %阶跃函数左右边界
a=a1;
b=b1;
f=@(t) (t.*0+1).*((a.*t-b)>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-0.5;
y_end=(b2/2)*1.1;
case 4 %冲激函数
         if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        syms f;
        syms tao;
        f=dirac(a1*tao-b1);  %定义冲激函数
      x1_start=b1/a1-3;  
x1_end=b1/a1+3;  %冲激函数左右边界
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-0.5;
if abs(a1)>1
    y_end=1.1;
else
y_end=round(1/abs(a1),1)*1.1;
end

x_of_f=x_start:0.01:x_end;%定义时间向量
 
y_of_f=double(subs(f,tao,x_of_f));% 将tao替换为x_of_f
  y_of_f(find(  y_of_f==inf))=1;%将冲激函数中的无穷大改为1
    xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
    case 5 %单边指数信号
        if a1==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a1;
b10=b1;
x1_start=-3; 
x1_end=3;
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=min((a1<0)*a1*(b2/2),a1*(b2/2)*(a1>0));
y_end=max((a1<0)*a1*(b2/2),a1*(b2/2)*(a1>0));
      case 6 %单边正弦波
           if a2==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
           end
        a10=a1;
b10=b1;
x1_start=-pi/abs(a10)  ;  
x1_end=3*pi/abs(a10) ;
f=@(t)  sin(a10.*t+b10).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
end
case 3 %函数y图形阶跃函数
        syms x g2;
        x2_start=b2/a2-3;  
x2_end=b2/a2+3;
a=a2;
b=b2;
g=@(t) (t.*0+1).*((a.*t-b)>=0);
g2=heaviside(a2*x-b2);
switch choose1 %函数x图形(f表示)
    case 1 %门函数
         if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+x2_start-3;
x_end=t1_end+x2_end+3;
y_start=-0.5;
y_end=b1*1.1;
f=@(t) (t.*0+1).*(t>=t1_start&t<=t1_end)+0;%使用函数句柄定义门函数,门高为1
  case 2 %三角函数
        if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
 t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+x2_start-3;
x_end=t1_end+x2_end+3;
y_start=-0.5;
y_end=(b1/2)*1.1;
t1_center=a1;
t1_width=b1;
a=t1_center;
b=t1_width;
f=@(t) ((2/b).*t-(2*a/b)+1).*(t>=t1_start&t<=t1_center)+((-2/b).*t+(2*a/b)+1).*(t>t1_center&t<=t1_end);
   case 3 %阶跃函数
          if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
x1_start=b1/a1-3;  
x1_end=b1/a1+3; %阶跃函数左右边界
a=a1;
b=b1;
f=@(t) (t.*0+1).*((a.*t-b)>=0);
x_start=x1_start+x2_start-3;
x_end=x1_end+x2_end+3;
y_start=-0.5;
y_end=10;
    case 4 %冲激函数
         if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        syms f;
        syms tao;
        f=dirac(a1*tao-b1);  %定义冲激函数
      x1_start=b1/a1-3;  
x1_end=b1/a1+3;  %冲激函数左右边界
x_start=x1_start+x2_start-3;
x_end=x1_end+x2_end+3;
y_start=-0.5;
if abs(a1)>1
    y_end=1.1;
else
y_end=round(1/abs(a1),1)*1.1;
end
x_of_f=x_start:0.01:x_end;%定义时间向量
 y_of_f=double(subs(f,tao,x_of_f));% 将tao替换为x_of_f
  y_of_f(find(  y_of_f==inf))=1;%将冲激函数中的无穷大改为1
    xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
    case 5 %单边指数信号
        if a1==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a1;
b10=b1;
x1_start=-3; 
x1_end=3;
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0);
x_start=x1_start+x2_start-3;
x_end=x1_end+x2_end+3;
y_start=min((a1<0)*a1*2,a1*2*(a1>0));
y_end=max((a1<0)*a1*2,a1*2*(a1>0));
       case 6 %单边正弦波
           if a2==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
           end
        a10=a1;
b10=b1;
x1_start=-pi/abs(a10)  ;  
x1_end=3*pi/abs(a10) ;
f=@(t)  sin(a10.*t+b10).*(t>=0);
x_start=x1_start+x2_start-3;
x_end=x1_end+x2_end+3;
y_start=-3;
y_end=3;
end
  case 4 %函数y图形冲激函数
        syms t f tao g2 x;
          t2_start=b2/a2-3;
          t2_end=b2/a2+3;
          g2=dirac(a2*x-b2);
        switch choose1  %函数x图形(f表示)
            case 1  
                if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start;
x_end=t1_end+t2_end;
y_start=-0.5;
if abs(a2)>1
    y_end=1.1;
else
y_end=round(1/abs(a2),1)*1.1;
end
       f=heaviside(tao-(a1-b1/2))-heaviside(tao-(a1+b1/2));%利用阶跃函数构建门函数
    xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
            case  2
                 if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
 t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start;
x_end=t1_end+t2_end;
y_start=-0.5;
if abs(a2)>1
    y_end=1.1;
else
y_end=round(1/abs(a2),1)*1.1;
end
                 f=(heaviside(tao-(a1-b1/2))-heaviside(tao-a1))*(tao-(a1-b1/2))*2/b1+(heaviside(tao-a1)-heaviside(tao-(a1+b1/2)))*(-tao+(a1+b1/2))*2/b1;%利用阶跃函数构建三角函数
           xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
            case 3
                if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
x1_start=b1/a1-3;  
x1_end=b1/a1-3; %阶跃函数左右边界
if abs(a2)>1
    y_end=1.1;
else
y_end=round(1/abs(a2),1)*1.1;

end
y_start=-0.5;
                f=heaviside(a1*tao-b1);%阶跃函数表达式
            x_start=x1_start+t2_start;
x_end=x1_end+t2_end;
xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
            case 4
               if a1==0
            msgbox('a can not be zero','warn','warn');
            return
               end
         x1_start=b1/a1-3;  
x1_end=b1/a1+3;  %冲激函数左右边界
x_start=x1_start+t2_start;
x_end=x1_end+t2_end;
if abs(a2)>1
    y_end=1.1;
else
y_end=round(1/abs(a2),1)*1.1;
end
y_start=-0.5;
                f=dirac(a1*tao-b1);%冲激函数表达式
           xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
            case 5 %单边指数信号
                 if a1==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
  x1_start=-3; 
x1_end=3;
x_start=x1_start+t2_start;
x_end=x1_end+t2_end;
if abs(a2)>1
    y_start=-abs(a1);
    y_end=abs(a1);
else
    y_start=-abs(a1)/abs(a2);
    y_end=abs(a1)/abs(a2);
end
                f= a1*exp(-abs(b1)*tao)*heaviside(tao);
            xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
            case 6 %单边正弦波
           if a2==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
           end
   x1_start=round(-pi/abs(a1) ,2) ;  
x1_end=round(3*pi/abs(a1),2) ;
x_start=x1_start+t2_start;
x_end=x1_end+t2_end;
if abs(a2)>1
    y_start=-3;
    y_end=3;
else
    y_start=-(1/abs(a2))*1.1;
    y_end=(1/abs(a2))*1.1;
end
                f=sin(a1*tao+b1)*heaviside(tao);
                 xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
        end
      case  5 %函数y图形单边指数函数
        t2_start=-3;  %限定x坐标轴范围
t2_end=3;
a=a2;
b=b2;
g=@(t)  (a*exp(-abs(b).*t)).*(t>=0);
syms g2 x;
 g2=a2*exp(-abs(b2)*x)*heaviside(x);
     switch choose1 %函数x图形(f表示)
    case 1 %门函数
         if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start-3;
x_end=t1_end+t2_end+3;
y_start=min((a2<0)*a2*b1,a2*b1*(a2>0));
y_end=max((a2<0)*a2*b1,a2*b1*(a2>0));
f=@(t) (t.*0+1).*(t>=t1_start&t<=t1_end)+0;%使用函数句柄定义门函数,门高为1
   case 2 %三角函数
        if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
 t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start-3;
x_end=t1_end+t2_end+3;
y_start=min((a2<0)*a2*(b1/2),a2*(b1/2)*(a2>0));
y_end=max((a2<0)*a2*(b1/2),a2*(b1/2)*(a2>0));
t1_center=a1;
t1_width=b1;
a=t1_center;
b=t1_width;
f=@(t) ((2/b).*t-(2*a/b)+1).*(t>=t1_start&t<=t1_center)+((-2/b).*t+(2*a/b)+1).*(t>t1_center&t<=t1_end);
    case 3 %阶跃函数
          if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
x1_start=b1/a1-3;  
x1_end=b1/a1+3; %阶跃函数左右边界
a=a1;
b=b1;
f=@(t) (t.*0+1).*((a.*t-b)>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-abs(a2);
y_end=abs(a2);
    case 4 %冲激函数
         if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        syms f;
        syms tao;
        f=dirac(a1*tao-b1);  %定义冲激函数
      x1_start=b1/a1-3;  
x1_end=b1/a1+3;  %冲激函数左右边界
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
if abs(a1)>1
    y_start=-abs(a2);
    y_end=abs(a2);
else
    y_start=-abs(a2)/abs(a1);
    y_end=abs(a2)/abs(a1);
end
x_of_f=x_start:0.01:x_end;%定义时间向量
 y_of_f=double(subs(f,tao,x_of_f));% 将tao替换为x_of_f
  y_of_f(find(  y_of_f==inf))=1;%将冲激函数中的无穷大改为1
    xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
    case 5 %单边指数信号
        if a1==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a1;
b10=b1;
x1_start=-3; 
x1_end=3;
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
top=abs(a1)+abs(a2);
y_start=-top;
y_end=top;
      case 6 %单边正弦波
           if a2==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
           end
        a10=a1;
b10=b1;
x1_start=-pi/abs(a10)  ;  
x1_end=3*pi/abs(a10) ;
f=@(t)  sin(a10.*t+b10).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
end
case 6 %函数y图形单边正弦波
        syms g2 x;
         g2=sin(a2*x+b2)*heaviside(x);
t2_start=round(-pi/abs(a2),2)  ;  
t2_end=round(3*pi/abs(a2),2) ;
g=@(t)  sin(a2.*t+b2).*(t>=0);
          switch choose1 %函数x图形(f表示)
    case 1 %门函数
         if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start-3;
x_end=t1_end+t2_end+3;
y_start=-3;
y_end=3;
f=@(t) (t.*0+1).*(t>=t1_start&t<=t1_end)+0;%使用函数句柄定义门函数,门高为1
   case 2 %三角函数
        if b1<=0
            msgbox('b should be positive','warn','warn');
            return
        end
 t1_start=a1-b1/2;
t1_end=a1+b1/2;
x_start=t1_start+t2_start-3;
x_end=t1_end+t2_end+3;
y_start=-3;
y_end=3;
t1_center=a1;
t1_width=b1;
a=t1_center;
b=t1_width;
f=@(t) ((2/b).*t-(2*a/b)+1).*(t>=t1_start&t<=t1_center)+((-2/b).*t+(2*a/b)+1).*(t>t1_center&t<=t1_end);
     case 3 %阶跃函数
          if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
x1_start=b1/a1-3;  
x1_end=b1/a1+3; %阶跃函数左右边界
a=a1;
b=b1;
f=@(t) (t.*0+1).*((a.*t-b)>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
    case 4 %冲激函数
         if a1==0
            msgbox('a can not be zero','warn','warn');
            return
        end
        syms f;
        syms tao;
        f=dirac(a1*tao-b1);  %定义冲激函数
      x1_start=b1/a1-3;  
x1_end=b1/a1+3;  %冲激函数左右边界
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
x_of_f=x_start:0.01:x_end;%定义时间向量
 y_of_f=double(subs(f,tao,x_of_f));% 将tao替换为x_of_f
  y_of_f(find(  y_of_f==inf))=1;%将冲激函数中的无穷大改为1
    xy_tao=f*subs(g2,x,x-tao);%将y中的x用x-tao替换
      xy=simplify(simplify(int(xy_tao,tao,-100,100)));%卷积过程
    case 5 %单边指数信号
        if a1==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
        end
        a10=a1;
b10=b1;
x1_start=-3; 
x1_end=3;
f=@(t)  (a10*exp(-abs(b10).*t)).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
      case 6 %单边正弦波
           if a2==0
            msgbox('a can not be zero,due to some reasons that exsit on sources codes','warn','warn');
            return
           end
        a10=a1;
b10=b1;
x1_start=-pi/abs(a10)  ;  
x1_end=3*pi/abs(a10) ;
f=@(t)  sin(a10.*t+b10).*(t>=0);
x_start=x1_start+t2_start-3;
x_end=x1_end+t2_end+3;
y_start=-3;
y_end=3;
end
end 
if choose2 ==4
    syms g g3 tao x;
    x_of_g=x_start:0.01:x_end;
        axes(handles.axes3);
        cla reset;
       grid on;
       hold on;
       %坐标轴范围
       axis([x_start x_end y_start y_end]);
       fplot(f,[x_start x_end ]);
       H=round(b2/a2,2);
       g=dirac(x-tao-H); %定义冲激函数
       g3=subs(g,tao,x_of_g);
        for  t=x_start:0.01:x_end
y_of_g=subs(g3,x,t);
    y_of_g(find(y_of_g==inf))=1;
   y_of_g_plot=plot(x_of_g,y_of_g,'r');
 res=double(subs(xy,x,t));
   plot(t,res,'.');
    pause(0.1);
    if flag ==0
        uiwait(handles.figure1);
    end
delete(y_of_g_plot);
        end
  return
end
if choose1 == 4  %冲激函数另作讨论
    x_of_g=x_start:0.01:x_end; %定义函数y时间向量
   axes(handles.axes3);
  cla reset; %清空坐标系
   hold  on;   %将多张图绘到一个坐标系上
   grid on;
   plot(x_of_f,y_of_f,'b');  %绘制x(tao)
      %坐标轴范围
axis([x_start x_end  y_start y_end]);
for t=x_start:0.01:x_end
  y_of_g=g(t-x_of_g);
     y_of_g_plot=plot(x_of_g,y_of_g,'r');  %绘制y(t-tao)
    pause(0.1);  %暂定目的看清绘制过程
   res=double(subs(xy,x,t));  %卷积xy中x用数值t替代
   plot(t,res,'.');   %绘制卷积结果,注意是一个又一个点
      if flag ==0
        uiwait(handles.figure1);
    end
   delete(y_of_g_plot);
end
    return
end
%一般情况
x_of_f=x_start:0.01:x_end;  %定义函数x时间向量
y_of_f=f(x_of_f);   %得到x的纵坐标
x_of_g=x_start:0.01:x_end;   %定义函数y时间向量
   axes(handles.axes3);
   cla reset;  %清空坐标系
   hold  on;   %将多张图绘到一个坐标系上
   grid on;
   plot(x_of_f,y_of_f,'b');%绘制x(tao)
      %坐标轴范围
axis([x_start x_end  y_start y_end]);
for t=x_start:0.01:x_end
    y_of_g=g(t-x_of_g);  
     y_of_g_plot=plot(x_of_g,y_of_g,'r');  %绘制y(t-tao)
    pause(0.1);  %暂定目的看清绘制过程
  sum=0;  %求卷积积分
    for tao=x_start:0.01:x_end
        sum=sum+0.01*f(tao)*g(t-tao);  %乘以0.01目的,归一化
    end
   plot(t,sum,'.');   %绘制卷积结果,注意是一个又一个点
    if flag ==0
        uiwait(handles.figure1);
    end
   delete(y_of_g_plot);
end

% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1

% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double
% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global flag;
str=get(handles.pushbutton5,'String');
if isequal(str,'pause')
    flag=0;
    set(handles.pushbutton5,'String','continue');
else
    flag=1;
  uiresume(handles.figure1);
    set(handles.pushbutton5,'String','pause');
end

三.界面布局

在这里插入图片描述
三个按钮从上到下依次为:
函数x图形:pushbutton1
函数y图形:pushbutton2
运算:pushbutton3
pause:pushbutton5
可编辑文本框从上到下依次为
edit1
edit2
edit3
edit4
下拉菜单从上到下依次为
popupmenu1
popupmenu2
其余为静态文本框
下载代码链接:
点击下载代码

  • 6
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值