用matlabguide做圆周卷积时域演示系统代码
下面是一个基于MATLAB GUIDE的圆周卷积时域演示系统的示例代码:
function varargout = circularConvolutionGUI(varargin)
% CIRCULARCONVOLUTIONGUI MATLAB code for circularConvolutionGUI.fig
% CIRCULARCONVOLUTIONGUI, by itself, creates a new CIRCULARCONVOLUTIONGUI or raises the existing
% singleton*.
%
% H = CIRCULARCONVOLUTIONGUI returns the handle to a new CIRCULARCONVOLUTIONGUI or the handle to
% the existing singleton*.
%
% CIRCULARCONVOLUTIONGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CIRCULARCONVOLUTIONGUI.M with the given input arguments.
%
% CIRCULARCONVOLUTIONGUI('Property','Value',...) creates a new CIRCULARCONVOLUTIONGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before circularConvolutionGUI_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to circularConvolutionGUI_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 circularConvolutionGUI
% Last Modified by GUIDE v2.5 02-Apr-2021 12:13:58
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @circularConvolutionGUI_OpeningFcn, ...
'gui_OutputFcn', @circularConvolutionGUI_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 circularConvolutionGUI is made visible.
function circularConvolutionGUI_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 circularConvolutionGUI (see VARARGIN)
% Choose default command line output for circularConvolutionGUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes circularConvolutionGUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = circularConvolutionGUI_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.
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 GUIDATA)
% Read input sequences
x = str2num(get(handles.edit1, 'String'));
h = str2num(get(handles.edit2, 'String'));
% Perform circular convolution
y = cconv(x, h, length(x));
% Plot the result
axes(handles.axes1);
stem(y);
xlabel('n');
ylabel('y[n]');
title('Circular Convolution');
grid on;
% --- 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)
% Clear input sequences and result
set(handles.edit1, 'String', '');
set(handles.edit2, 'String', '');
axes(handles.axes1);
cla;
% --- Executes during object deletion, before destroying properties.
function figure1_DeleteFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Clear input sequences and result
set(handles.edit1, 'String', '');
set(handles.edit2, 'String', '');
axes(handles.axes1);
cla;
% --- Executes on key press with focus on pushbutton1 and none of its controls.
function pushbutton1_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
if strcmp(eventdata.Key, 'return')
pushbutton1_Callback(hObject, eventdata, handles);
end
% --- Executes on key press with focus on pushbutton2 and none of its controls.
function pushbutton2_KeyPressFcn(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
% Key: name of the key that was pressed, in lower case
% Character: character interpretation of the key(s) that was pressed
% Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
if strcmp(eventdata.Key, 'return')
pushbutton2_Callback(hObject, eventdata, handles);
end
上述代码中,cconv函数是MATLAB中的一个内置函数,用于计算圆周卷积。这个GUI界面包含两个文本编辑框,用户可以在其中输入两个输入序列。点击“Calculate”按钮后,会读取输入序列并执行圆周卷积操作,然后将结果绘制在图形窗口中。点击“Clear”按钮或者关闭程序窗口时,输入序列和结果会被清空。
为了使用这个代码,你需要在MATLAB中创建一个新的GUI应用程序(使用GUIDE工具),然后将上述代码复制到GUI应用程序的.m文件中,并将对应的GUI控件(如文本编辑框、按钮和图形窗口)添加到GUI界面中。最后,保存并运行GUI应用程序即可。
原文地址: https://www.cveoy.top/t/topic/i6d8 著作权归作者所有。请勿转载和采集!