-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathECG.m
164 lines (145 loc) · 4.96 KB
/
ECG.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
function varargout = ECG(varargin)
%ECG MATLAB code file for ECG.fig
% ECG, by itself, creates a new ECG or raises the existing
% singleton*.
%
% H = ECG returns the handle to a new ECG or the handle to
% the existing singleton*.
%
% ECG('Property','Value',...) creates a new ECG using the
% given property value pairs. Unrecognized properties are passed via
% varargin to ECG_OpeningFcn. This calling syntax produces a
% warning when there is an existing singleton*.
%
% ECG('CALLBACK') and ECG('CALLBACK',hObject,...) call the
% local function named CALLBACK in 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 ECG
% Last Modified by GUIDE v2.5 01-May-2018 03:31:04
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @ECG_OpeningFcn, ...
'gui_OutputFcn', @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 ECG is made visible.
function 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 ECG
handles.output = hObject;
% % START USER CODE
% % Specify function handles for its start and run callbacks
set(handles.ecggraphtitle, 'String', 'ECG Waveform');
% handles.axesECG=axes;
% k=[-10,0.00001,10];
% SQ=k.^2;
% handles.SQ=SQ;
% % END USER CODE
% % Update handles structure
guidata(hObject, handles);
% --- Outputs from this function are returned to the command line.
function varargout = 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;
% function y = ECGsq(x)
% y=x.^2;
% --- Executes on button press in StartECGbutton.
function StartECGbutton_Callback(hObject, eventdata, handles)
% hObject handle to StartECGbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clear all;
fs=1e2;
t=[];
c=0;
s=serial('/dev/cu.usbmodem1411');
set(s,'BaudRate',9600);
fopen(s);
for i=1:12000
T=str2num(fgetl(s));
t=[t,T];
end
fclose(s);
g=length(t);
if mod(g,2) == 1
g=g-1;
end
g=g/2;
for i=1:g
c(i)=t(2*i-i)*5/1023.0;
end
e=(1:g)/100;
plot(handles.axesECG,e,c);
% a = arduino('/dev/cu.usbmodem1411','Uno');
% ECGline=line(nan, nan, 'color', 'red');
%
% i=0;
% flag=0;
% interval=5000;
% x=zeros(1,5000); y=zeros(1,5000);
% Fs=1e3;
%
% LP = designfilt('lowpassfir','FilterOrder',20,'CutoffFrequency',150, ...
% 'DesignMethod','window','Window',{@kaiser,3},'SampleRate',Fs);
% HP = designfilt('highpassfir','FilterOrder',20,'CutoffFrequency',0.05, ...
% 'DesignMethod','window','Window',{@kaiser,3},'SampleRate',Fs);
%
% while (i<interval)
% ECGn=readVoltage(a,'A1');
% pause(0.1);
% x=[x, i];
% % ECGlp=filter(LP,ECGn); %lowpass
% % ECGhp=filter(HP,ECGlp); %highpass
% % ECGbsq=diff(ECGhp); %differentiation
% % ECGsqn=SQ(ECGbsq); %squaring
% % ECGc=integral(ECGsqn,-inf,+inf); %integration
% y=[y, ECGn];
% xlabel('time [s]');
% ylabel('Voltage [mV]');
% grid minor;
% set(ECGline, 'xData', x, 'yData', y);
% grid on;
% i=i+1;
% pause(0.5);
% if (flag==1)
% break;
% end
% end
% --- Executes on button press in BackECGButton.
function BackECGButton_Callback(hObject, eventdata, handles)
% hObject handle to BackECGButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
HomeScreen
close(ECG)
% --- Executes on button press in StopECGButton.
function StopECGButton_Callback(hObject, eventdata, handles)
% hObject handle to StopECGButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
flag=1;