gusucode.com > 能检测心电特征点PQRST,用matlab编写了界面,并能计算识别率 > ecg/ecg_gui.m
function varargout = ecg_gui(varargin) % ECG_GUI M-file for ecg_gui.fig % ECG_GUI, by itself, creates a new ECG_GUI or raises the existing % singleton*. % % H = ECG_GUI returns the handle to a new ECG_GUI or the handle to % the existing singleton*. % % ECG_GUI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in ECG_GUI.M with the given input arguments. % % ECG_GUI('Property','Value',...) creates a new ECG_GUI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before ecg_gui_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to ecg_gui_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 % Copyright 2002-2003 The MathWorks, Inc. % Edit the above text to modify the response to help ecg_gui % Last Modified by GUIDE v2.5 16-Jan-2010 19:22:15 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @ecg_gui_OpeningFcn, ... 'gui_OutputFcn', @ecg_gui_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 ecg_gui is made visible. function ecg_gui_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 ecg_gui (see VARARGIN) global pop_xielv; global pop_xishu; global pop_max; global pop; global pop_qrswave; global pop_filt; global pop_pt; pop_xielv=0; pop_xishu=0; pop_max=0; pop=0; pop_qrswave=0; pop_filt=0; pop_pt=0; % Choose default command line output for ecg_gui handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes ecg_gui wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = ecg_gui_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; function groupnum_Callback(hObject, eventdata, handles) % hObject handle to groupnum (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 groupnum as text % str2double(get(hObject,'String')) returns contents of groupnum as a double % --- Executes during object creation, after setting all properties. function groupnum_CreateFcn(hObject, eventdata, handles) % hObject handle to groupnum (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 on button press in radiobutton1. function radiobutton1_Callback(hObject, eventdata, handles) % hObject handle to radiobutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton1 global algo; if get(gcbo,'value')==1 set(findobj('tag','radiobutton2'),'Value',0); algo=1; end % --- Executes on button press in radiobutton2. function radiobutton2_Callback(hObject, eventdata, handles) % hObject handle to radiobutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of radiobutton2 global algo; if get(gcbo,'value')==1 set(findobj('tag','radiobutton1'),'Value',0); algo=2; end % --- Executes on button press in readdata. function readdata_Callback(hObject, eventdata, handles) % hObject handle to readdata (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global X; global sfreq; global groupnum; groupnum=get(handles.groupnum,'String'); [X sfreq]=readdata(groupnum); plot(X,'r'); xlim([0, 3600]); % --- Executes on button press in detection. function detection_Callback(hObject, eventdata, handles) % hObject handle to detection (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global algo; global P; global Q; global R; global S; global T; global X; global sfreq; global X1; global Y1; global Y4; global se; global Qstart; global Send; global swd; global swa; global Mj4; global groupnum; if algo==1 [R Q S P T X1 Y4 Y1 se Qstart Send]=PQRST_detect(X,sfreq); set(handles.showderiva,'Enable','on'); elseif algo==2 [R Q S P T X1 Qstart Send swd swa Mj4]=wPQRST_detect(X,sfreq); set(handles.coefficient,'Enable','on'); set(handles.extremum,'Enable','on'); end cla; PQRST_show(X,P,Q,R,S,T); switch groupnum case '1' load G1; G=G1; case '2' load G2; G=G2; case '3' load G3; G=G3; case '4' load G4; G=G4; otherwise load G5; G=G5; end [rightnum totalnum Reco_rate]=Recognition(P,Q,R,S,T,G); set(handles.total,'String',num2str(totalnum)); set(handles.right,'String',num2str(rightnum)); set(handles.ratio,'String',num2str(Reco_rate)); set(handles.pop,'Enable','on'); set(handles.qrswave,'Enable','on'); set(handles.filter,'Enable','on'); set(handles.filterpt,'Enable','on'); % --- Executes on button press in showderiva. function showderiva_Callback(hObject, eventdata, handles) % hObject handle to showderiva (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global X; global Y1; global se; global pop_xielv; figure('Name','原始心电信号及其一阶导数'); xielv_show(X,Y1,se); pop_xielv=1; % --- Executes on button press in coefficient. function coefficient_Callback(hObject, eventdata, handles) % hObject handle to coefficient (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global X; global swd; global swa; global pop_xishu; figure('Name','原始心电信号及其在1,2,3,4尺度下的尺度系数及小波系数'); xbxs_show(X,swd,swa); pop_xishu=1; % --- Executes on button press in extremum. function extremum_Callback(hObject, eventdata, handles) % hObject handle to extremum (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global Mj4; global pop_max; figure('Name','尺度3下小波系数的模极大值点'); max3_show(Mj4); pop_max=1; % --- Executes on button press in qrswave. function qrswave_Callback(hObject, eventdata, handles) % hObject handle to qrswave (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global algo; global pop_qrswave; global X; global Y4; global Qstart; global Send; figure('Name','QRS波群范围'); QRSwave_show(X,Qstart,Send); pop_qrswave=1; % --- Executes on button press in filter. function filter_Callback(hObject, eventdata, handles) % hObject handle to filter (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global X; global X1; global pop_filt; figure('Name','滤波前后的心电波形'); fliter_show(X,X1); pop_filt=1; % --- Executes on button press in filterpt. function filterpt_Callback(hObject, eventdata, handles) % hObject handle to filterpt (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global X1; global P; global T; global pop_pt;; figure('Name','滤波后心电信号的P点和T点'); fliterPT_show(X1,P,T); pop_pt=1; % --- Executes on button press in pop. function pop_Callback(hObject, eventdata, handles) % hObject handle to pop (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global P; global Q; global R; global S; global T; global X; global pop; figure('Name','原始心电信号的PQRST点'); PQRST_show(X,P,Q,R,S,T); pop=1; % --- Executes on button press in reset. function reset_Callback(hObject, eventdata, handles) % hObject handle to reset (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global pop_xielv; global pop_xishu; global pop_max; global pop; global pop_qrswave; global pop_filt; global pop_pt; set(handles.groupnum,'String',''); set(handles.total,'String',''); set(handles.right,'String',''); set(handles.ratio,'String',''); set(handles.showderiva,'Enable','off'); set(handles.coefficient,'Enable','off'); set(handles.extremum,'Enable','off'); set(handles.pop,'Enable','off'); set(handles.qrswave,'Enable','off'); set(handles.filter,'Enable','off'); set(handles.filterpt,'Enable','off'); set(findobj('tag','radiobutton1'),'Value',0); set(findobj('tag','radiobutton2'),'Value',0); cla; if pop_xielv==1 close ('原始心电信号及其一阶导数'); pop_xielv=0; end if pop_xishu==1 close ('原始心电信号及其在1,2,3,4尺度下的尺度系数及小波系数'); pop_xishu=0; end if pop_max==1 close ('尺度3下小波系数的模极大值点'); pop_max=0; end if pop==1 close ('原始心电信号的PQRST点'); pop=0; end if pop_qrswave==1 close ('QRS波群范围'); pop_qrswave=0; end if pop_filt==1 close ('滤波前后的心电波形'); pop_filt=0; end if pop_pt==1 close ('滤波后心电信号的P点和T点'); pop_pt=0; end % --- Executes on button press in quit. function quit_Callback(hObject, eventdata, handles) % hObject handle to quit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) delete(handles.figure1); close all; function total_Callback(hObject, eventdata, handles) % hObject handle to total (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 total as text % str2double(get(hObject,'String')) returns contents of total as a double % --- Executes during object creation, after setting all properties. function total_CreateFcn(hObject, eventdata, handles) % hObject handle to total (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 right_Callback(hObject, eventdata, handles) % hObject handle to right (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 right as text % str2double(get(hObject,'String')) returns contents of right as a double % --- Executes during object creation, after setting all properties. function right_CreateFcn(hObject, eventdata, handles) % hObject handle to right (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 ratio_Callback(hObject, eventdata, handles) % hObject handle to ratio (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 ratio as text % str2double(get(hObject,'String')) returns contents of ratio as a double % --- Executes during object creation, after setting all properties. function ratio_CreateFcn(hObject, eventdata, handles) % hObject handle to ratio (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