Automatic Recognition of ECG Lead Misplacement in Python

DOI : 10.17577/IJERTV7IS070056

Download Full-Text PDF Cite this Publication

Text Only Version

Automatic Recognition of ECG Lead Misplacement in Python

Dhaani Kulshreshtha, Alice Cheeran Department of Electrical Engineering Veermata Jijabai Technologial Institute Mumbai, India

Vaibhav Awandekar

A3-rmt Pvt. Ltd. Mumbai, India

Abstract – Electrocardiogram (ECG) is a method to monitor the electrical functioning of the heart. Lead misplacements take place in up to 4% of the ECG readings taken in urban clinical settings. This number is even higher in rural settings due to inadequate training. This can often lead to misdiagnosis and incorrect treatment. This project looks at detecting lead misplacement at the time of acquisition in order to avoid this misdiagnosis in 12 lead ECG systems. Two approaches have been explored for this purpose. The first is based on wavelet transform with dynamic thresholding and windowing. The second is a neural network based approach. Of these, the first is applied successfully and a usable system has been developed. The neural network has been created but not trained to its potential due to the limitation posed by an inadequate labelled dataset for training and validation.

Keywords: ECG, Electrocardiogram, Lead reversal, Lead misplacement, Wavelet Transform, Neural networks


    ECG is a non-invasive method to monitor the electrical activity of the heart through electrodes placed on the skin at specific points. A 12 lead ECG system makes use of 10 such electrodes, with one electrode placed on each limb and six electrodes placed on chest. The potential difference obtained from various combinations of these electrodes provides us with twelve signal representations of the electrical functioning of the heart from different perspectives.

    Due to the limitation of healthcare services provided in rural India, the operators of medical and diagnostic equipment often receive very limited training. This leads to raised likelihood of incorrect connections and misplacements of leads. As the diagnosis and treatment of the patient is carried out on the basis of these readings, it can prove to be dangerous for the patient.

    Wavelet transform is a tool for time-frequency analysis of signals. It has found widespread application in biosignal processing due to its ability to examine complex non- stationary signals. The daubechies family of wavelets are found to be suitable for the analysis of ECG signals.

    Artificial neural network refers to a group of interconnected nodes inspired by the structure of connections between neurons in the brain. These systems are trained to perform various tasks without being given specific rules or instructions. It is useful when an application requires one to spot a pattern in data. It also provides an efficient method for classification problems, provided enough labelled training data is available.

    The Visual Geometry Group VGG 16 is a 16 layer convolutional neural network created for applications in image recognition. For this application, transfer learning is applied to learn the edge detection capability of VGG 16. The later layers are modified for the required classification problem.

    This project explores two methods for the automatic recognition of ECG lead misplacement in Python. The first approach uses denoising through wavelet transforms followed by dynamic windowing and thresholding to obtain features. It then uses static conditions based on these features to check whether an interchange has occurred and to identify the detected interchange. The second approach uses a Convolutional Neural Network created by applying transfer learning from VGG 16 followed by training using labelled datasets of genuine ECG readings as well and readings obtained with specific lead interchanges.

    This paper is divided into four sections. Section I introduces the topic. Section II describes the methodology used. Section III states the results obtained with the implementation of the described methods. Section IV provides the conclusion of the project.


    1. Method 1

      The flow of the system is as shown in Fig. 2.1.1. The system is idle until ECG acquisition is initiated. Once the ECG acquisition is completed, the recognition of ECG lead misplacement is carried out as explained in the following section.

      Fig. 2.1.1: System Flow of Project by Method I

      1. Load files

        In order to accurately detect any lead misplacement, all 12 leads are to be obtained. In this project, filtered ECG data is acquired. Therefore, further filtering is not necessary. However, if an error occurs while loading the file, the system returns to idle rather than terminating the process abruptly.

      2. Feature Extraction

        Feature Extraction is a process consisting of multiple steps as shown in Fig. 2.1.2. In order to identify the feature locations, Lead II signal is analyzed, since it contains relatively more distinct peaks as compared to the other leads.

        Wavelet transform is applied to Lead II signal. In this case, the Daubechies 4 wavelet (db4) is used. The level 2 reconstruction is obtained. Using peak detection with a threshold of minimum amplitude, the R peaks are detected. The locations of these R peaks are recorded. These locations are multiplied with a factor of 4 to get the approximate R peak locations in the original signal. Once again, using a peak detector in small windows around these approximate R peak locations in the original signal, the R peaks in the original Lead II signal are obtained.

        Once the R peak locations in the original Lead II signal are obtained, they are used to calculate the heart rate and average interval of each heart cycle. Based on this interval, the width of the windows to locate the other features is calculated. The R peak locations are used as reference points with which the remaining features, i.e. the P wave location, P onset, P offset, Q wave location, S peak location, QRS interval, PR interval, T peak location, and T interval, of the cardiac cycle in Lead II waveform are measured.

        Fig. 2.1.2: Work flow for Feature Extraction

        The location of the features or waves in all Leads will be the same as the signals are obtained simultaneously. However, their amplitudes and shapes will differ from Lead to Lead. These amplitudes and patterns are used in diagnosis of various heart conditions and abnormalities. These will be used to identify Lead interchanges and misplacements in this project.

        Based on the locations of the waves and features obtained from Lead II, the features in the remaining leads are identified.

        If the signal is too noisy or if, due to some error, the features cannot be extracted or identified, the system returns to idle and does not terminate the process abruptly.

      3. Limb lead check

      Based on an extensive literature survey, an optimized algorithm is developed in order to recognize whether any form of lead interchange or misplacement has taken place. It also identifies which interchange or misplacement has been detected.

      This algorithm was carefully developed to ensure that no heart condition or abnormality is dismissed as manual error while also controlling the number of conditions and criteria that are used as reference in order to limit the processing time. This algorithm is verified using a dataset consisting of 119 samples of real patient ECG readings.

    2. Method 2

    The system flow for this method is as shown in Fig. 2.2.1.

    Fig. 2.2.1: System Flow of Project by Method II

    1. Preprocess data

      The preprocessing of the data is carried out in stages as shown in Fig. 2.2.2

      Fig. 2.2.2: Preprocessing of Data

      The ECG signal was first divided into individual heartbeats. These signal segments were converted into images as shown in Fig. 2.2.3. Due to it being a 12 lead system, 12 images were obtained for each beat. Using various methods, two images for all the 6 leads for each heartbeat was obtained, with one image representing the limb leads and a second image representing the precordial leads. This involved superimposing pairs of leads, with each assigned a different weight (combined 2:1) to obtain images like the one shown

      in Figure 2.2.4. to obtain 6 images which were combined into 2 images (combined 3:1) by having each greyscale image assigned to a different colour component in RGB respectively for the final image. The final images are as shown in Fig. 2.2.5.

      Fig. 2.2.3: Single beat converted into image

      Fig. 2.2.4: Two superimposed Leads in greyscale

      Fig. 2.2.5: Single beat over all 6 Limb Leads converged in single image

    2. Create training data set

      A data set to train the neural network is created by acquiring a large number of 12 lead ECG readings in the required format. The training dataset used here consists of 95 labelled samples.

    3. Neural network

      Transfer learning was employed to employ the edge detection capacity of VGG16. The final layers were modified to suit the classification problem at hand. The resulting neural network is a convolutional neural network. This network was trained using the training data set acquired for this purpose.

    4. Check for interchange

      Once trained, the neural network is used to identify any misplacement or interchange that may occur in the electrodes during the acquisition of ECG readings. The test set used here consists of 24 samples.

      1. Method 1


    Table 3.3: Results for Method 2

    Dataset in consideration

    No. of samples accurately Identified

    Total samples in set

    Percentage of accurate identification in set

    Training set




    Test set




    An algorithm for the detection of misplacement of ECG leads has been developed and implemented.


    No. of samples

    Values in %

    No interchange accurately identified



    Total samples with no interchange



    Table 3.1: Results on non-interchanged data for Method I

    Table 3.2: Results on interchanged data for Method I



