• No results found

Methods: Feature extraction and V,A,N classification on restricted

annotation file, was used to detect the RR intervals between consecutive QRS peaks in the ECG signals. The RR interval is one of the important features in the feature extraction model.

The ‘ecgpuwave –a qrs –r ecg_samples_file –o epu’ command, which uses the ‘qrs’ annotation file, was used to generate another annotation file with

‘epu’ extension. This annotation file contained the locations of the start ‘(‘, stop

‘)’ , P-wave ‘p’, QRS complex ‘N’ and T-wave ‘t’ sub annotation type locations in the fresh ECG signal.

The ‘rdann -a epu -r ecg_samples_file -p <annotation_subtype>’ command, which used the ‘epu’ annotation file from the previous ecgpuwave command, was used to locate the annotation subtypes ‘p’ and ‘t’ which are essentially P-wave and T waves with their onset and stop boundaries, the N type annotation being the QRS wave. The ‘rdann’ command was executed thrice for detecting the locations of P-wave, T-wave, QRS complex and their start and stop locations. The command generated a file for each of these annotation types and sub-types each containing a column of sample numbers which represented the locations of P-wave, T-wave and the QRS complex along with their start and stop positions.

4.6

Methods:

Feature extraction and V,A,N

classification on restricted device

A feature extraction algorithm 4.2 similar to algorithm 4.1 was developed, though this algorithm contained the WFDB format conversion pipeline described in section 4.5.3 which used WFDB routines to convert ECG samples acquired in real-time to a record compatible with WFDB and MITDB arrhythmia database. As the model trained on MITDB database would predict on the freshly acquired test signal, it was required that the signal was MITDB compatible. The classifier model was persisted and deployed on a restricted target device described in sections 3.1 and 3.5.

Algorithm 4.2 Real-time feature extraction algorithm for a resource constrained

device

1: procedure ECGPreprocessor

2: WRSAMP -F 360 -G 1000 -i ecgSamples.txt -o dat

. The routine generated the WFDB compatible ecgSamples.dat file

3: GQRS -r ecgSamples.dat -m 1.5

. The routine generated the ecgSamples.qrs file containing the locations for QRS peaks as compared to Algorithm 4.1 where the atr annotation file was used to extract feature annotations to train V, A, N classifier.

4: [qrsannsamplenums, qrsanntype] = RDANN -r ecgSamples -a qrs

. The routine read the QRS peaks annotations from the qrs file, qrsanntype took value N as compared to Algorithm 4.1 where the values were V, A, N

5: [rrintervals, rrsamplenumbers] = ANN2RR -a qrs -r ecgSamples

. The routine calculated the RR intervals from the qrs annotation file

6: [rrintervalsandsampnums] = [rrintervals rrsamplenumbers] 7: ECGPUWAVE -a qrs -r ecgSamples -o epu

. The routine generated the annotations file with extension epu containing the locations of (,), N, p, t annotations from the corresponding qrs file.

8: [epuAnnotSampN umbers, epuAnnotT ype] =

9: RDANN -a epu -r ecgSamples -p (, ), N, p, t

. The routine read the epu annotations file to return [epuAnnotSampN umbers, epuAnnotT ype] corresponding to the (, p, N, t,) annotations. return [epuAnnotSampN umbers, epuAnnotT ype]

10: end procedure

11:

12: procedure FeatureExtractionRealTime [epuAnnotSampN umbers,

epuAnnotT ype] = Call ECGPreprocessor . /*features initialised*/

13: f eatureP Rinterval = 0; f eatureP Rpsd =0;

14: f eatureQRSinterval = 0; f eatureQRSpsd =0; 15: f eatureRRinterval = 0;

16: f eatureP owerSpectralDensity = 0;

17: f eatureSN R = 0;

. /*Iterate all epu annotations: (,), p, N, t */

18: for iEP U annot = 0 : length(epuAnnotSampN umbers) - 1 do

19: if epuAnnotT ype(iEP U annot) == ’N’) then

. /*sample number at N-type annotation */

20: epusampnum = epuAnnotSampN umbers(iEP U annot); . /*iterate all atr annotations (V, A, N)*/

21: for iQRSann = 1 : length(qrsannsamplenums) - 1 do

. /*iterate all N-type annotations obtained from qrs annotator file only to obtain N-type annotation locations, as compared to Algorithm 4.1 where the class labels were obtained using the atr annotation file*/

4.6. Methods: Feature extraction and V,A,N classification on restricted device137

Algorithm 4.2 Real-time feature extraction algorithm for a resource constrained

device (continued)

22: if (qrsannsamplenums(iQRSann) >=

23: epuAnnotSampN umbers(iEP U annot - 1))

24: &&

25: (qrsannsamplenums(iQRSann) <=

26: epuAnnotSampN umbers(iEP U annot + 1)) then

./*iterate all N-type annotations and if epu annotations and qrs annotations do not match break the loop and proceed to next epu N-type annotation. In Algorithm 4.1 F eatureAnnotationT ype class label was assigned a value from (V, A, N). As this algorithm only generated feature vector samples,

f eatureAnnotationT ype was not required */

27: break For loop;

28: end if

29: end for

./*calculate f eatureP Rinterval and f eatureQRSinterval*/

30: k = iEP U annot - 1;

./*iterate epu annotations to locate start/end of P-wave and T-wave*/

31: while epuAnnotT ype(k) != ’N’ do

./*check if P-wave precedes QRS peak*/

32: if epuAnnotT ype(k) == ’p’ then

