top of page

MATLAB Code

Github Code Credit to
- karthik raviprakash (2023). ECG simulation using MATLAB (https://www.mathworks.com/matlabcentral/fileexchange/10858-ecg-simulation-using-matlab), MATLAB Central File Exchange. Retrieved March 4, 2023.

- Said BOUREZG (2023). Open_ECG: ECG .dat file reader (https://www.mathworks.com/matlabcentral/fileexchange/49822-open_ecg-ecg-dat-file-reader), MATLAB Central File Exchange. Retrieved March 4, 2023.

Using these two codes 

Code 1: clear all clc close all [filename, pathname] = uigetfile('*.dat', 'Open file .dat');% only image Bitmap if isequal(filename, 0) || isequal(pathname, 0) disp('File input canceled.'); ECG_Data = []; else fid=fopen(filename,'r'); end; time=10; f=fread(fid,2*360*time,'ubit12'); Orig_Sig=f(1:2:length(f)); % plot(Orig_Sig) writetable(array2table(Orig_Sig),'test.csv')

Code 2 run = 1; while (run == 1)%while loop allows user to run the program again if they want to %build x axis array x=0.60008:0.00008:1.4; %query user to see if want to create a defualt typical ECG or custom ECG default=input('Press 1 if u want default ecg signal else press 2:\n'); if(default==1) %default waveform values li=30/72; %P wave and PR interval default settings a_pwav=0.25; %P wave amplitude d_pwav=0.09; %P wave duration t_pwav=0.16; %PR interval. This combined with P wave duration defines PR segment %Q wave default settings a_qwav=0.025; %Q wave amplitude d_qwav=0.066; %Q wave duration t_qwav=0.166; %not adjustable in program %R wave default settings a_qrswav=1.6; %R wave amplitude d_qrswav=0.11; %R wave duration %S wave default settings a_swav=0.25; %S wave amplitude d_swav=0.066; %S wave duration t_swav=0.09; %not adjustable in program %T wave default settings a_twav=0.35; %T wave amplitude d_twav=0.142; %T wave duration t_twav=0.2; %ST Interval %U wave default settings a_uwav=0.035; %U wave amplitude d_uwav=0.0476; %U wave duration t_uwav=0.433; %not adjustable in program else rate=input('\n\nenter the heart beat rate :'); li=30/rate; %p wave specifications fprintf('\n\np wave specifications\n'); d=input('Enter 1 for default specification else press 2: \n'); if(d==1) a_pwav=0.25; d_pwav=0.09; t_pwav=0.16; else a_pwav=input('amplitude = '); d_pwav=input('duration = '); t_pwav=input('p-r interval = '); d=0; end %q wave specifications fprintf('\n\nq wave specifications\n'); d=input('Enter 1 for default specification else press 2: \n'); if(d==1) a_qwav=0.025; d_qwav=0.066; t_qwav=0.166; else a_qwav=input('amplitude = '); d_qwav=input('duration = '); t_qwav=0.166; d=0; end %qrs wave specifications fprintf('\n\nqrs wave specifications\n'); d=input('Enter 1 for default specification else press 2: \n'); if(d==1) a_qrswav=1.6; d_qrswav=0.11; else a_qrswav=input('amplitude = '); d_qrswav=input('duration = '); d=0; end %s wave specifications fprintf('\n\ns wave specifications\n'); d=input('Enter 1 for default specification else press 2: \n'); if(d==1) a_swav=0.25; d_swav=0.066; t_swav=0.09; else a_swav=input('amplitude = '); d_swav=input('duration = '); t_swav=0.09; d=0; end %t wave specifications fprintf('\n\nt wave specifications\n'); d=input('Enter 1 for default specification else press 2: \n'); if(d==1) a_twav=0.35; d_twav=0.142; t_twav=0.2; else a_twav=input('amplitude = '); d_twav=input('duration = '); t_twav=input('s-t interval = '); d=0; end %u wave specifications fprintf('\n\nu wave specifications\n'); d=input('Enter 1 for default specification else press 2: \n'); if(d==1) a_uwav=0.035; d_uwav=0.0476; t_uwav=0.433; else a_uwav=input('amplitude = '); d_uwav=input('duration = '); t_uwav=0.433; d=0; end end pwav=p_wav(x,a_pwav,d_pwav,t_pwav,li); %qwav output qwav=q_wav(x,a_qwav,d_qwav,t_qwav,li); %qrswav output qrswav=qrs_wav(x,a_qrswav,d_qrswav,li); %swav output swav=s_wav(x,a_swav,d_swav,t_swav,li); %twav output twav=t_wav(x,a_twav,d_twav,t_twav,li); %uwav output uwav=u_wav(x,a_uwav,d_uwav,t_uwav,li); %ecg output ecg=pwav+qrswav+twav+swav+qwav+uwav; figure(1) %ecg plot(x,ecg); %Query the user to see what they want to do with the ECG waveform fprintf('Enter 1 to send to 33521A or 33522A\n'); fprintf('Enter 2 to send to .CSV file\n'); fprintf('Enter anything else to exit\n'); whereTo=input('Enter: '); if(whereTo==1) %query user for waveform name arbName = input('Enter a name for the waveform: ','S'); ecgScaled = ampScale(ecg); %scale waveform amplitude for AWG arbTo33500(ecgScaled,arbName); %send arb to a 33521A or 33522A elseif(whereTo==2) %query user for name of CSV file where waveform will be stored csvName= input('Enter a name for the waveform: ','S'); csvName = [csvName '.csv']; dlmwrite(csvName, ecg', 'coffset', 0, 'roffset', 0); else %fprintf('do nothing\n'); end %Query the user to see if they want to run the program again or exit run = input('Enter 1 to run program again or any other number to exit: '); if(run ~= 1) run = 69; end end fprintf('Done and outta here.......\n');

We were able to 

1. Test out an estimate of a ECG's data such as height, shape, width, and size of peaks to use with our Arduino live input

2. Read and plot the .dat files of the given data

 

 

 

 

 

3. 

Screen Shot 2023-03-04 at 1.14.59 PM.png
Screen Shot 2023-03-04 at 1.20.39 PM.png
Screen Shot 2023-03-04 at 1.25.56 PM.png
Screen Shot 2023-03-04 at 1.28.15 PM.png
Screen Shot 2023-03-04 at 1.27.24 PM.png

Contact

Cewit Building

Navigation

Home

EKG Readings

Our Code

bottom of page