Peak detection in ECG signal - use of extinction values

This demonstration illustrates the use of contrast extinction value (also called dynamics), area and volume extinction values in processing of noisy ECG signal.

Using the contrast extinction value, it is possible to extract the ECG peaks and using area and volume extinction values, it is possible to extract the 60 Hz period of the noise.

 1 import scipy.io
 2 import numpy as np
 3 import iamxt.max_tree_alpha as MX
 4 import ia636
 5 mat = scipy.io.loadmat(find_attachment_file('courseTopics1S2013/lot_ecg/ecg.mat'))
 6 ecg_raw = mat['ecg']
 7 
 8 ecg = ia636.ianormalize(ecg_raw).astype('uint8')
 9 print ia636.iaimginfo(ecg)
10 adshow(ia636.iaplot(ecg, title='original signal'))
11 
12 Bc = np.ones((3,3), dtype = bool)
13 mxt = MX.MaxTreeAlpha(ecg,Bc)
14 H = mxt.computeHeight()
15 Hext = mxt.computeExtinctionValues(H,'height')
16 Himg = Hext[mxt.node_index]
17 adshow(ia636.iaplot(Himg, title='Height extinction values'))
18 
19 A = mxt.node_array[3,:]
20 Aext = mxt.computeExtinctionValues(A,'area')
21 Aimg = Aext[mxt.node_index]
22 adshow(ia636.iaplot(Aimg, title='Area extinction values'))
23 
24 V = mxt.computeVolume()
25 Vext = mxt.computeExtinctionValues(V,'volume')
26 Vimg = Vext[mxt.node_index]
27 adshow(ia636.iaplot(Vimg, title='Volume extinction values'))
<type 'numpy.ndarray'> (4170, 1) uint8 0 255

By inverting the signal, we can analyze its valleys:

1 mxt = MX.MaxTreeAlpha(255-ecg,Bc)
2 Hn = mxt.computeHeight()
3 Hnext = mxt.computeExtinctionValues(Hn,'height')
4 Hnimg = Hnext[mxt.node_index]
5 adshow(ia636.iaplot(Hnimg, title='Height extinction values (of valleys)'))

1 adshow(ia636.iaplot([ecg[:800],Himg[:800],Hnimg[:800]],title='Combined'))