Monday, December 26, 2011

Philips Healthcare's Sierra ECG format XLI Compression Scheme

One of the services I work for has recently acquired a Philips HeartStart MRx cardiac monitor. It came complete with Bluetooth transmission of 12-Lead and event data. At roughly the same time our service installed a computer, an MDT, into the cab of our unit to interface with our county's CAD software.

Naturally I linked our monitor and our MDT via Bluetooth, and transmitted a 12-Lead from a rhythm generator. When the file landed on the MDT, I looked for an application to view the 12-Leads and rhythm strips, however, none appeared to be able to use the file as-is.

For the non-technical, the ECGs are shipped compressed--somewhat like a ZIP file--which contains all of your monitored vital signs, printed rhythm strips, and your 12-Leads. The format of the 12-Leads is an Open Standard; Philips Healthcare provides most of the details needed to use the files. The 12-Lead data is also compressed to save space. Unfortunately, there is no documentation which tells you how to decompress the 12-Lead data.

The technically-faint-of-heart should skip these next bits.

For the technical, the ECGs are contained in a Gzip'd TAR archive. The 12-Leads are stored inside in an XML format known as the Sierra ECG format (currently at version 1.03 or 1.04, as far as I can tell). Inside this XML format is Base64 encoded, XLI compressed data comprising the acquired leads during a 12-Lead (up to 16 leads appear to be able to be stored).

I searched for a description of the XLI compression format, however, I was only able to find a reference implementation for Microsoft Windows which simply decoded the files. No code or description was provided, and the implementation itself is not portable. (ed: it appears this may be a reference to the HP PageWriter XLi which Philips acquired)

At this point I decided my only option was to reverse engineer the XLI Compression format, and began with simple guesses. I tried decompressing the data using Deflate, Zip, and RLE without any progress. I was able to determine that the first 8 bytes of the compressed data included a compressed length, some uncompressed data, and that each of the 12 to 16 leads were stored in a chunk with one of these headers:
offset   2        4        6        8  ...
| Size            |  Unk.  | Delta? | Compressed data...       |
+--------+--------+--------+--------+                          |
| ...                                             [Size bytes] |
| Next lead chunk ...                                          |
Once the simple guesses were ruled out, I began exploring the behavior of the reference implementation provided for the Sierra ECG format. Using OllyDbg I noticed certain code tells which made me believe the decompression algorithm read 10-bits at a time:
SHR   EAX, 16h   ; reduce EAX to the 10-bit code word
SHL   ECX, Ah    ; prepare to read 10 more bits from the input
The compressed data also did not appear to contain a compression dictionary referenced by the code. At this point I considered I was looking at a form of Lempel-Ziv-Welch, or LZW, compression. LZW is a popular, lossless compression scheme which creates its compression dictionary on the fly. It is used by the GIF and TIFF image formats, and was the subject of controversy when it was first introduced into the GIF format due to patent licensing requirements.

In my quest to quickly reach a conclusion I found an excellent LZW implementation from Mark Nelson in C and it successfully decompressed the data. In fact, the structure of the C code was so familiar, I realized the reference implementation from Philips used the exact same code!

If you've reached this step while following along at home, you'll notice the decompressed data seems front-loaded with 0's. This is a case of intelligently streaming the data to the compression algorithm to take advantage of data duplication.

The uncompressed data represents 16-bit delta codes, of which the majority include 0x00 or 0xFF in their most significant byte (MSB). This is because they are either small and positive or small and negative, and as ECG data is rhythmic the delta codes are likely to retain the same sign for numerous samples.

To take advantage of this fact during compression, the delta codes are first deinterleaved into two halves. The first half includes each MSB and the second half includes each LSB. The pseudo-code for interleaving the decompressed data looks like the following:
# input contains the decompressed data
# output will contain the interleaved 16-bit delta codes
fun unpack( input[], output[], nSamples )
    for i <- 1..nSamples
        output[i] <- (input[i] << 8) | input[nSamples + i]
At this point the delta compression scheme will need to be decoded to produce the actual signal data for each of the leads. The delta compression scheme is a simple recurrence relation (a second order difference relation) using the prior two delta codes:
# output contains the 16-bit delta codes
# first is the 16-bit delta code from the chunk header
fun deltaDecompression( output[], nSamples, first )
    x <- output[1]
    y <- output[2]
    prev <- first
    for i <- 3..nSamples
        z <- (2 * y) - x - prev
        prev <- output[i] - 64   # is -64 to 64 the range?
        output[i] <- z
        x <- y
        y <- z
