二、心电信号采集与处理简介
理论知识参考文献:心电信号采集及小波分析处理系统设计
三、部分源代码
function varargout = GUI_ECG(varargin)
%GUI_ECG M-file for GUI_ECG.fig
% GUI_ECG, by itself, creates a new GUI_ECG or raises the existing
% singleton*.
%
% H = GUI_ECG returns the handle to a new GUI_ECG or the handle to
% the existing singleton*.
%
% GUI_ECG('Property','Value',...) creates a new GUI_ECG using the
% given property value pairs. Unrecognized properties are passed via
% varargin to GUI_ECG_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% GUI_ECG('CALLBACK') and GUI_ECG('CALLBACK',hObject,...) call the
% local function named CALLBACK in GUI_ECG.M with the given input
% arguments.
%
% *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 GUI_ECG
% Last Modified by GUIDE v2.5 10-May-2021 16:17:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_ECG_OpeningFcn, ...
'gui_OutputFcn', @GUI_ECG_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 GUI_ECG is made visible.
function GUI_ECG_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 unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for GUI_ECG
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI_ECG wait for user response (see UIRESUME)
% uiwait(handles.figure1);
set(handles.COM_State,'string','COM closed');
global valys;
global valxs;
global scom;
global ECG;
valys=1;
valxs=0;
ECG=[];
try
scoms=instrfind;
fclose(scoms);
end
% --- Outputs from this function are returned to the command line.
function varargout = GUI_ECG_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 OpenCOM.
function OpenCOM_Callback(hObject, eventdata, handles)
% hObject handle to OpenCOM (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% sprintf('%d',get(hObject,'value'))
% Open COM
global scom;
if get(hObject,'value')
port=get(handles.Port,'value');
portstr=['COM',num2str(port)];
scom=serial(portstr);
scom.OutputBufferSize=4;
scom.InputBufferSize=27*2048;
set(scom,'BaudRate',256000,'Parity','none','DataBits',8,'StopBits',1);
try
fopen(scom);
set(hObject,'String','Close COM');
set(handles.COM_State,'string',['COM',num2str(port),' ', 'Open']);
catch
msgbox('Port Unavailable');
set(hObject,'value',0);
return;
end
% Close COM
else
set(handles.COM_State,'string','COMs closed');
set(hObject,'String','Open COM');
scoms=instrfind;
stopasync(scoms);
fclose(scoms);
delete(scoms);
end
% --- Executes during object creation, after setting all properties.
function Port_CreateFcn(hObject, eventdata, handles)
% hObject handle to Port (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on selection change in Port.
function Port_Callback(hObject, eventdata, handles)
% hObject handle to Port (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = cellstr(get(hObject,'String')) returns Port contents as cell array
% contents{get(hObject,'Value')} returns selected item from Port
% --- Executes on button press in Configuration.
function Configuration_Callback(hObject, eventdata, handles)
% hObject handle to Configuration (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
uint8 command;
uint8 addr;
uint8 val;
% pn=get(handles.Port,'value');
% portstr=['COM',num2str(pn)];
% s=serial(portstr);
% s.OutputBufferSize=4;
% s.InputBufferSize=27;
% set(s,'BaudRate',256000,'Parity','none','DataBits',8,'StopBits',1,'ReadAsyncMode','continuous',...
% 'BytesAvailableFcnCount',27,'BytesAvailableFcnMode','byte','BytesAvailableFcn',{@bytes,handles});
% try
% fopen(s);
% catch
% msgbox('Port Unavailable');
% return;
% end
% global mark;
global scom;
sm=get(handles.Signal_Mode,'value');
if sm==1
v2=hex2dec('20');
v512=hex2dec('60');
else
v2=hex2dec('30');
v512=hex2dec('65');
end
command(1)=hex2dec('72');
command(2)=hex2dec('02');
for i=1:19
if(i<17) addr(i)=i;
else addr(i)=i+6;
end
val(i)=0;
end
addr=addr+64;
val(1)=hex2dec('86');
val(2)=v2;
val(3)=hex2dec('CC');
for k=5:12
val(k)=v512;
end
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 沈再阳.精通MATLAB信号处理[M].清华大学出版社,2015.
[2]高宝建,彭进业,王琳,潘建寿.信号与系统——使用MATLAB分析与实现[M].清华大学出版社,2020.
[3]王文光,魏少明,任欣.信号处理与系统分析的MATLAB实现[M].电子工业出版社,2018.
[4]郑雷,李国蕾,王晓军,王丽,刘艳霖,李颖,高泽利.心电信号采集及小波分析处理系统设计[J].实验科学与技术. 2014,12(01)