No. of samples

Values in %

Interchange missed



Interchange accurately detected



Interchange accurately identified



Total interchanged samples



Due to the widespread problem of lead interchanges during ECG acquisition, a system based in Python has been developed as proposed in the paper. The system accurately detects any lead interchange and identifies the same, giving an adequate warning in case an interchange has occurred during ECG acquisition, prompting the ECG technician to recheck the connections when required as well as in case of any ambiguity. This ensures that all the readings acquired are reliable and may form the basis for the diagnosis of the patient. The neural network based approach may be pursued further in case a much larger dataset is available for better results.

The system is tested using a dataset consisting of 119 samples. Of these, no interchange occurred while acquiring 17 samples, as mentioned in Table 3.1. Of these, 11, that is 64.71%, are accurately identified as not interchanged. As presented in Table 3.2, 102 samples with interchanged leads are also checked. In 74 samples, that is 72.55%, an interchange is detected. Of these, the type of interchange is accurately identified in 64 samples, which makes up 86.49% of the detected interchange instances, which is 62.75% of the total samples.

In the case of ambiguity, as is often the case, the reading is treated as an interchange. This is to ensure that the connections are rechecked by the ECG technician and any readings thus obtained are reliable and can be used for diagnosis of the patient.

    1. Method 2

The implemented neural network is trained on a training set consisting of 95 samples. The results are as presented in Table