Now that you have the actual, per signal data all you need to do is recreate leads III, aVR, aVL, and aVF. This is done using the data from leads I and II as on most ECG machines. I've omitted the actual formulas for brevity.

Using my reference implementation of the decompression algorithm I was able to feed the original acquired 12-Lead to the Philips ECG to SVG converter, with the following results:

If you'd like to start playing with my code I welcome you to join my Github Project: sierra-ecg-tools. I am also working on a C implementation, and likely an Android implementation. Stay tuned, and apologies for the technical post.

The author has no financial ties to Philips Healthcare and received no compensation for this work.

Tuesday, December 6, 2011

EKG Myth - Ventricular tachycardia must have concordance

This is part of a series of posts detailing common electrocardiogram myths.

Myth: Ventricular Tachycardia must have precordial concordance

When differentiating a regular, wide-complex tachycardia some will look for precordial concordance to rule-in, or more importantly to rule-out ventricular tachycardia.

The absence of precordial concordance is not a reliable method of ruling out ventricular tachycardia:
Although the specificity of concordance for VT is high (>90%), the sensitivity is low (~20%)1.
It is generally thought that positive concordance indicates a posteriobasal left ventricular origin and negative concordance indicates an anterioapical left ventricular origin. However, in the case of positive concordance, SVT with a left-posterior accessory pathway is a known cause.

Until recently, negative concordance has been thought to be "virtually diagnostic" of ventricular tachycardia2. Multiple case reports have shown that certain configurations of accessory pathways can also cause negative concordance3,4,5.

The key takeaway is while this criteria is a useful tool to rule-in ventricular tachycardia (i.e. high specificity), it is not a useful tool to rule-out ventricular tachycardia (i.e. low sensitivity).

Ventricular tachycardia without precordial concordance6.
Ventricular tachycardia without precordial concordance. (c) 2011 EMS 12-Lead Blog.
WPW and Atrial flutter with positive concordance7.
While positive or negative concordance may strongly suggest ventricular tachycardia, providers should not rule-out ventricular tachycardia in its absence.

  1. Pellegrini CN, Scheinman MM. Clinical management of ventricular tachycardia. Curr Probl Cardiol. 2010; 35(9):453-504. [PubMed]
  2. Goldberger ZD, Rho RW, Page RL. Approach to the Diagnosis and Initial Management of the Stable Adult Patient With a Wide Complex Tachycardia. Am J Cardiol. 2008; 101:1456-1466. [Full Text]
  3. Pappas LK, et al. Wide QRS complex supraventricular tachycardia with negative precordial concordance. Am Heart Hosp J. 2009; 7(1):67-8. [PubMed]
  4. Kappos KG, et al. Wide QRS Complex tachycardia with a negative concordance pattern in the precordial leads: Are the ECG criteria always reliable? Pacing Clin Electrophys. 2006; 29:63-6. [PubMed]
  5. Volders PGA, et al. Wide QRS complex tachycardia with negative precordial concordance: Always a ventricular origin? J Cardio Electro. 2003; 14:109-111. [PubMed]
  6. Garmel GM. Wide Complex Tachycardias: Understanding this Complex Condition Part 1 - Epidemiology and Electrophysiology. W J Emerg Med. 2008; 9(1):28-39. [Full Text]
  7. Ibid. 1, Figure 3.

Thursday, November 17, 2011

EKG Myth - "It's Too Fast for Ventricular Tachycardia"

This is part of a series of posts detailing common electrocardiogram myths.

Myth: Rate can help you rule out Ventricular Tachycardia

When differentiating a regular, wide-complex tachycardia some will look at the rate to rule out ventricular tachycardia. Studies have not found rate to be a predictive finding1.
...regarding ventricular rate, significant overlap unfortunately exists between VT and SVT such that rate is not a helpful criterion to differentiate origins2.
Ventricular tachycardia technically can range in rates from 100 bpm through 300 bpm. However, a practical definition of VT would place the lower bound around 120 bpm and the upper bound around 260 bpm3.

Common terminology includes rates slower than 120 as "Slow Ventricular Tachycardia", which most often is not true VT4. Rates upwards of 260 to 300 bpm are commonly termed "Ventricular Flutter"5.

Ventricular tachycardia at 130 bpm. (c) 2001 - 2011 Beth Israel Deaconess Medical Center.

Ventricular tachycardia at 206 bpm. (c) 2011 EMS 12-Lead Blog.

Ventricular tachycardia at 280 bpm. (c) 1994-2011 WebMD.

As a rule: a regular, wide-complex tachycardia should be treated as ventricular tachycardia in the field, until proven otherwise.

  1. Griffith MJ, et al. Multivariate analysis to simplify the differential diagnosis of broad complex tachycardia. Br Heart J (1991); 66:166-74. [PubMed]
  2. Hudson KB, et al. Electrocardiographic Manifestations: Ventricular Tachycardia. J Emerg Med (2003); 25:303-314. [PubMed]
  3. Surawicz B, Knilans TK. Chou's Electrocardiography in Clinical Practice: Adult and Pediatric, 6th ed. Philadelphia, PA. Saunders, 2008. 
  4. Mattu A. ECG PEARLS: Beware the Slow Mimics of Ventricular Tachycardia. Emergency Physicians Monthly, 24 August 2010. Retrieved Online 8 November 2011. [Free Full Text]
  5. Gurevitz O, et al. Long-term prognosis of inducible ventricular flutter: not an innocent finding. Am Heart J (2004); 147(4):649-54. [PubMed]

Wednesday, June 22, 2011

Zebra Spotting

I'm sure we all received the following good advice at some point in our EMS education or careers:
"When you hear hoofbeats, think horses not zebras."
I propose we add the corollary:
"...but if you don't stay to watch, you won't know what you missed."
Remember, always err on the side of the patient.

Monday, May 23, 2011

An attempt at Video Education: Axis Determination

I'm a huge fan of the Khan Academy and regularly watch his videos when I have a question about something in mathematics. Usually it only takes five or so minutes into the video for me to recall how to accomplish the task, and I can move along. I've always wanted to see if I could do the same thing for ECG interpretation.
So here is my inaugural attempt; rapid axis determination using leads I and aVF (assuming you're ok with a ±5° difference):

Wednesday, April 6, 2011

Conclusion to 54 year old female CC: BLS intercept

As many readers noted, there is a lot of baseline wander. This is not the most helpful of 12-Leads. On scene the crew attempted multiple 12-Leads, however, the patient would not sit still and that was the best one. 
I think a close look at the Initial 12-Lead has enough information to make a field diagnosis.

Tuesday, April 5, 2011

New Case Study at EMS 12-Lead Blog

My first case study as an associate editor is up at the EMS 12-Lead Blog, so check it out: 54 year old female cc: BLS Intercept:
"It is just after 3am when you are called to intercept a BLS unit on scene with a 54 year old female with a low heart rate.

Upon your arrival, you find two EMT-Basics attending to a small woman lying in bed, who appears acutely ill..."
Also, I've done a brief review of atrioventricular blocks to help with identification of the rhythm in this case study!


Thursday, March 10, 2011

Unrecognized Limb Lead Misplacement?

Dr. Smith's ECG Blog has a new case up, "Reperfusion through collaterals associated with nitroglycerin, lateral MI with reciprocal T-wave inversion in lead III," with a pretty stark change in the initial 12-Leads. However, I have a hunch the stark change was really a change in the limb lead positions!

ECG 1 and ECG 2: Limb Leads Only
Look at leads I and II, notice how they "swap" positions between the two 12-Leads. Now look at aVL and aVF, notice how the "swap" positions too. Now take a look at lead III. It goes from inverted P's and T's with a Qr complex, to upright P's and T's with a Rs complex.

I propose that this change is due to a simple reversal of two leads. If we take a look at our friend Einthoven's Triangle (we covered this in a previous post on the S5 Lead) we can see that this makes sense!

LA/LL Swap: Einthoven's Triangle is "Flipped"
We can see that Lead I is actually looking at Lead II and Lead II is actually looking at Lead I; confirmed with ECG's 1 and 2. Lead III becomes an inverted Lead III; confirmed again in the original ECG's. This looks like a case of an unrecognized left arm and left leg lead reversal.

What I find most interesting is if you compare every ECG except the first, it appears to be a case with subtle posteriolateral changes that may have been missed had there not been the lead reversal!

Monday, February 28, 2011

Highlighting Atrial Activity on an ECG: The S5 Lead

Kelly Grayson, of A Day in the Life of an Ambulance Driver fame, posted an article on over a year ago entitled The Leads Less Traveled. In this he touched on modified chest leads (MCL1 through MCL6), right precordial leads (V4R), and the S5 Lead.

Update: after posting this I have since learned it is also known as the Lewis Lead, after Sir Thomas Lewis1, and have included a link to an article detailing how it was derived.

I had never heard of the S5 Lead before and promptly forgot about it until yesterday, when I finished acquiring 12-Leads for my limb lead reversal project. I went ahead and captured a rhythm strip from myself using the S5 lead placement.
S5 Leads: monitoring Leads I and II.
Before we cover the S5 Leads, let's recap normal lead placement and our friend, Einthoven's Triangle. This produces convenient ECGs with positive waveforms along the usual mean vector of the heart. Lead I points to 0°, Lead II points to 60°, and Lead III points to 120°.
Our friend, Einthoven's Triangle.
Additionally, the electrodes themselves are placed out on the limbs which generally results in waveforms proportional to the myocardium involved. Atrial activity is shown as well, but considering the proportion of myocardium involved in atrial depolarization, this configuration is not always useful in finding P-waves.
Normal Placement: Leads I and II from the same patient.
Now let's introduce the S5 Lead. You can produce this using many variations of the electrodes, however, for simplicity's sake we will stick with Kelly's description:
  1. Place the Right Arm electrode on the patient's manubrium.
  2. Place the Left Arm electrode on the 5th intercostal space, right sternal border.
  3. Place the Left Leg electrode on the right lower costal margin.
  4. Monitor Lead I.
Maximal atrial activity monitoring Lead I, S5 Lead configuration.
Notice the change in the direction of each lead. Lead I now points to the usual mean vector of atrial depolarization. Lead II and lead III are nearly perpendicular to the usual mean vector of ventricular depolarization. What does this mean for the electrocardiographer? If you remember that a vector which travels towards a lead is positive and perpendicular to a lead is isoelectric the answer is easy: atrial activity is highlighted, ventricular activity is diminished. 
S5: Lead I
S5: Lead II
The new direction Lead I points in is not quite perpendicular to the mean vector and it is also closer to the ventricular depolarization, hence we still have clear ventricular activity. However, the direction and location of Lead I is right in front of the atrial depolarization wavefront, giving clear P-waves. Lead II shows a large P-wave and small, nearly isoelectric ventricular activity.

If I can remember, I will try and acquire S5 Leads in the field. Has anyone else used the S5 Lead? Are there any other interesting lead configurations we should use?
  1. Bakker, ALM, et al. The Lewis Lead: Making Recognition of P Waves Easy During Wide QRS Complex Tachycardia. Circ (2009); 119:e592-e593. [Free Full Text]

Monday, February 14, 2011

Limb Lead Reversal: Preliminary Findings

Back in January, Tom over at the EMS 12-Lead blog had an interesting case entitled "Bait and Switch" in which the diagnosis of a STEMI was potentially masked due to incorrect limb lead placement. Interestingly, the limb lead placement was not one of classic LA/RA reversal, but rather a "rotation" of the limb leads. In this instance, the cardiac monitor did not detect the incorrect limb lead positioning. Over the last few weeks I have set out to collect 12-Lead ECGs acquired from each of the 24 possible limb lead positions and to catalog the characteristics of each.

All of the ECGs I have acquired are on LifePak 12 monitors using the GE Marquette 12SL algorithm. Currently, only classic limb lead reversal has produced the, "*** Suspect arm lead reversal, interpretation assumes no reversal," message. However, I still have 12 combinations of lead placements to complete.

Here are 3 ECG's acquired from a healthy male subject without any known cardiac abnormality or history (i.e. me).

Normal ECG **Unconfirmed**; Normal Sinus Rhythm
Abnormal ECG **Unconfirmed**; *** Suspect arm lead reversal, interpretation assumes no reversal; Normal sinus rhythm; Right axis deviation; Nonspecific ST abnormality.
Abnormal ECG **Unconfirmed**; Unusual P-axis, possible ectopic atrial rhythm; Left axis deviation; ST & T wave abnormality, consider inferior ischemia