./* locate the PR segment on either side of the P-wave peak. WelchSpectrum and BandPower routines from Algorithm 4.1 */

33: prsamplef rom = epuAnnotSampN umbers(k - 1);

34: prsampleto = epuAnnotSampN umbers(k + 1);

35: f eatureP Rinterval = prsampleto - prsamplef rom; .

/*featurePRinterval*/

36: Xp[n] = prsamplef rom:prsampleto

37: [psd1] = Cal WelchSpectrum(Xs[n]);

38: f eatureP Rpsd = Call BandPower(psd1); ./* locate QRS interval segment on either side of QRS peak*/

39: qrssamplef rom = epuAnnotSampN umbers(iEP U annot -

1);

40: qrssampleto = epuAnnotSampN umbers(iEP U annot + 2); ./* featureQRSinterval*/

41: f eatureQRSinterval = qrssampleto - qrssamplef rom;

42: Xq[n] = qrssamplef rom:qrssampleto

43: [psd2] = Call WelchSpectrum (Xq[n] );

44: f eatureQRSpsd = Call BandPower(psd2));

45: break While loop;

./*Check if P-wave absent in which case T-wave from previous beat precedes QRS peak */

46: else if epuAnnotT ype(k) == ’t’ then

./* featurePRinterval set to zero if P-wave absent*/

Algorithm 4.2 Real-time feature extraction algorithm for a resource constrained

device (continued)

48: f eatureP Rpsd = 0;

./* locate QRS interval when P-wave absent*/

49: qrssamplef rom = epuAnnotSampN umbers(iEP U annot -

1);

50: qrssampleto = epuAnnotSampN umbers(iEP U annot + 2);

51: f eatureQRSinterval = qrssampleto - qrssamplef rom;

52: Xq[n] = qrssamplef rom:qrssampleto;

53: [psd3] = Call WelchSpectrum (Xq[n]);

54: f eatureQRSpsd = Call BandPower(psd3));

55: break While loop;

56: end if

57: k = k - 1;

58: if thenk == 0

59: break While loop;

60: end if

61: end while

62: for iRRann = 0 : length(rrSampleN umber) - 1 do . /* calculate featureRRinterval*/

./*check if RR-interval sample numbers coincide with epu sample numbers*/

63: if (rrSampleN umber(iRRann) >=

64: epuAnnotSampN umbers(iEP U annot - 1))

65: &&

66: (rrSampleN umber(iRRann) <=

67: epuAnnotSampN umbers(iEP U annot + 1)) then

68: f eatureRRinterval = rrIintervals(iRRann); Refer line 5

69: break For loop

70: end if

71: end for . /* for iRRann iteration ends*/

. /*calculate Signal-Noise-Ratio and Power Spectral Density over the entire heartbeat*/

72: samplespsdsnrf rom = epuAnnotSampN umbers(iEP U annot - 4);

73: samplespsdsnrto = epuAnnotSampN umbers(iEP U annot + 4);

74: Xsnr[n] = samplespsdsnrf rom: samplespsdsnrto

75: [psd4] = Call WelchSpectrum (Xsnr[n]);

76: f eatureP owerSpectralDensity = Call BandPower(psd4));

77: Ssnr[n] = samplespsdsnrf rom:samplespsdsnrto

78: f eatureSN R = Call SignalNoiseRatio(Ssnr[n]) ;

79: end if . /*iEP U annot == N ends */

80: newSampleRow = [f eatureP Rinterval, f eatureP Rpsd,

81: f eatureQRSinterval,

82: f eatureQRSpsd, f eatureRRinterval,

83: f eatureP owerSpectralDensity, f eatureSN R]

84: end for . /*iEP U annot iteration ends*/

4.6. Methods: Feature extraction and V,A,N classification on restricted device139

The feature vectors generated were according to the following tuple: {PR_Interval, PR_PSD, QRS_Interval, QRS_PSD, RR_Interval, Heart rate,

PowerSpectralDensity, SignalToNoiseRatio} where, PR_Interval: PR interval in a heartbeat waveform PR_PSD: the power spectral density in the PR interval QRS_Interval: the QRS duration in the QRS complex QRS_PSD: the power spectral density in the QRS complex

RR_Interval: the RR-interval at a given location in the waveform

PowerSpectralDensity: the power spectral density of the entire P QRS T wave SignalToNoiseRatio: the signal-to-noise ratio of the entire P QRS T wave. Target class variables: V, A, N annotations representing PACs, PVCs and Normal sinus rhythm

Having obtained the filtered signal it could be passed through the feature extraction algorithm implemented using WFDB routines and ported and deployed to the Beaglebone black. The algorithm used WFDB routines along with power spectral estimation methods in SciPy package to obtain the features from the test ECG signal acquired from human subject in real time. It was this ECG signal (converted to an MITDB compatible record) that was used by the classification model that was persisted on the Beaglebone black. The model could then classify between the V, A, N annotation types in real-time. The Algorithm 4.2 could extract WFDB compatible features, though only N-type annotations could be tested when used for healthy patients. A clinical trial would be required to test the algorithm on patients who are known to be suffering from cardiac arrhythmia to extract V-type and A-type annotations. Due to the scope of the research and limitations related to running clinical trials, the algorithm was tested only on an existing MITDB record MITDB/223 which was completely omitted from the training and test samples set. The record was chosen as it contained both the V-type and A-type annotations and the samples from the records were read into a test ecgSamples.txt text file and passed through algorithm 4.2 followed by the classifier model that was serialised and stored on the resource constrained

Beaglebone Black device.