Aula 💡🕊️Ahmad TASKIARuba jasserReem Rasheed
Published © MIT

Leveraging ECG for Advanced Personal Identification

This project explores the potential of the Hexabitz EXG Module for secure ECG-based identification.

AdvancedWork in progressOver 33 days198
Leveraging ECG for Advanced Personal Identification

Things used in this project

Story

Read more

Schematics

H2BR0x-FactSheet

Code

H2BR0x-main code

C/C++
/*
 BitzOS (BOS) V0.3.2 - Copyright (C) 2017-2024 Hexabitz
 All rights reserved

 File Name     : main.c
 Description   : Main program body.
 */
/* Includes ------------------------------------------------------------------*/
#include "BOS.h"

/* Private variables ---------------------------------------------------------*/

/* Private function prototypes -----------------------------------------------*/

/* Main function ------------------------------------------------------------*/

int main(void){

	Module_Init();		//Initialize Module &  BitzOS

	//Don't place your code here.
	for(;;){}
}

/*-----------------------------------------------------------*/

/* User Task */
void UserTask(void *argument){

EXG_Init(ECG);
	

	// put your code here, to run repeatedly.
	while(1){


		

PlotToTerminal(P3,ECG);
		


			// 	  }

	}
}

/*-----------------------------------------------------------*/

EXG_Module

MATLAB
function varargout = EXG_Module(varargin)
% EXG_MODULE MATLAB code for EXG_Module.fig
%      EXG_MODULE, by itself, creates a new EXG_MODULE or raises the existing
%      singleton*.
%
%      H = EXG_MODULE returns the handle to a new EXG_MODULE or the handle to
%      the existing singleton*.
%
%      EXG_MODULE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in EXG_MODULE.M with the given input arguments.
%
%      EXG_MODULE('Property','Value',...) creates a new EXG_MODULE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before EXG_Module_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to EXG_Module_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 EXG_Module

% Last Modified by GUIDE v2.5 26-May-2024 22:36:32

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @EXG_Module_OpeningFcn, ...
                   'gui_OutputFcn',  @EXG_Module_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 EXG_Module is made visible.
function EXG_Module_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 EXG_Module (see VARARGIN)

% Choose default command line output for EXG_Module
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);
global Port index filteredECG
filteredECG=[];
index = 0;
channel='COM7';
Port=serial(channel,'BaudRate',115200,'Timeout',5); 


% UIWAIT makes EXG_Module wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = EXG_Module_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)
global Port filteredECG index
fopen(Port);
fs=120;
RecordTime=4; %sec
k=fs*RecordTime; % k Number of samples
ECG=[];
filteredECG=[];
t=0;
fprintf(Port,'a00s');   % start
for i=1:k
    tic;
     x=fscanf(Port); % size of message 
    if( isempty(x) )
        fclose(Port);
    end
    
    if ( x(1)=='a' && x(end)==10) % '\n' = 10
        delimiter_b_index = find(x=='b');
        ECG(i)= str2double(x(2 : delimiter_b_index -1) );  % mesage (a...b...\n)
        filteredECG(i)= str2double(x(delimiter_b_index + 1 :end - 1) );
    end
    t=toc+t;   
end
fprintf(Port,'a00f');  %stop
fclose(Port);
axes(handles.axes1);

plot(ECG(5:end))
grid on
axes(handles.axes2);

plot(filteredECG(5:end))
grid on
index = index +1;
fopen(Port);
fprintf(Port,'a00d');   % ask for HR
x=fscanf(Port); % size of message 
if( isempty(x) )
   fclose(Port);
else
    if ( x(1)=='a' && x(end)==10) % '\n' = 10
    HR = x(2 :end - 1);
%     HR = str2num(EOG_state);
    end
    set(handles.edit2,'string',HR);
    fclose(Port); 
