image thumbnail
from ECG Beat Calculation by Arun Kumar
Calculates ECG beats per minute

ecgbeat.m
% 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;

for i=1:datapoints
    if cofsq(i) >=threshold
        peak=peak+1;
    end
end

% Beats per minute
beats= (peak/sample_freq)*10;

% Show output
disp(sprintf('Beat interval is %g beats per minute',beats))
disp('              Thank You')
disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Contact us at files@mathworks.com