function varargout = fashengqi1(varargin)
% FASHENGQI1 MATLAB code for fashengqi1.fig
% FASHENGQI1, by itself, creates a new FASHENGQI1 or raises the existing
% singleton*.
%
% H = FASHENGQI1 returns the handle to a new FASHENGQI1 or the handle to
% the existing singleton*.
%
% FASHENGQI1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FASHENGQI1.M with the given input arguments.
%
% FASHENGQI1('Property','Value',...) creates a new FASHENGQI1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before fashengqi1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to fashengqi1_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 fashengqi1
% Last Modified by GUIDE v2.5 17-May-2020 16:32:47
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fashengqi1_OpeningFcn, ...
'gui_OutputFcn', @fashengqi1_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 fashengqi1 is made visible.
function fashengqi1_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 fashengqi1 (see VARARGIN)
% Choose default command line output for fashengqi1
handles.output = hObject;
movegui(gcf,'center')
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes fashengqi1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = fashengqi1_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 when user attempts to close figure1.
function figure1_CloseRequestFcn(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)
% Hint: delete(hObject) closes the figure
delete(hObject);
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
global t y
global p1;%定义全局变量
global p2;
global p3;
global p4;
global p5;
global p6;
p6=0;
p5=0; %按钮正弦波按下
p2=0;
p3=0;
p4=0;
p1=get(handles.pushbutton1,'value');%获取正弦按钮的当前值并赋给p1
j=get(handles.sliderfuzhi,'value');%获取幅值滚动条的值,且赋给j
k=get(handles.sliderpinlv,'value');%获取频率滚动条的值,且赋给k
set(handles.editfuzhi,'string',num2str(j));%修改editfuzhi 的值为滚动条当前的值
set(handles.editpinlv,'string',num2str(k));%修改editpinlv 的值为滚动条当前的值
A=str2num(get(handles.editfuzhi,'string'));%获取幅值选择框的值,并且赋给A
f=str2num(get(handles.editpinlv,'string'));%获取频率选择框的值,并且赋给f
t=0:0.0001:8*pi;
y=A*sin(2*pi*f*t); %正弦波表达式
plot(t,y,'r');
set(gca,'color',[0,1,0.5]); %设定显示的背景颜色,
set(handles.axes1,'XLim',[0 0.05],'YLim',[-20 20])
%axis([0,8*pi,-1.2,1.2]); %曲线的颜色同时给出坐标并显示网格
grid on;
% 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.
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)
global t y
p2=get(handles.pushbutton1,'value');%获取正弦按钮的当前值并赋给p2
j=get(handles.sliderfuzhi,'value');%获取幅值滚动条的值,且赋给j
k=get(handles.sliderpinlv,'value');%获取频率滚动条的值,且赋给k
set(handles.editfuzhi,'string',num2str(j));%修改editfuzhi 的值为滚动条当前的值
set(handles.editpinlv,'string',num2str(k));%修改editpinlv 的值为滚动条当前的值
A=str2num(get(handles.editfuzhi,'string'));%获取幅值选择框的值,并且赋给A
f=str2num(get(handles.editpinlv,'string'));%获取频率选择框的值,并且赋给f
t=0:0.0001:6; y=A*square(2*pi*f*t,50);
plot(t,y,'r');
set(gca,'color',[0,1,0.5]);
set(handles.axes1,'XLim',[0 0.05],'YLim',[-20 20])
grid on;
% --- 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 t y
p3=get(handles.pushbutton1,'value');%获取正弦按钮的当前值并赋给p3
j=get(handles.sliderfuzhi,'value');%获取幅值滚动条的值,且赋给j
k=get(handles.sliderpinlv,'value');%获取频率滚动条的值,且赋给k
set(handles.editfuzhi,'string',num2str(j));%修改editfuzhi 的值为滚动条当前的值
set(handles.editpinlv,'string',num2str(k));%修改editpinlv 的值为滚动条当前的值
A=str2num(get(handles.editfuzhi,'string'));%获取幅值选择框的值,并且赋给A
f=str2num(get(handles.editpinlv,'string'));%获取频率选择框的值,并且赋给f
t=0:0.0001:20; y=A*sawtooth(pi*f*t,0.5);
plot(t,y,'r');
set(gca,'color',[0,1,0.5]);
set(handles.axes1,'XLim',[0 0.05],'YLim',[-20 20])
grid on;
% --- Executes on slider movement.
function sliderfuzhi_Callback(hObject, eventdata, handles)
% hObject handle to sliderfuzhi (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function sliderfuzhi_CreateFcn(hObject, eventdata, handles)
% hObject handle to sliderfuzhi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function sliderpinlv_Callback(hObject, eventdata, handles)
% hObject handle to sliderpinlv (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,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function sliderpinlv_CreateFcn(hObject, eventdata, handles)
% hObject handle to sliderpinlv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a