I will help you out a bit with the signal processing, and I will let you do the heart rate and all other necessary calculations:
fidi = fopen('Biza Ferreira ecg16.txt', 'rt');
Data = textscan(fidi, repmat('%f', 1, 11), 'Delimiter','\t', 'CollectOutput', 1, 'HeaderLines',8);
fclose(fidi);
Fs = 1000;
Fn = Fs/2;
Ts = 1/Fs;
EKG = Data{:}(:,4);
T = [0:size(EKG,1)-1]*Ts;
Rp = 5;
Rs = 25;
Wp = [2 50]/Fn;
Ws = Wp.*[0.2 1/0.2];
[n,Wn] = buttord(Wp, Ws, Rp, Rs);
[b,a] = butter(n,Wn);
[sos,g] = tf2sos(b,a);
EKGf = filtfilt(sos,g,EKG);
figure(1)
freqz(sos, 1024, Fs);
figure(2)
plot(T, EKGf)
hold on
plot(T, EKG)
hold off
grid
axis([0 2.5 ylim])
legend('Original', 'Bandpass Filtered')
title('Filtered and Unfiltered EKG')
xlabel('Time (sec)')
ylabel('Amplitude (mV)')
[R, Rt] = findpeaks(EKGf, Fs, 'MinPeakHeight',500);
figure(3)
plot(T, EKGf)
hold on
plot(Rt, R, '^r')
hold off
grid
axis([0 2.5 ylim])
legend('EKG', 'R-Wave Peaks')
title('Filtered EKG With R-Wave Locations')
xlabel('Time (sec)')
ylabel('Amplitude (mV)')
It is generally necessary to filter an EKG signal to remove the wandering baseline (usually due to respiratory motion) and high-frequency noise. This EKG had a bit of high-frequency noise, so I used a Butterworth bandpass filter to filter the noise and the baseline drift to get a stable baseline. I then used the findpeaks function to locate the R-waves and their times, since in this EKG it will work for that purpose. The best way to understand this code is to read the documentation on the various functions to understand what they do and how I used them here.
ABNORMAL EKG I am not certain where you got this EKG, and I am not certain what lead it is, but it is distinctly abnormal. The ST segment should be isoelectric in a healthy EKG, and there are about 2 mV of ST segment depression in this one. There is also a degree of electrical alternans in the R-wave amplitudes. The intervals and amplitudes are otherwise within normal limits. The abnormalities could be normal variants, but both need to be investigated with a full workup.
Best Answer