?? ecgbeatfitter.m
字號:
function varargout = ECGBeatFitter(varargin)
%
% ECGBeatFitter(ECG,Phase,ExpParamName),
% Graphical user interface for ECG approximation with Gaussian kernels.
%
% inputs:
% ECG: a single ECG waveform used for model training
% Phase: the phase corresponding to the ECG waveform
% ExpParamName (optional): The name of the vector containing the exported parameter (default:OptimumParams)
% Title (optional): The title of the plot
%
%
% Open Source ECG Toolbox, version 1.0, November 2006
% Released under the GNU General Public License
% Copyright (C) 2006 Reza Sameni
% Sharif University of Technology, Tehran, Iran -- LIS-INPG, Grenoble, France
% reza.sameni@gmail.com
% This program is free software; you can redistribute it and/or modify it
% under the terms of the GNU General Public License as published by the
% Free Software Foundation; either version 2 of the License, or (at your
% option) any later version.
% This program is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
% Public License for more details. You should have received a copy of the
% GNU General Public License along with this program; if not, write to the
% Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
% MA 02110-1301, USA.
% ECGBEATFITTER M-file for ECGBeatFitter.fig
% ECGBEATFITTER, by itself, creates a new ECGBEATFITTER or raises the existing
% singleton*.
%
% H = ECGBEATFITTER returns the handle to a new ECGBEATFITTER or the handle to
% the existing singleton*.
%
% ECGBEATFITTER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ECGBEATFITTER.M with the given input arguments.
%
% ECGBEATFITTER('Property','Value',...) creates a new ECGBEATFITTER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before ECGBeatFitter_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to ECGBeatFitter_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 ECGBeatFitter
% Last Modified by GUIDE v2.5 13-Sep-2006 17:43:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 0;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ECGBeatFitter_OpeningFcn, ...
'gui_OutputFcn', @ECGBeatFitter_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 ECGBeatFitter is made visible.
function ECGBeatFitter_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 ECGBeatFitter (see VARARGIN)
%setappdata(hObject,'SelectedIndeces',0);
mn = varargin{1};
phase = varargin{2};
if (nargin>5),
handles.ExpParamName = varargin{3};
else
handles.ExpParamName = 'OptimumParams';
end
if (nargin>6),
set(handles.text3,'String',varargin{4});
end
handles.Linehandles = [];
handles.Initmodhandle = [];
handles.Optmodhandle = [];
handles.SelectedIndeces = [];
handles.ECGmean = mn;
handles.ECGphase = phase;
handles.OptimizedParameters = [];
plot(mn,'linewidth',2);
grid on;
xlabel('Sample index');
ylabel('Amplitude (mV)');
hold on;
set(handles.axes1,'ButtonDownFcn',@MyButtonDownFcn);
% set(handles.figure1,'Pointer','crosshair');
ECGcurve = get(handles.axes1,'Children');
set(ECGcurve,'ButtonDownFcn',@MyButtonDownFcn);
% Choose default command line output for ECGBeatFitter
handles.output = hObject;
%handles.output = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes ECGBeatFitter wait for user response (see UIRESUME)
uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = ECGBeatFitter_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 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)
data = guidata(gcbo);
% delete(data.Initmodhandle);
delete(data.Optmodhandle);
% data.Initmodhandle = [];
data.Optmodhandle = [];
N = length(data.SelectedIndeces);
for i = 1:N
delete(data.Linehandles(i));
end
data.SelectedIndeces = [];
data.Linehandles = [];
set(data.kernelnumber,'String','');
set(data.opterror,'String','');
guidata(gcbo,data);
% --- Executes on button press in Optimize.
function Optimize_Callback(hObject, eventdata, handles)
% hObject handle to Optimize (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = guidata(gcbo);
% delete(data.Initmodhandle);
delete(data.Optmodhandle);
localpeaks = zeros(size(data.ECGmean));
I = max(round(data.SelectedIndeces),1);
I = min(I,length(data.ECGmean));
P = length(I);
localpeaks(I) = 1;
tetai = data.ECGphase(I(1:P));
alphai = 1.2*data.ECGmean(I(1:P));
bi = .04*ones(size(alphai));
options = optimset('TolX',1e-4,'TolFun',1e-4,'MaxIter',100);
InitParams = [alphai bi tetai];
OptParams = nlinfit(data.ECGphase,data.ECGmean,@ECGModel,InitParams,options);
%OptParams = lsqnonlin(@(InitParams) ECGModelError(InitParams,ECGmn,Phasemn,0),InitParams,InitParams-2,InitParams+2,options);
Model0 = ECGModelError(InitParams,data.ECGmean,data.ECGphase,1);
Model = ECGModelError(OptParams,data.ECGmean,data.ECGphase,1);
% data.Initmodhandle = plot(Model0,'g');
data.Optmodhandle = plot(Model,'r');
data.OptimizedParameters = OptParams;
er = 100*mean((Model-data.ECGmean).^2)/mean(data.ECGmean.^2);
set(data.kernelnumber,'String',length(data.SelectedIndeces));
set(data.opterror,'String',round(100*er)/100);
guidata(gcbo,data);
% --- Executes on button press in ExportData.
function ExportData_Callback(hObject, eventdata, handles)
% hObject handle to ExportData (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
assignin('base',handles.ExpParamName,handles.OptimizedParameters);
% handles.output = 1; % Function has finished execution
% guidata(hObject, handles);
uiresume(handles.figure1);
function MyButtonDownFcn(hObject, eventdata, handles)
pn = get(gca,'Currentpoint');
% hndl = plot(pn(1,1),pn(1,2),'ro');
ax = axis;
ln = line([pn(1,1),pn(1,1)],[ax(3),ax(4)]);
set(ln,'Color',[0 1 .5]);
data = guidata(gcbo);
data.SelectedIndeces = [data.SelectedIndeces pn(1,1)];
data.Linehandles = [data.Linehandles ln];
guidata(gcbo,data);
% --------------------------------------------------------------------
function Helpmenu_Callback(hObject, eventdata, handles)
% hObject handle to Helpmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --------------------------------------------------------------------
function About_1_Callback(hObject, eventdata, handles)
% hObject handle to About_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
AboutPath = which('About.htm');
web(AboutPath);
% --------------------------------------------------------------------
function Help_1_Callback(hObject, eventdata, handles)
% hObject handle to Help_1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
HelpPath = which('Help.htm');
web(HelpPath);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -