3lead Wireless ECG Anwar Vahed
3lead Wireless ECG Anwar Vahed
3lead Wireless ECG Anwar Vahed
Final Report
Abstract
This document presents an overview of the design process undertaken, as well as the project specifications in the design and implementation of a low cost wearable ECG system. A detailed explanation of the various modules of the design and their implementations is provided. Each module was successfully simulated and then implemented. There exists a demand for such systems as current implementations are complex to use, high in cost and inaccessible to the vast majority of South Africans. The system design aims to provide solutions to the problems encountered in acquiring from the body, as well as providing remote transmission, of ECG data. Two separate devices have been constructed to achieve the overall goal. A remote device is attached to the person being monitored. The remote device acquires the raw ECG data from the Leads which are placed in predefined areas of the body. The necessary filter requirements (for ECG frequency band selection) and formatting of filtered ECG data (for transmission) both occur in the DSPic microcontroller which is present in the mobile unit. The data is transmitted wirelessly using a low-cost RF Transceiver. A second Data acquisition unit is connected to USB port of a P.C. The unit has a second transceiver to receive and decode the data received from the remote unit. The data is then transmitted via the USB to the P.C for display. A user friendly graphical interface (GUI) was constructed using Visual Basic 6.0 enterprise edition. The GUI allows for the monitoring of real time ECG data. A database was implemented using MS Access 2000. This allowed for storage of the ECG data. The report provides a theoretical section on the 3-Lead ECG as well as how the heart generates the ECG signal. The design is then dissected into various models which are discussed individually. A separate section is provided on the integration of these modules.
Table of Contents
List of Abbreviations ......................................................................................................... iii List of Tables ..................................................................................................................... iv List of Figures..................................................................................................................... v 1. Introduction..................................................................................................................... 1 2. The Heart ....................................................................................................................... 2 2.1. The Activity of the Heart ......................................................................................... 2 2.2. Depolarisation and Repolarisation........................................................................... 3 3. The Three Lead ECG..................................................................................................... 4 4. ECG Frequency Bandwidth ........................................................................................... 5 5. ECG Interference Sources ............................................................................................. 6 5.1. Noise originating from sources external to the patient ............................................ 6 5.1.1. Electrostatic Sources......................................................................................... 6 5.1.2. Electromagnetic Induction ................................................................................ 6 5.2. Noise originating from the patient ........................................................................... 7 5.3. Noise originating from patient-electrode contact .................................................... 7 6. Feasibility Study ............................................................................................................ 8 7. Functional Specifications............................................................................................... 9 7.1. UML Case Diagram............................................................................................... 10 8. Non-Functional Specifications .................................................................................... 11 9. System Requirements .................................................................................................. 12 10. System Block Diagram .............................................................................................. 13 11. Wearable ECG Hardware .......................................................................................... 14 11.1. DSPIC30F3012 16-Bit Microcontroller .............................................................. 15 11.1.1. Analogue to Digital Converter...................................................................... 16 11.1.2. Programmable Serial USART....................................................................... 16 11.3. Aerocomm AC4486 wireless transceiver ............................................................ 17 11.3.1. Power Supply ................................................................................................ 18 11.4. Analogue Front End............................................................................................. 21 11.4.1. Differential Amplification ............................................................................ 21 11.4.2. Differential Amplifier Design....................................................................... 23 11.4.3. Anti-Aliasing Low-pass Filter ...................................................................... 24 11.4.4. Anti-Aliasing Low-pass Filter Design .......................................................... 25 11.5. Removing the D.C Offset Component................................................................. 25 11.6. Signal Offset and Gain stage................................................................................ 25 11.7. The Right-Leg Common mode feedback circuit ................................................. 26 11.8. DC Restoration Amplifier.................................................................................... 26 11.9. Results and Analysis of the Analogue Front End ................................................ 27 12. Microcontroller Firmware........................................................................................... 28 12.1. Analogue to Digital Converter Initialization ....................................................... 29 12.1.1. ADC Sampling Frequency............................................................................ 29 12.3. ADC Interrupt Service Routine ........................................................................... 31 12.4. Serial USART ...................................................................................................... 31 12.5. Digital Filters ....................................................................................................... 32 i
12.5.1. Digital IIR Notch Filter................................................................................. 32 12.5.2. Low Pass 4th order IIR Filter......................................................................... 33 12.5.3. DSPic30F3012 Implementation of IIR Digital Filters.................................. 35 12.5.4. Results and Analysis of Digital Filters ......................................................... 36 13. Wireless Communication............................................................................................ 38 13.1. Minimum Data Rate Requirements ..................................................................... 38 13.2. AC4486 Initialization........................................................................................... 39 14. Visual Basic 6.0 Graphical User Interface (GUI)....................................................... 41 14.1. MSComm Control................................................................................................ 41 14.1.1 Com Port Settings .......................................................................................... 42 14.2. GUI Functionality ................................................................................................ 42 14.2.1. Live Trace ..................................................................................................... 42 14.2.2. Verification of GUI Parameters .................................................................... 43 New Patient............................................................................................................... 44 15. ECG Live! Database System ...................................................................................... 46 16. System Enclosure (Mechanical Design) ..................................................................... 48 17. Conclusion .................................................................................................................. 49 18. References................................................................................................................... 50 Appendix A.......................................................................................................................... i Appendix B ........................................................................................................................ iii Appendix C ........................................................................................................................ iv Appendix D......................................................................................................................... v
ii
List of Abbreviations
D.C EMF A.C P.C GUI IA IC MIPS p-p ISR RF Direct Current (A) Electromotive Force Alternating Current (VRMS) Personal Computer Graphical User interface Instrumentation Amplifier Integrated Circuit Millions instruction per Second peak to peak Interrupt Service Routine Radio Frequency
iii
List of Tables
Table 1: Scoring Matrix for the 16-bit Microcontroller Table 2: Scoring Matrix for the Wireless Transceiver Table 3: Current Measurement Table 4: Comparison of Switching and Linear Regulators Table 5: Instrumentation Amplifier Comparison Table 6: Lead Vector Characteristics Table 7: Functional Description of ECG Live! Toolbar
iv
List of Figures
Figure 1: Typical ECG waveform Figure 2: The Cross-Section of the Heart Figure 3: Electrical Conduction Path of the Heart Figure 4: Electrophysiology of the Heart Figure 5: The Three Leads Figure 6: The UML Use Case Diagram Figure 7: System Block Diagram Figure 8: Hardware Module Description Figure 9: Frame Structure for the transmission of 1 character Figure 10: Three Operational Amplifier Differential Amplifier Figure 11: AD620 Instrumentation Amplifier Figure 12: Sallen key Low-pass Filter Figure 13: Gain and Offset Stage using 2 op-amps Figure 14: Right Leg Drive Figure 15: AD620 with DC Restoration Scheme Figure 16(a): Lead1 Signal Prior to Offset and Amplification stage Figure 16(b): Lead1 Signal prior to Offset and Amplification stage with D.C. Figure 17: DSPic Microcontroller Main Method Figure 18: ADCON3 Register with ADCS and SAMC bits Figure 19: ADC ISR Figure 20: UART Transmit Function Figure 21: UART Receive Function Figure 22(a): Unfiltered ECG Signal Figure 22(b): Notch Filter Magnitude Response Figure 22(c): Filtered ECG Signal Figure 22(d): Pole-Zero Diagram Figure 23: Matlab Code for 4th Order Low Pass IIR Filter Figure 24: Simulation Results of 4th order low-pass IIR Filter Figure 25: C code implementation of Digital Filters Figure 26(a): Filtered Lead I output with 12 bit resolution Figure 26(b) Filtered Lead II output with 8 bit resolution Figure 27: ECG Live! Packet structure Figure 28: Programming Methodology of Wireless Transceiver Figure 29: MSComm Communication Protocol Figure 30: Com Port Settings Tab
Figure 31: Parent Form menu file Figure 32: Figure 32: ECG Live! Toolbar Description Figure 33: Real Time Data Display using ECG Live! And GUI Figure 34: New patient Entry Form Figure 35(a): Patient table: stores patients personal details Figure 35(b) Data Table: Stores ECG data Figure 35(c): Trace table: Relates a Particular Patient ID to Trace Data Figure 36: Database Tables and Relationships Figure 37(a): The Mobile Unit Figure 37(b): The Back View of the Mobile Unit Figure 38(a): The Host Unit Figure 38(b): The Back View of the Host Unit
vi
1. Introduction
An ECG is used to measure the electrical activity of the heart treated as a vector quantity. It measures the rate and regularity of heartbeats, the position of the various chambers, the existence of any damage to the heart and the effects of drugs and devices used to regulate the heart. The potential created by the heart wall contraction spreads electrical currents from the heart throughout the body. The spreading electrical currents create different potentials at different points on the body. Leads are placed on the body in several pre-determined locations to provide information about heart conditions. The cardiac signal, typically 5 mV peak to peak, is an AC signal with a bandwidth of 0.05 Hz to 100 Hz (Section 4). The ECG signal is characterized by six peaks and valleys labeled with successive letters of the alphabet P, Q, R, S, T, and U (Figure 1).
The proposed design involves the implementation of a wearable three lead wearable ECG system. The primary objective is to keep the cost of the design as low as possible while still achieving industry standard performance. Two other constraints have been placed on the design: All signal conditioning and processing be done using a suitable processor. Wireless transmission be implemented using a suitable R.F transceiver.
Currently there are various wireless applications being employed in the health care industry. The most common are wireless pulse oxymetry, measuring the oxygen content in the blood. Another example is wireless temperature sensors in which the patient swallows a small transponder that will constantly transmit the bodys core temperature.
2. The Heart
2.1. The Activity of the Heart
The main purpose of the heart is to pump blood throughout the body. The heart is divided into four chambers; the right atrium, right ventricle, left atrium and left ventricle. The right side of the heart delivers deoxygenated (carbonated) blood from the body to the lungs, and the left side of the heart delivers oxygenated blood from the lungs to the body.
Deoxygenated blood enters the Right Atrium of the heart. The atria contract and push the blood into the Right Ventricle. The ventricles then contract and push the blood out of the heart, and thus to the lungs. The oxygenated blood from the lungs is returned to the Left Atrium. The Atria again contract and push the blood through into the Left Ventricle. The Ventricles again contract and push the blood to all parts of the body. An electrical impulse is necessary to cause the heart to contract. The Sinoatrial Node (SA Node) is responsible for producing these impulses. The impulse from the SA node stimulates the atrial muscles causing both atria to contract and blood to flow into the ventricles.
The signal then reaches the Atrioventricular Node (AV Node) where it is naturally delayed to allow the atria to contract and fill the ventricles with blood. The signal continues down to a thick bundle of nerve fibres known as the Bundle of His. The bundle branches out to the left and right and terminate in tiny fibres known as Purkinje Fibres. These distribute the impulse to the cells of the heart muscle causing ventricular stimulation.
Einthovens law also states that the value of any point of the triangle can be computed as long as values for the other two points are known. This point is crucial in the implementation of the design. It simplifies the overall analogue design and reduces the component count (and most importantly cost) as only two differential amplifiers are required. If any two leads (of the three lead ECG) are generated using the front end hardware the third lead may be generated entirely by software by simply subtracting (or adding) the two leads obtained from the analogue front end. The equations presented below verify the above statement. The Einthoven limb leads (standard leads) are defined in the following way: Lead I: VI = (1) = potential at the left arm Lead II: VII = Lead III: VIII = (2) (3) = potential at the right arm = potential at the left foot = Lead II
Manipulation of the above results yields: Lead I + Lead III = + = Similarly: Lead II - Lead I = Lead III
From the above result it can be seen that the ECG signal has frequency components below 1Hz. 5
mains, but rather, somewhere in between. Since the mains current is fluctuating (AC), the induced voltage of the subject is also fluctuating. The effect is however minimised by the fact that the electromagnetic field generated by the live wire is to a large degree cancelled out by the neutral cable flowing adjacent to the live cable but in the opposite direction.
6. Feasibility Study
A crucial aspect of the design process was determining the feasibility of a Low-Cost wireless ECG system. In a country were health care is constantly under the spotlight, it seemed obvious to validate if a niche market was present in South African health care system for a Low-Cost ECG device. The health care system in South Africa consists of a large public sector which provides medical care (facilities, personnel and medication) to the vast majority of the population. Public health care cost consumes annually, 62 billion rand (Roughly 10%) of the governments total budget. Public Health care however is currently desperately under resourced with people in the rural areas finding it very difficult to travel to hospitals and clinics which are largely based in the larger metropolis and there surrounding areas. In a recent attempt to make health care more accessible to the underprivileged, the department of health has decided to launch a fleet of mobile health clinics that are set up in large ambulance type vehicles. Massive revamps have also been ordered on existing clinics and rural hospitals that do not meet department standards. A low cost easily manoeuvrable ECG machine is one of the key requirements for these clinics to deliver an adequate and accurate service to persons using this service. The low cost ECG apparatus also finds potential use in the private health care sector. Pharmacies and General Practitioners (G.P) may also provide ECG tests to their customers and patients for early detection of possible heart conditions. The device may also be used by private nurses who provide medical care to patients in their homes. Although low cost is the primary objective for the project, low power consumption and ease of use by both patient and doctor is also a key requirement. Current ECG systems make patient monitoring cumbersome and difficult. The ECG leads are frequently dislodged from the patient by persons in the examining or operating room. This causes serious complications because in an operating scenario it appears to the monitoring station that the patient is going into cardiac arrest. Another issue inherent within the currently employed ECG system is the obstructive nature of wires and leads decreasing mobility of doctors and nurses. A solution to this would be to design an ECG that utilises wireless data transmission as much as possible to eliminate the need for wires.
7. Functional Specifications
The following are the functional specifications for the ECG: To provide a real time 3-lead ECG trace on a P.C. A simple intuitive GUI that may be used by a person with no medical background. Transmission of data from remote unit is initiated from the GUI. Easy setup and installation of entire system. Two separate units. A portable unit that is attached to the person being monitored. A second unit interfaces directly to the P.C and acquires data that is being transmitted wirelessly. The portable device is light weight, compact and unobtrusive. User plugs P.C unit into USB port for reception of data. Visual feedback is provided to the user/s on the portable device via an LED to inform user that the ECG portable unit has been switched on. An additional pair of LEDs is provided to indicate the successful reception and transmission of ECG data. A simple but concise manual will be provided on the operation of the device.
10
8. Non-Functional Specifications
As mentioned previously the design is broken down into two components. A mobile unit is attached to the person being monitored. A second unit is attached to the P.C. At the core of the mobile unit is a low cost Digital Signal Processor (DSP), the DSPic30F3012. The DSPic is responsible for processing the raw ECG data acquired from the analogue front end hardware, before aligning the data for transmission. The primary purpose of choosing such a high performance processor is to perform all the necessary filtration in the digital domain thus reducing the overall size, power consumption, efficiency and cost of the mobile device. The ECG leads interface directly to mobile units analogue circuitry. Peripheral components are added between the patient and circuitry to maximize impedance seen by the circuit and hence decrease overall current flow through to the patient. The analogue front end will use the typical approach employed by the majority of current ECG designs with an instrumentation amplifier (IA) and a right leg common-mode feedback op amp. The use of digital filters was a constraint placed on the design. The implementation utilizes Infinite Impulse Response (IIR) to perform the necessary ECG frequency band selection. The filtered ECG signal is transmitted via SPI (Serial Peripheral Interface) to a radio frequency (RF) Transceiver, (provides the wireless link from the portable unit to base station.). The P.C unit receives the data (Corresponding Transceiver). A microcontroller is required to decode the received R.F signal. It will then communicate with the P.C via USB plotting the resultant ECG traces on the P.C screen using a custom written Visual Basic 6.0 application (VB6). Communication is achieved between VB6 and the P.C unit by using the MSCOMM control.
11
9. System Requirements
The host PC with the following minimum requirements will be used as the data acquisition and display unit: Microsoft Windows 98 or higher. Intel Pentium II 300MHz processor or equivalent. 32MB RAM.
21MB available hard disk space. USB 1.1 Compliant An Available USB port
Thy system requirements are derived from the minimum requirements for USB 1.1 and Visual Basic. The final implementation with the MSComm plug-in is 20.3MB. However the memory requirements are largely dependant on the size of the database, which varies for different scenarios.
12
DSPic
UART
RF
RF
Controller
13
4 LEDs
1 AnalogueFrontEnd
1 PowerSupply
1 DSPICC
1 WirelessTransceiver
> Show device is powered up > Indicate transmission of data > Indicate reception of data >Flashing LED indicates heart rate detection
> Receive Raw ECG Signal from Leads >Generate Unfiltered ECG Data
> Battery Power > NonRechargeable > Regulated Power Supply (5V at 1A)
> Digitises Data > Digital Filtering > Serial Communication to Wireless Transceiver > Controls Tx and Rx LEDs
PC
8-bitC
1 WirelessTransceiver
The above diagram above illustrates the hardware structure of the entire system and briefly lists the role that each constituent plays.
14
Options from both Analogue Devices and Texas Instruments were investigated along with the DSPic option. Table 1 below highlights the 3 options that were investigated. The cost criterion includes the cost of a compiler and development board. This largely dictated the choice in processor as the project had to be within budgetary constraints. The DSPic rated highly on this criterion as the compiler was provided by Microchip for free. As performance is often measured in MIPS this criterion was also considered. Here again DSPic surpassed its competitors. The MIPS rating was twice that of its nearest competitor. High Performance Microcontroller DSPic MSP430 ADuC842 Rating Score Rating Score Rating Score 5 4 5 20 20 10 50 2 2 1 8 10 2 20 1 2 3 4 10 6 20
Criteria
Weighting
All the initial development was done on the 40Pin DSPic30F4013. On completion it was evident that a 40 pin microcontroller was not necessary as most of its peripherals and I/O pins were not in use. Using a smaller microcontroller would also lower the overall power consumption in the design. The 18 pin DSPic30F3012 was selected for the final implementation. The 30F3012 met all the requirements as well as having a typical input current of 5.8mA as compared to the 7.1mA with the 30F4013.
15
Full Duplex Operation Synchronous and Asynchronous Operation High Resolution BAUD Rate Generator Frame Error Detection Noise filtering including False Start Bit Detection Three interrupts: Receive Complete, Transmit Complete, and Transmit Data Register Empty
Frame Format A serial frame is defined to be one character of data bits, with synchronisation bits and an optional parity bit.
16
FRAME (IDLE) St 0 1 2 3 4 [5] [6] [7] [8] [P] Sp1 [Sp2] (St/IDLE)
No transmission on communication lines Start Bit. Always low Data Bits. Bits within brackets are optional Parity Bit (Optional) Stop Bit
Figure 9: Frame Structure for the transmission of 1 character [1]
Criteria Cost
Weighting 5 5
Initially the Nordic NRF905 wireless transceiver was selected for the design. However implementation of the transceiver proved to be a problem as they were very sensitive to voltage variations. Two transceivers were destroyed during the implementation phase. A more robust alternative was sought that met the necessary criteria. Investigation yielded the AC4486 transceiver; although slightly higher in cost the transceiver met all other requirements. An additional feature was internal surge protection which made the option seem a lot more attractive after the misfortune encountered with the NRF905. The Aerocomm AC4486 is a cost-effective, high performance transceiver. It employs an asynchronous TTL scheme communications. Communications include both system and 17
configuration data. The transceiver supplies data for transmission to other transceivers and may be used to implement a star topology network. Configuration data is stored in on-board EEPROM. All RF system data transmission/reception is performed by the transceiver. For one to one data transmission the transceiver may be programmed once at design time with the necessary configuration settings.
The current at the output of he 7905 regulator was measured to be 22mA (on the bread board. The major factor influencing the design of power supplies is regulator topology. 11.3.1.1. Regulator Topology The three popular topologies are: switching regulators Linear Regulators Switched Capacitor
18
Switched Capacitor topology is typically used in applications that require peak currents less than 150mA [17]. Placing these devices in parallel however, effectively doubles there output current. Single chip solutions are readily available. Most voltage inverter regulators utilise this topology. The table below provides a comparison between switching and linear regulators.
Type
Switching
Step Up, Step Down, Invert High High High High
Linear
Step Down Low Low Low Low
The primary benefit of the switching regulator topology is their ability to boost (step up) any input voltage. They are highly efficient reaching efficiencies of up to 90% [17]. This reduces the overall cell (battery) count required in portable applications. This is a key motivating factor in the design of any battery powered device as the physical dimensions of the battery is critical to the overall size of the device. The foremost deciding factor was based on the requirement of a low noise power supply as the ECG signal is susceptible to various kinds of interference. Since a clean ECG trace is the primary requirement of the design, linear regulators were selected. 11.3.1.2. Power Supply Implementation A 9V Duracell battery is used in the implementation of the power supply (Appendix D) 11.3.1.2.1. Voltage Inversion Using Switched Capacitor I.C Two charge pump regulators were selected to generate the required negative voltage. The ICL7660 was used for this purpose. The devices were placed in parallel halving there overall output resistance hence doubling their output current capability. The output current from the implementation was measured to be 38 mA at voltage of -8.59V. The implementation followed the outline in the datasheet. The schematic is presented in Appendix D. 11.3.1.2.2. 5V Regulated power supply 19
The 7805, 7905 regulators were used in the implementation. They are both able to supply 1A of current. The power supply is simulated using electronics work bench (Appendix D). Both regulators are loaded until breakdown in the simulation. The 7805 is successfully able to deliver 910mA before breakdown. The 7905 however only supplied 632mA. However this is more than sufficient for the purpose of the design.
20
through and amplifying the differential voltage. Its differential gain Ad, and common mode gain Ac, are given by the following equations: (4)
(5)
The configuration utilizes three op-amps. The circuits optimal performance in terms of stability, differential gain and high common mode rejection ratio (CMRR) are difficult to compete with when using other discrete component implementations. Accuracy in matching of the resistors is an important consideration in the design of a discrete component differential amplifier. The slightest error in the matching of resistances R3,top R3,bottom, and R4,top, R4,bottom in the discrete implementation (figure 9) results in unwanted common-mode amplification. Assuming we use 1% resistors:
(6)
Or (7) with
(8) Substituting the above results into equation 5 yields the unwanted common mode gain which is given by:
22
(9)
IA Type
CMR(Gain=100) Accuracy Noise
Power Requirements
Input Current
Although other options were investigated the AD620 was selected as it was the only instrumentation amplifier that was readily available. It also satisfied the budgetary constraints of the design. The AD620 requires only a single external gain-setting resistor; the gain equation is given by: Gain = (10)
23
Figure 11 illustrates the AD620 connection scheme utilized in the 22K implementation. This method was To RL To RG AD620 Driver utilized because two separate Patient 22K amplifiers needed to be interfaced to the right leg common-mode driver. Two 22k resistors are Figure 11: AD620 Instrumentation Amplifier [8] placed in parallel with the gain resistor. The right leg driver interface is at the centre of these two resistors. The two 22k resistor modify the gain equation. The gain of the AD620 is given by: Gain = 1 + (11)
The AD620 has a maximum gain of 1000 [2] ideally we would like to set the gain here to some maximum value thus eliminating the requirements for an additional gain stage prior to microcontroller stage. The gain selection of the AD620 is however critical to the design of the entire system. The gain must be set such that output saturation of the 5V power supply does not occur. As mentioned above the maximum input is 5 mV plus a variable normal-mode dc offset of up to 300 mV [8]. By setting the gain resistor to 6.2k it ensures that the maximum output swing is 3.07V i.e. Gain = 10. The gain was verified by grounding the negative input and passing waves of varying amplitude into the amplifier while observing both the input and output waves on an oscilloscope.
CY
RX RY The anti-aliasing filter cut-off frequency (fC) I/P TL084 is set to the highest ECG frequency CX component of interest (fmax) so that fC = fmax. As mentioned previously a maximum Figure 12: Sallen key Low-pass Filter frequency component of 250Hz is present in the representation of ECG signals. The filter was hence designed to have a cut-off frequency of 250Hz. The Sallen and Key active filter configuration was preferred to the Multiple Feedback due to its less component count. The Butterworth filter was selected due to its pass-band flatness. Since the ECG signal is so small in magnitude, any ripple in the pass-band would only further attenuate the signal making its recovery more difficult. A simple fourth order low-pass filter was designed for this purpose. Figure 12 shows a second order low-pass filter block. Two of these are cascaded to form the fourth order filter. The calculation of the component values along with the corresponding bode plot is present in the Appendices (A1).
Signal In 5V
10k
1k
To ADC
4.7k
TL084
1k
220k
25
runs of a 3.3V supply. This requires that the input to the DSPic be within the 0-3.3V range. The 10k and 4.7k resistors form a voltage divider. The output of the divider is given by:
The output of OA1 is simply a buffered version of the voltage divider. The operational amplifier is utilized as it has very high input impedance. This ensures that no resistive loading occurs on the input signal. Operational amplifier OA2 is configured in the non-inverting summer configuration. The circuit has a total gain of 48. The filtered signal is simply added to the output of OA1 which causes it to be centred at 1.59V.
To LP Filter 1M
AD620
Ref
100nF
0P07
26
Figure 15: AD620 with DC Restoration Scheme
skin and electrode. This condition results in a deviation of the D.C content of the amplified differential signal and manifests itself as a drift in the baseline of the ECG signal. This phenomenon is often referred to as baseline wander. The problem is overcome by utilizing an analog integrator scheme highlighted in Figure 15. The integrator scheme integrates the dc content of the 10 amplified Raw ECG signal and feeds it back to the reference pin of theAD620. The feedback action allows the AD620 to maintain a constant DC level at the output, regardless of the change in skin contact resistance.
Figure 16(a): Lead1 Signal Prior to Offset and Amplification stage Figure 16(b): Lead1 Signal prior to Offset and Amplification stage with D.C. Blocking Cap Removed
The output of the Low pass filter prior to the offset and gain stage was measured using an oscilloscope. Figure 16(a) illustrates the Lead1 ECG signal. The signal is approximately 20mV p-p and is centred at 0V. The Instrumentation amplifier gain was set to ten, which implies that the raw signal prior to amplification of the ECG is 2mVp-p. The 2mVp-p signal falls within the typical ECG signal range. This result was required in the Design of The GUI. To highlight the effect of the D.C offset component in the signal the D.C blocking capacitor was removed. Figure 16(b) illustrates the Lead1 ECG signal with the capacitor removed. The ECG signal is now centred at 77mV. This highlights the necessity of the blocking capacitor. FT232RL The Ft232RL I.C converts serial Data to the USB protocol. The driver create a virtual comport on the P.C that allow serial communication via USB. The host unit interfaces to the P.C via the FT232Rl. The royalty free drivers may be downloaded from the site FTDI site
27
Initialize UART
Initialize ADC
Loop
No Do_Filter Flag Set? Yes Call Filter ( )
No
Transceiver Ready( )
UART(ECG_Data)
28
A sampling frequency of 8 KHz correlates to a sample time of 125s (TSAMP = 125s). Where TCONV is the time required for the ADC to complete a conversion. TACQ is defined as the total acquisition time. The ADCS bits in the ADCON3 register define the ADC clock period which is denoted as TAD where: (13)
29
TCY in equation (13) represents the DSPic instruction cycle time. The DSPic is being driven using an external crystal of frequency 7.3728MHz. This corresponds to instruction cycle time: TCY = (14)
The only constraint in setting the sampling frequency is the minimum conversion time. The datasheet however recommends that the acquisition time be set as high as the application allows, thus ensuring accurate representation of the signal. As mentioned above the SAMC bits in the ADCON3 register (figure 18) defines the sample acquisition time. Setting The SAMC bits to a maximum of 31, yields a TACQ: TACQ = 31TAD (15) The ADC requires 14 ADC clock periods to complete a conversion. The total conversion period TCONV is given by: TCONV = 14 TAD (16) Substituting (15) and (16) into (13) yields: TSAMP = 45 TAD = 125 s (17) Or TAD = 2.78s (18) Substituting (18) into (13) and rearranging for ADCS yields an ADCS value of 40.
30
Start
No j<15
Set Do_Filter
U1TxReg = Data
RecByte =U1TxReg
End
Return RecByte
End
31
Substituting these values in equations B6-1 and B6-2 (Appendix B), we arrive at
Then, substituting the above values in equation B4, we arrive at the desired transfer function
whose gain and pole-zero plot are plotted in figure 20b and 20d respectively. Figure 20a represents an ECG signal with 50Hz interference superimposed onto it. The signal is generated using the ecgplusint( ) function. Finally figure 20c represents the effect of using the above transfer function on the ECG signal with 50Hz interference.
32
(a)
(b)
(c) )
(d)
L
Figure 22(a): Unfiltered ECG Signal Figure 22(b): Notch Filter Magnitude Response Figure 22(c): Filtered ECG Signal Figure 22(d): Pole-Zero Diagram
The derived transfer function is then converted to a recursive algorithm (difference equation).
Where n represents the current input or output. This equation is then implemented on the processor using C code.
33
The code snippet below uses the butter() function to generate the necessary coefficients for a second order Butterworth filter with a 100Hz cut-off frequency. The ecgsig() function is then employed to generate a an ECG signal with 200Hz interference (figure 24a). The generated ECG signal is then filtered using convolution and the resultant trace is plotted (figure 24b). Finally figure 24c tests the filter as it will be programmed on the DSPic30F4013.
Figure 23: Matlab Code for 4th Order Low Pass IIR Filter
The transfer function generated from the above code snippet needs to be converted to a recursive algorithm. The transfer function for the Low pass filter H(z) is given by:
34
(a)
(b)
(c) )
(d)
35
The peak to peak voltage of Lead II is greater than Lead I. This conforms to standard (Healthy) ECG signals. The frequency component is almost identical as they should be. However there is still an element of interference in the measured results as compared to the simulated results. This stems from the manner in which the simulated results are generated. The custom written ecgplusint( ) function only allows a single frequency of interference to be input, which is non-ideal in a real world situation.
36
37
A total of 5 packet bytes plus a start byte of 255 must be transmitted prior to new data becoming available from the Analogue to Digital converter. Furthermore a "resend on error" capability must be employed to ensure reliable communication. The design only employs a single resend capability. Due to the robust protocol already implemented in the transceiver firmware this low-level protocol is deemed sufficient. For single resend capability a total of 13 (12 packet bytes + 1 for Nack reception) bytes must be sent within prior to new data becoming available. The total time to receive 2 data bytes from the ADC is 2ms. The filter iteration however requires 209s to complete. This leaves 2ms - 209s = 1.79 ms for transmission of data. The resulting data rate is hence: 38
57900 bit/s
The interface Data Rate is hence set to a maximum of 115200 bits/s. The R.F data rate however is fixed at 64Kbits/s
39
Start
1. C1h command notifies transceiver that data is to be written. If the command is echoed back it has been received successfully by the transceiver. 2. EEPROM address that data is to be written to. (Command 0 register in this case)
Response C1h
Response 45h
Send 0b10010100
End
40
Yes
Send Ack
End 1. In the form Load Procedure the Receive Event is set to trigger on the reception of a single byte. If the Byte 255 is received the receive event is set to trigger on reception of 5 bytes. The data flag is set. This informs the GUI that data is about to be sent The receive event triggers after receiving 5 data bytes. These bytes make up the data packet (discussed above) A simple XOR checksum of the first 4 Data bytes are calculated Data is then Passed to Plotter Function (and Stored to a database) depending on user requirements. MSComm is reinitialized to trigger on 1 Byte. It waits for 255 Byte = 255 No 1 Byte = 240? Yes Re-Initialize MSComm (2) 4 Byte = 15 Yes Set Data Bit Yes End 5 Byte = Checksum Yes
th th st
Re-initialize
No MSComm (6)
2.
CalcChecksum (4)
3.
No
4. 5.
6.
41
42
Functions Connect Disconnect Clear Screen Shift Baseline Commands Adjust Time Scale Zoom Trace Duration
Descriptions The connect icon connects the PC to the Host unit via the serial port Close the connection between the Host Unit and P.C Erases all ECG data points plotted on the screen 1mV represents a single block on the screen Time scale is measured in terms of mm/sec. This was implemented to conform to general ECG standards Magnify Trace by selected amount Elapsed time since pressing the connect button
43
third lead. Due to the slight delay introduced by the digital filters the results are erroneous.
Figure 33: Real Time Data Display using ECG Live! And GUI
New Patient
Part of the specification of the design was to implement a database. Selection of the "New Patient" tab (figure 31) allows the user to add a new patient to the database. Figure 34 below illustrates the patient details form and each field that is stored in the relational database. On pressing the save button the live trace form is loaded and the ECG trace is displayed on pressing the connect button. The ECG data however in this case is stored together with its timestamp in the database and may be viewed at a later stage. Currently the New Patient Episode and Open Patient Episode forms are still under development
44
45
46
The relationship between the each of tables is illustrated in Error! Reference source not found.36. The 1 and (commonly referred to as one to many) symbols indicate that for each Patient ID in the patient table there exist an infinite number (possibly) of entries for that Patient ID in the data table.
The primary benefit of implementing such a database is the simplicity at which it may be adapted to meet the various user needs. For example a Physician/Doctor table can be created and a relation between doctors and patients formed. The database is accessed by the user through the GUI as discussed above.
47
48
17. Conclusion
The design was successfully dissected into various modules. Each module with the exception of the database system has been implemented. The integration of the individual modules was achieved successfully. All the results were categorically measured. A digital to analogue converter (DAC) was implemented into the design. The DAC was as a necessity for the proper measurement and categorization of measured results. It allowed the filtered ECG data to be viewed on an oscilloscope and necessary measurements to be taken. The wireless transceiver proved to be an excellent choice. Initial teething problems were experienced during the implementation as the datasheet was not very well documented. Although slightly more challenging to implement than the Nordic options, the RF link is considerably more reliable. The device is also considerably more robust and may be repaired easily (personal experience). Most importantly however the data throughput figure outlined in the data sheet is realistic and achievable unlike many other RF products. A range of 30m was successfully achieved indoors. All the GUI functionality discussed in the report is operational. The functionality was based on low cost ECG software used in hospitals in South Africa. The ECG trace however is very temperamental with respect to clarity. At times the trace is up to industry standard ECG machines. However, on occasion the signal is distorted slightly. The storage of patient details and ECG data to the database has been implemented successfully, however loading the stored data proved to be a problem. Further investigation is under way.
49
18. References
1. INA 114 Datasheet, www.ti.com, 2nd September 2007 2. AD620 Datasheet, www.analog.com, 9th September 2007 3. AMP01 Datasheet, www.analog.com, 14th September 2007 4. Micro Electronics circuits, 4th Edition, Sedra and Smith 5.www.publicworks.gov.za/consultants_docs/Uninterrupted_Power_Supply_specification .doc, 19th August 2007 6. http://www.webmd.com/brain/electromyogram-emg-and-nerve-conduction-studies, 7. Dr Cassim Hansa, Cardiologist, Gatesville Medical Centre, [email protected]. 8. Analogue Dialogue, Volume 37, November 2003 9. Minimum Bandwidth Requirements for Recording of Pediatric Electrocardiograms. Peter R. Rijnbeek, MSc; Jan A. Kors, PhD; Maarten Witsenburg, MD PhD. 10.Webster John G., Medical Instrumentation. Application and Design. 3rd edition, Wiley, 1998. 11. Ride Magazine www.ride.co.za 12. Digital Signal Processing, Sanjit K Mitra, 2nd Edition, McGraw-Hill, 2002 13. DSPIC30F4013 Datasheet, www.microchip.com, 14. http://health.howstuffworks.com/heart3.htm, 15th October 2007 15. http://butler.cc.tut.fi/~malmivuo/bem/bembook/06/06.htm, 16th October 2007 16. http://www.biopac.com/bslprolessons/h01/bslproh01.htm , 14th October 2007 17. Electonics 3 Class notes 2007, Lecturer Roger Peplow 18. http://www.analog.com/library/analogDialogue/archives/37-11/ecg.html, 15th October 2007 19. ICL7660 Datasheet, www.maxim.com, 11 November 2007
50
Appendix A
4th Order Low Pass Filter Design
i 1 2 Filter Section 1
ai 1.8478 0.7654
bi 1 1
Filter Section 2
ii
Appendix B
A second-order analogue filter has a transfer function given by . Its magnitude response is then , which approaches unity values, i.e., a gain of 0dB, at zero value at the notch frequency . If (17) and . The magnitude has a denote the frequencies . (16)[12]
at which the gain is down by -3dB, the 3-dB notch bandwidth defined by
(21a) (21b) Equations (21a) and (21b) are the desired design formulas to determine the constants for a given notch frequency and a 3-dB notch bandwidth . iii
Appendix C
Aerocomm AC4486 wireless transceiver Configuration registers
iv
Appendix D