end
    
  
function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (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 edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (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 edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
global Port
fopen(Port);
fprintf(Port,'a00w');   % ask for wires states
x=fscanf(Port); % size of message 
if( isempty(x) )
   fclose(Port);
else
    if ( x(1)=='a' && x(end)==10) % '\n' = 10
    wire_state = str2double(x(2 : end -1));  % mesage (a...\n)
    end
    fclose(Port); 
    if (wire_state==0)
        set(handles.edit1,'string','LeadP_CONNECTED_LeadN_CONNECTED');
    elseif (wire_state==1)
        set(handles.edit1,'string','LeadP_CONNECTED_LeadN_NOTCONNECTED');
    elseif (wire_state==2)
        set(handles.edit1,'string','LeadP_NOTCONNECTED_LeadN_CONNECTED');
    elseif (wire_state==3)
            set(handles.edit1,'string','LeadP_NOTCONNECTED_LeadN_NOTCONNECTED');
    end
end
    

        
% hObject    handle to pushbutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (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 edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (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 edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
delete(hObject);


% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global filteredECG index
ECGsignal=dataset(filteredECG');
export(ECGsignal,'XLSFile',['ECGsignal' num2str(index)]);


% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data1 = xlsread('ECGsignal1.xls');
data2 = xlsread('ECGsignal2.xls');
data3 = xlsread('ECGsignal3.xls');
data4 = xlsread('ECGsignal4.xls');
data5 = xlsread('ECGsignal5.xls');
[peaks1,locs1]=findpeaks(data1,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks2,locs2]=findpeaks(data2,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks3,locs3]=findpeaks(data3,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks4,locs4]=findpeaks(data4,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks5,locs5]=findpeaks(data5,'MinpeakHeight',1,'MinpeakDistance',60);
Data=[peaks1; peaks2; peaks3; peaks4; peaks5];
Data=Data(1:25);
%Data=Data'
% --- Executes on selection change in delete.
mynet=handles.mynet;
INPUTS=[Data;Data;Data];
INPUTS=INPUTS';
out=sim(mynet,INPUTS);
out=out';
sum(out)

% --- Executes on button press in delete.
function delete_Callback(hObject, eventdata, handles)
i=0:20;
 filei='E:\k\ECGsignal1.xls';
delete(filei);



% hObject    handle to delete (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on key press with focus on pushbutton5 and none of its controls.
function pushbutton5_KeyPressFcn(hObject, eventdata, handles)
% hObject    handle to pushbutton5 (see GCBO)
% eventdata  structure with the following fields (see MATLAB.UI.CONTROL.UICONTROL)
%	Key: name of the key that was pressed, in lower case
%	Character: character interpretation of the key(s) that was pressed
%	Modifier: name(s) of the modifier key(s) (i.e., control, shift) pressed
% handles    structure with handles and user data (see GUIDATA)
data1 = xlsread('ECGsignal1.xls');
data2 = xlsread('ECGsignal2.xls');
data3 = xlsread('ECGsignal3.xls');
data4 = xlsread('ECGsignal4.xls');
data5 = xlsread('ECGsignal5.xls');
[peaks1,locs1]=findpeaks(data1,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks2,locs2]=findpeaks(data2,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks3,locs3]=findpeaks(data3,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks4,locs4]=findpeaks(data4,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks5,locs5]=findpeaks(data5,'MinpeakHeight',1,'MinpeakDistance',60);
Data=[peaks1; peaks2; peaks3; peaks4; peaks5];



% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data1 = xlsread('newreem1.xlsx');
data2 = xlsread('newruba1.xlsx');
data3 = xlsread('newahmad1.xlsx');
inputs = [data1; data2; data3]';
targets = [repmat([1; 0; 0], 1, 25), repmat([0; 1; 0], 1, 25), repmat([0; 0; 1], 1, 25)];
hiddenLayerSize = [20 40 60];
net =feedforwardnet(hiddenLayerSize);
net.divideParam.trainRatio =0.6;
net.divideParam.valRatio = 0.2;
net.divideParam.testRatio = 0.2;
net.trainparam.lr=0.01;
net.trainFcn='trainlm';
[net,tr]=train(net,inputs,targets);
outputs = net(inputs);
errors = gsubtract(outputs,targets);
performance = perform(net,targets,outputs);
p = vec2ind(outputs);
p1 = vec2ind(targets);
%plotconfusion (targets,outputs)
figure, plotperform(tr)
view(net)
handles.mynet=net;
guidata(hObject,handles);



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data1 = xlsread('newreem1.xlsx');% peaks extracted from raw data
data2 = xlsread('newruba1.xlsx');% peaks extracted from raw data
data3 = xlsread('newahmad1.xlsx');% peaks extracted from raw data
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%standard diviation & mean value extractes also from raw data:
data11 = xlsread('reem1.xls');
data12 = xlsread('reem2.xls');
data13 = xlsread('reem3.xls');
data14 = xlsread('reem4.xls');
data15 = xlsread('reem5.xls');
ecgg=[data11;data12;data13;data14;data15];
ecgg1=(ecgg-min(ecgg));
ecgg1=ecgg1/max(ecgg1);
m=mean(ecgg1);
s = std(ecgg1);
data1(26)=m;
data1(27)=s;
%%%%%% ruba
data11 = xlsread('ruba1.xls');
data12 = xlsread('ruba2.xls');
data13 = xlsread('ruba3.xls');
data14 = xlsread('ruba4.xls');
data15 = xlsread('ruba5.xls');
ecgg=[data11;data12;data13;data14;data15];
ecgg1=(ecgg-min(ecgg));
ecgg1=ecgg1/max(ecgg1);
m=mean(ecgg1);
s = std(ecgg1);
data2(26)=m;
data2(27)=s;
%%%%%% Ahmad:
data11 = xlsread('ruba1.xls');
data12 = xlsread('ruba2.xls');
data13 = xlsread('ruba3.xls');
data14 = xlsread('ruba4.xls');
data15 = xlsread('ruba5.xls');
ecgg=[data11;data12;data13;data14;data15];
ecgg1=(ecgg-min(ecgg));
ecgg1=ecgg1/max(ecgg1);
m=mean(ecgg1);
s = std(ecgg1);
data3(26)=m;
data3(27)=s;
inputs = [data1; data2; data3]'; 
targets = [repmat([1; 0; 0], 1, 27), repmat([0; 1; 0], 1, 27), repmat([0; 0; 1], 1, 27)];
hiddenLayerSize = [20 40 60];
net =feedforwardnet(hiddenLayerSize);
net.divideParam.trainRatio =0.6;
net.divideParam.valRatio = 0.2;
net.divideParam.testRatio = 0.2;
net.trainparam.lr=0.01;
net.trainFcn='trainlm';
[net,tr]=train(net,inputs,targets);
outputs = net(inputs);
errors = gsubtract(outputs,targets);
performance = perform(net,targets,outputs);
p = vec2ind(outputs);
p1 = vec2ind(targets);
%plotconfusion (targets,outputs)
figure, plotperform(tr)
view(net)
handles.mynet=net;
guidata(hObject,handles);
% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
data1 = xlsread('ECGsignal1.xls');
data2 = xlsread('ECGsignal2.xls');
data3 = xlsread('ECGsignal3.xls');
data4 = xlsread('ECGsignal4.xls');
data5 = xlsread('ECGsignal5.xls');
[peaks1,locs1]=findpeaks(data1,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks2,locs2]=findpeaks(data2,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks3,locs3]=findpeaks(data3,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks4,locs4]=findpeaks(data4,'MinpeakHeight',1,'MinpeakDistance',60);
[peaks5,locs5]=findpeaks(data5,'MinpeakHeight',1,'MinpeakDistance',60);
Data=[peaks1; peaks2; peaks3; peaks4; peaks5];
Data=Data(1:25);
%standard diviation & mean value extractes also from raw data:
data11 = xlsread('ECGsignal1.xls');
data12 = xlsread('ECGsignal2.xls');
data13 = xlsread('ECGsignal3.xls');
data14 = xlsread('ECGsignal4.xls');
data15 = xlsread('ECGsignal5.xls');
ecgg=[data11;data12;data13;data14;data15];
ecgg1=(ecgg-min(ecgg));
ecgg1=ecgg1/max(ecgg1);
m=mean(ecgg1);
s = std(ecgg1);
Data(26)=m;
Data(27)=s;
%Data=Data'
% --- Executes on selection change in delete.
mynet=handles.mynet;
INPUTS=[Data;Data;Data];
INPUTS=INPUTS';
out=sim(mynet,INPUTS);
out=out';
sum(out)
% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

H2BR0x-Firmware

Credits

Aula 💡🕊️
60 projects • 224 followers
Electronic Engineering
Contact
Ahmad TASKIA
12 projects • 11 followers
MPhil. Bsc. ELECTRONICS Engineering
Contact
Ruba jasser
1 project • 0 followers
Contact
Reem Rasheed
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.