www.gusucode.com > Matlab GUI创建用户界面语音信号进行频谱分析及滤波,高通、低通、带通等 > code23/pro.m
function varargout = pro(varargin) % PRO MATLAB code for pro.fig % PRO, by itself, creates a new PRO or raises the existing % singleton*. % % H = PRO returns the handle to a new PRO or the handle to % the existing singleton*. % % PRO('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in PRO.M with the given input arguments. % % PRO('Property','Value',...) creates a new PRO or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before pro_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to pro_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 pro % Last Modified by GUIDE v2.5 30-Jul-2011 20:14:57 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @pro_OpeningFcn, ... 'gui_OutputFcn', @pro_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 pro is made visible. function pro_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 pro (see VARARGIN) % Choose default command line output for pro handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes pro wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = pro_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) %读入数据 [file_name file_path] = uigetfile ('*.txt');% 读入txt文件 %global x; if file_path~=0 all=load([file_path,file_name]); end [m n]=size(all); %读入数据的大小 m*n input=all(:,1:n-1); output=all(:,n); %神经网络开始 input=input'; output=output'; %[pn,ps]=mapminmax(input); %输入归一化 %[tn,ts]=mapminmax(output); %输出归一化 for count=8:23; j=0; net=newff(input,output,count,{'logsig','purelin'},'trainlm'); %新建一个bp网络 net.trainParam.epochs=1000; net.trainParam.goal=0.000000000000000001; %设置误差的最小值 net.trainParam.lr=0.005; %设置步进 net=train(net,input,output); %训练网络 %save('bp-1','net');%保存网络为bp-1 % input_test=load('input.txt'); %加载要预测的输入数据 input_test=input; %output_test=load('output.txt'); %加载要预测的输出数据 output_test=output; % input_test=input_test'; %转置 %[ptn,ps]=mapminmax(input_test); %测试输入归一化 yt=sim(net,input_test); %仿真输出数据 %y=mapminmax('reverse',yt,ts); %测试输出归一化 yt=yt'; for i=1:n if abs(yt(i)-output_test(i))<0.5 j=j+1; end end if j/n>=0.6 save good_one net; rate=j/n; figure(1); title('the correct rate is :'); plot(1,rate,'ro'); str=sprintf('The correct rate is :%f',rate); %Update the text field set(handles.TextBox,'String',str); end end warndlg('the train has finished','Reminder','modal'); warndlg('Please input your test data','Reminder','modal'); choice = menu('Choose','choose your data','exit'); if choice==1 %读入要验证的数据 [file_name file_path] = uigetfile ('*.txt');% 读入txt文件 %global x; if file_path~=0 all_test=load([file_path,file_name]); end [m n]=size(all_test); %读入数据的大小 m*n input_test=all(:,1:n-1); output_test=all(:,n); input_test=input_test'; %[ptn,ps]=mapminmax(input_test); %测试输入归一化 yt=sim(net,input_test); %仿真输出数据 %y=mapminmax('reverse',yt,ts); %测试输出归一化 yt=yt'; for i=1:n if abs(yt(i)-output_test(i))<0.5 j=j+1; end end rate=j/n; figure(2); title('the correct rate is :'); plot(1,rate,'ro'); str=sprintf('The correct rate is :%f',rate); %Update the text field set(handles.TextBox,'String',str); end % --- 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)