基于GUI的信号基本运算
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
Matlab综合课程设计
设计报告
设计题目:基于GUI的信号基本运算设计
专业电子信息工程
班级电信121
学生潘亚妮
学号3120412031
指导教师梁莉莉
2014 年春季学期
一、课题总体设计
1.程序方案设计;
该课题利用连续时间信号时域运算的基本方法,想要设计基于GUI的连续信号的基本运算操作和演示。
为实现该操作演示,要求在设计菜单包括信号的运算有:加运算,乘运算,信号的翻转、平移和展缩和卷积操作;且输入两个信号,可进行信号的相关操作并显示;设计菜单包括信号的运算有:加运算,乘运算,信号的翻转、平移和展缩和卷积操作;可输入任意信号,信号的翻转平移展缩的参数可修改。
2. 功能函数设计;
6个功能函数,包括:加运算,乘运算,信号的翻转、平移和展缩和卷积。
信号的卷积:
3、整体系统流程图或程序界面设计。
流程图:
程序界面:
二、编程与调试
1、详细描述程序编写的步骤;
分别对加运算,乘运算,信号的翻转、平移和展缩和卷积编写程序,然后设计GUI界面,再将各子程序写入对应的按键的callback里即可。
2、详细描述调试过程中出现的问题和解决方法;
出现过的问题:一个按钮对于两个函数的控制不当,使得出来的图像对不上,比如一个翻转按钮不能对两幅图进行很好的转换。
解决方法:设置两个按钮,区分开两个函数的图像调用。
3、详细描述程序测试方案。
1.输入了sin(x)与cos(x)函数,分别按绘图按钮,检查输出图像正确与否;
2.分别按展缩、平移、翻转按钮,查看图像,对平移和展缩可适当设置不同参数,进行比较;和运算、乘运算、卷积也一样;
3.若图像与实际不符,则证明程序有问题,可打开对应按钮的callback,进行调试。
三、结果分析
1、已达到设计要求;
2、程序算法简单,运行速度较快;
3、功能性课题分析程序完备,简单简明。
四、总结
通过本次课程设计,对于matlab语言及应用这门课,有了更深的认识和运用;掌握应用matlab语言相关知识、基于matlab 语言的工具箱GUI等,初次尝试了在信息与控制相关研究与实际应用中的建模、设计、系统的设计流程.
附图:
Sin(x)
翻转
展缩
平移
Cos(x)与sin(x)类似
和运算
乘运算
卷积
源程序:
function varargout = untitled(varargin)
% UNTITLED M-file for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input arguments. %
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before untitled_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to untitled_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDA TA, GUIHANDLES
% Copyright 2002-2003 The MathWorks, Inc.
% Edit the above text to modify the response to help untitled
% Last Modified by GUIDE v2.5 02-Jul-2014 19:28:36
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @untitled_OpeningFcn, ...
'gui_OutputFcn', @untitled_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 untitled is made visible.
function untitled_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 GUIDA TA) % varargin command line arguments to untitled (see V ARARGIN)
% Choose default command line output for untitled
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes untitled wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = untitled_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see V ARARGOUT); % hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDA TA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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 GUIDA TA) syms t;
f1=get(handles.edit1,'string');
y1=subs(f1,-t);
ezplot(y1);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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) f1=get(handles.edit1,'string');
f2=get(handles.edit2,'string');
y=strcat(f1,'+',f2);
ezplot(y);
% --- 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 GUIDA TA) syms p k1 k2;
f=get(handles.edit1,'string');
g=get(handles.edit2,'string');
p=0.01; % p:取样时间间隔
k1=-10:p:10; % k1: f(t)的对应时间向量
k2=k1; % k2: 序列g(t)的对应时间向量
f=subs(f,k1); % f: f(t)的非零样值向量
g=subs(g,k2); % g: g(t)的非零样值向量
y=conv(f,g); %计算序列f与g的卷积和y
y=y*p;
k0=k1(1)+k2(1);%计算序列y非零样值的起点位置
k3=length(f)+length(g)-2; %计算卷积和y的非零样值的宽度
k=k0:p:k0+k3*p; %确定卷积和y非零样值的时间
plot(k,y);
% --- 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) f1=get(handles.edit1,'string');
f2=get(handles.edit2,'string');
y=strcat(f1,'*',f2);
ezplot(y);
% --- 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 GUIDA TA)
syms t;
f1=get(handles.edit1,'string');
a1=get(handles.edit3,'string');
y1=subs(f1,a1*t);
ezplot(y1);
% syms t;
% f2=get(handles.edit2,'string');
% a2=get(handles.edit3,'string');
% y2=subs(f2,a2*t);
% ezplot(y2);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDA TA)
syms t;
f1=get(handles.edit1,'string');
t01=get(handles.edit4,'string');
y1=subs(f1,t-t01);
ezplot(y1);
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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 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 GUIDA TA)
% 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 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 GUIDA TA)
% 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); 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 GUIDA TA)
% 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
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate axes1
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA) syms t;
f1=get(handles.edit1,'string');
ezplot(f1);
% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDA TA) syms t;
f2=get(handles.edit2,'string');
ezplot(f2);
% --- Executes on button press in pushbutton13.
function pushbutton13_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton13 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDA TA) syms t;
f2=get(handles.edit2,'string');
a2=get(handles.edit3,'string');
y2=subs(f2,a2*t);
ezplot(y2);
% --- Executes on button press in pushbutton14.
function pushbutton14_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton14 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDA TA) syms t;
f2=get(handles.edit2,'string');
t02=get(handles.edit4,'string');
y2=subs(f2,t-t02);
ezplot(y2);
% --- Executes on button press in pushbutton15.
function pushbutton15_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton15 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDA TA) syms t;
f2=get(handles.edit2,'string');
y2=subs(f2,-t);
ezplot(y2);。