-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecgbeat.m
57 lines (42 loc) · 1.23 KB
/
ecgbeat.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
% ecgbeat.m
% Author - Arun Kumar A , Santhom Computing Facility
% Email - aka.bhagya@gmail.com
% 03/07/09
% Program to Calculate the beats of an ECG signal
% Uses Continuous Wavelet Transform
% Data file should be a 'csv' file
close all
clear all
clc
disp(' WELCOME ')
disp(' %%%%%%%')
disp('Program to calculate ECG beats')
disp('-------------------------------')
% User Inputs
file_name=input('Enter the name of the file with extention:','s');
sample_freq=input('Enter the sampling frequency of the signal:');
% Load file
data=csvread(file_name);
% Perform CWT with scale 3 and wavelet Coiflet-1
cof=cwt(data,3,'coif1');
% R -Peak Identification
cofsq=cof.^2;
threshold=mean(cofsq);
peak=0;
%datapoints=6*sample_freq*10;
% Remove edge effects
cofsq(1)=0;
cofsq(end)=0;
ntime=6*sample_freq;
for i=1:ntime
if cofsq(i) >=threshold
peak=peak+1;
end
end
% Beats per minute
beats= peak; % (peak/sample_freq)*36;
% Show output
disp(sprintf('Beat interval is %g beats per minute',beats))
disp(' Thank You')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%