3.3. When tested on this dataset, it identifies the lead interchange in 57 samples, which translates to an accuracy of 60%. When tested on a test set of 24 samples, it detects any interchange of ECG leads in 11 samples giving an accuracy of 45.80%. Therefore, it can be concluded that this neural network has high bias due to an inadequate training set. This approach is not being pursued further due to the limitation posed by unavailability of feasible datasets for effective training in this project.


  1. Bo Hedén, MD1, Mattias Ohlsson, PhD2, Holger Holst, BM1, Mattias Mjöman, BM1, Ralf Rittner, MSc1, Olle Pahlm, MD, PhD1, Carsten Peterson, PhD2, Lars Edenbrandt, MD, Detection of Frequently Overlooked Electrocardiographic Lead Reversals Using Artificial Neural Networks, The American Journal of Cardiology, October 1996

  2. Paul S Addison, Wavelet transforms and the ECG: a review,

    Physiological Measurement, Vol. 26,2005, p. 155-199

  3. Mary Ann Peberdy, MD, Joseph P. Ornato, MD, Recognition of Electrocardiographic Lead Misplacements, American Journal of Emergency Medicine, Volume 11, Number 4 R July 1993, pp. 403-405

  4. Inan Gu¨ler, ElifDerya U¨ beyli, ECG beat classifier designed by combined neural network model, Rattern Recognition 38(2005)199- 298

  5. Stanislaw Osowski,Linh Tran Hoai,and Tomasz Markiewicz,Support Vector Machine-Based Expert System for Reliable Heartbeat Recognition, IEEE Transactions on Biomedical Engineering,

    VOL.51,NO.4,APRIL 2004

  6. Velislav N. Batchvarov, Marek Malik, A. John Camm, Incorrect electrode cable connection during electrocardiographic recording,

    European Society of Cardiology, 10 October 2017, pp. 1081-1090

  7. Qibin Zhao, Liqing Zhang, ECG Feature Extraction and Classification Using Wavelet Transform and Support Vector Machines, IEEE Conference, November 2005, pp. 1089-1092

  8. Javier Garcia-Niebla, et al., Technical Mistakes during the Acquisition of the Electrocardiogram, Annals of Noninvasive Electrocardiology,

    October 2009, pp. 389-403

  9. Adrian Baranchuk, et al., Electrocardiography Pitfalls and Artifacts:

    The 10 Commandments, Critical Care Nurse, March 2009, pp. 67-73

  10. Hoshiar Abdollah, John A. Milliken, Recognition of Electrocardiographic Left Arm/Left Leg Lead Reversal, The American Journal of Cardiology, Vol. 80, November 1997, pp. 1247- 1249

  11. Anil George, et al., aVR- The forgotten lead, Exp Clinical Cardology,

    Vol 15 No 2, 2010, pp. 36-44

  12. Michal Kania, The effect of Precordial Lead Displacement on ECG Morphology, Med Biol Eng Comput, 2014, pp. 109-119

  13. Rachid Haddadi Elhassane Abdelmounim, Abdelaziz Belaguid, Discrete Wavelet Transform Based Algorithm for Recognition of QRS Complexes, World of Computer Science and Information Technology Journal, Vol 4 No 9, 2014, pp. 127-132

  14. Vikrant Bhateja, et al., A Composite Wavelets and Morphology Approach for ECG Noise Filtering, Springe-Verlag Berlin Heidelberg, 2013, pp. 361-366

  15. Kaja Mohammad Rasheed, ECG Mishaps, Artifacts and Operator Faults, Bangladesh Critical Care Journal, March 2017

  16. Richard Lynch, ECG Lead Misplacement: A Brief Review of Limb Lead Misplacement, African Journal of Emergency Medicine, Vol 4, 2014, pp. 130-139

  17. Jayanta Kumar Basu, Debnath Bhattacharyya, Tai-hoon Kim, Use of Artificial Neural Network in Paattern Recognition, International Journal of Software Engineering and Its Applications, Vol 4 No 2, April 2010, pp. 23-34

  18. Harry G Mond, et al., Twisted Leads: The Footprints of Malpositioned Electrocardiographic Leads, Heart, Lung and Circulation, Vol 25, 2016, pp. 61-67

  19. Richard A Harrigan, et al., Electrocardiographic Electrode Misplacement, Misconnection, and Artifact, The Journal of Emergency Medicine, Vol 43 No 6, 2012, pp. 1038-1044

Leave a Reply