ECG Simulator

Electricity to ECG

How a heartbeat becomes twelve traces

Before anything else: what is it we are actually measuring?

Voltage is always a difference

There is no such thing as voltage at one point. A meter always reports one point minus another. That is why every ECG lead needs two ends — and why the answer can come out negative.

Move point B
Why the sign matters on an ECG. Each lead has a positive end and a negative end. When the heart's electricity travels towards the positive end, the number comes out positive and the trace goes up. When it travels away, the number is negative and the trace goes down.

A Q wave and an R wave are not different kinds of event — they are the same kind of event, moving in opposite directions relative to that lead. Swap the two electrodes and every up becomes a down.

How big is the heart's signal?

Log scale — every gridline is ten times the one below.

One cell swings about 110 mV. By the time that reaches the skin it is only about 1 mV — a hundred times smaller. So the machine has to amplify about 1000×, while throwing away mains hum that can be bigger than the signal.

That millivolt comes from charged atoms crossing a membrane.

The ventricular action potential

Tap a phase. Current in the body is carried by ions, not electrons.

Membrane voltage now
What is moving

Every cell makes a tiny arrow. Here is how millions of them become one trace.

1 · What a vector is

Some things are just a number — temperature, weight. Others need a direction as well — wind, a push, and the heart's electricity. Anything with both a size and a direction is a vector, and we draw it as an arrow.

Direction
Size
The arrow points the way positive charge is heading. Its length is how much charge is moving. That is the whole idea — nothing more.

2 · Two arrows make one

Two patches of muscle firing together make two arrows. The body cannot report them separately. It reports only their sum, found by laying them tip to tail.

● Arrow A direction
● Arrow B direction

3 · Millions of cells, one arrow

Each patch of muscle below is firing its own little arrow. Drag the spread to change how well they line up, and watch what survives in the total.

How scattered the cells are
If they all added up
What actually survives

4 · What one lead can see

A lead is a line of sight. It cannot see the whole arrow — only the part lying along its own direction. That part is the arrow's shadow on the lead.

Turn the heart's arrow

5 · Shadows become the trace

The arrow changes every millisecond. Take its shadow on one lead at each instant, plot that as a height, and the trace draws itself.

Time

The electrode translates ions into electrons

Ions move charge in the body. Electrons move charge in a wire. The electrode is the point where one becomes the other.

Skin preparation
Half-cell offset
Compared with the R wave
What the amplifier actually receives
Why a sticky pad makes a voltage at all

This is the same chemistry as a torch battery, and for the same reason.

A battery works because two different materials, sitting in a liquid, swap charge at different rates. An ECG electrode is exactly that: a silver/silver-chloride disc (one material) in salty gel (the liquid) against skin (the other side).

At the silver surface, chloride ions from the gel stick to the metal and release electrons into it: Ag + Cl⁻ → AgCl + e⁻. Electrons pile up in the metal, chloride is used up in the gel, and that separation of charge is a voltage. It settles at a steady value and stays there.

So the pad is a weak battery you did not ask for, wired in series with the patient. The machine receives heartbeat + battery added together, and cannot tell them apart from one wire alone.
Step 1 — what the wire carries

Drag the slider. The red line is heartbeat + battery. Watch it lift away from zero while its shape never changes.

Size of the battery (offset)
Step 2 — what the machine does about it

The amplifier subtracts a constant to bring the line back to zero, then magnifies what is left. Watch the same signal go through both steps.

Types of electrode

The sensor you stick on decides how clean the trace can ever be. Pick one and watch what it does to the signal.

Half-cell offset
Skin contact impedance
Movement artifact
Recovery after a shock
Trace you would get from this electrode
Contact impedance, side by side
Impedance is what turns mains hum into a visible problem. The amplifier only cancels interference if both electrodes see the same thing — and a high-impedance electrode next to a low-impedance one breaks that match. Two good electrodes beat one good and one dry every time.

Impedance — how hard it is for the signal to get out

Impedance is the resistance the signal meets between heart and amplifier. Almost all of it lives in the dead outer layer of skin. Change the conditions and watch it move.

Skin cleaned and lightly abraded
Removes the dead surface layer, where most impedance sits
Hair at the site
Holds the electrode off the skin
Gel dried out
Old or long-open electrode
Patient sweating
Lifts adhesive but wets the skin
Electrode contact area
This electrode
Machine would report
Why matching matters more than the number

The amplifier cancels interference only if both electrodes see it identically. Give one a different impedance and the cancellation breaks.

Impedance of the partner electrode

Ten electrodes on the skin. Twelve leads on the paper. They are not the same thing.

Electrode vs lead

Placement

Tap any electrode. Ribs, sternal angle and reference lines drawn to scale.

Applying them, in order
1 Check each site — bone, scar and heavy hair all give a poor signal.
2 Clean the skin. Wipe with alcohol and let it dry, or abrade lightly.
3 Dry the skin, then press the electrode down from the centre outward.
4 Attach the leadwires last, and let them hang loose so they do not tug.

How each lead is built

ILA − RAbipolar · 0°
IILL − RAbipolar · +60°
IIILL − LAbipolar · +120°
aVR−(I + II)/2augmented · −150°
aVLI − II/2augmented · −30°
aVFII − I/2augmented · +90°
Only two of the six limb leads carry new information. The other four are worked out from those two. Einthoven's law (II = I + III) holds exactly here.

Everything here happens to the real voltage, before a single number exists.

Overview — the whole journey

The complete path from one cell to the printed trace. Tap any point to see what the signal looks like there. The rest of this module walks the same path in detail.

Amplitude here
Domain
1What arrives

About 1 mV of heartbeat, buried under a far larger offset and room noise.

What arrives at the wire

The starting point for everything in this module: about 1 mV of heartbeat, sitting on a much larger steady offset, with room noise on top. Every stage that follows is an attempt to keep the first part and discard the rest.

The signal you want
≈ 1 mV
Electrode offset on top
up to 300 mV
Mains hum in the room
often > 1 mV
So the wanted part is
under 1% of it
This is why an ECG machine is mostly a noise-rejection device. Amplifying is the easy part; amplifying only the heartbeat is the whole engineering problem. The offset and impedance behind these numbers are covered in the Electrodes module.
2Amplify it

Two wires in, one difference out. Noise shared by both cancels; the heartbeat survives and is magnified about a thousandfold.

Why every lead needs two wires

Mains hum reaches both electrodes equally. Since a lead is a subtraction, that shared noise cancels itself out. This is the single most important trick in the whole machine.

Mains hum picked up by the body
Electrode mismatch (bad skin prep)
RA wire — signal + hum
LA wire — signal + the same hum
Lead I = LA − RA — hum cancels

From here on the signal becomes numbers, and stops being a voltage.

3Anti-alias — the last analog step

A fixed hardware filter sitting just before the converter. It removes anything too fast to be sampled, because that particular damage cannot be undone afterwards.

Anti-alias — the one filter you cannot switch off

Some things attached to a patient are far faster than anything the heart does: electrosurgery, radio pickup, switching noise from nearby equipment. This filter blocks them before the converter. Here is why it has to.

Two different waves, one set of readings

The machine samples 500 times a second. The gold dots are the only moments it looks.

Frequency arriving
What it does to a real ECG

A 600 Hz source reaching the converter, with the filter on and off.

Anti-alias filter
Real machines have no switch. Here you can turn it off to see why.
ANTI-ALIAS (here)
Blocks what is too fast to sample
Hardware, before the converter
Always on
Cannot be undone
NOTCH (stage 6)
Removes mains hum at 50/60 Hz
Software, after the converter
You switch it on
Can be undone
4Sample — look at fixed moments

How often the machine glances at the voltage. Glance too rarely and the peak falls between glances.

Sampling

Zoomed onto the QRS, because that is the fastest thing on the trace and the first to be lost. Grey is the real signal, gold marks each moment the ADC looked, navy is all it kept.

Sampling rate
Samples across one QRS
Gap between samples
True R height
Worst case captured
5Round — each look becomes a number

Every reading must land on one of a fixed set of steps. Anything smaller than one step disappears.

What an ADC actually does

ADC = analog-to-digital converter. A voltage is a smooth thing; a computer can only store numbers. The ADC turns one into the other, and it does exactly two jobs.

Job 1 — sampling
Look at the voltage only at fixed moments
Job 2 — quantisation
Round each reading to the nearest step
Think of a ruler. An ADC can only measure between two fixed limits — here −5 mV to +5 mV, a range of 10 mV. And it only has a fixed number of marks on it. With n bits it has 2ⁿ marks.

Step size is simply the gap between two marks: range ÷ number of marks. Nothing can be reported between two marks, so every reading must jump to the nearest one.

Rounding error is how far the reading had to jump to get there. It can never be more than half a step.
See the marks. How many does an R wave get?
Steps across one R wave
Steps across 0.1 mV of ST
Watch a real QRS and ST land on those marks

Grey is the true signal. Navy is what the ADC stores. There is a genuine 0.1 mV ST elevation in this beat. Change the bit depth here and watch the navy trace break into steps.

How much was thrown away by rounding

Every sample had to jump to the nearest mark. This red line is the size of each jump: what the machine stored, minus what was really there. Magnified so it is visible at all.

True ST elevation
0.100 mV
ST elevation as stored

Now feed it one voltage and watch it land on a mark.

Voltage arriving at the ADC
Stored as code
Rounding error
what actually leaves the ADC
The number is all the machine keeps. Everything after this — filters, measurements, the printed trace — works from these codes, never from the original voltage.

Quantisation

The ADC outputs whole steps only. Fewer bits, coarser steps.

ADC resolution
Step size (1 LSB)
Levels
6Filter — now it is only arithmetic

These run on the stored numbers, so each is optional and can be undone. That is the opposite of stage 3.

Filters you can switch — all digital

These run on the stored numbers, after the ADC, and every one of them is optional. That makes them the opposite of the anti-alias filter in the overview above, which is fixed in hardware and runs before the numbers exist.

High-pass 0.5 Hz (monitor mode)
Off = diagnostic 0.05 Hz. Kills drift but distorts ST.
Low-pass 40 Hz (muscle filter)
Off = 150 Hz diagnostic. Smooths EMG but blunts QRS.
Notch 50 Hz
Removes mains interference specifically.
The trace, right here — flip a switch above and watch it

Grey is the signal before filtering. Navy is what you are left with. The square pulse on the left is the 1 mV calibration mark, and it is the quickest way to see what a filter has done.

Bandwidth now
Suitable for

Inject artifact

An "artifact" is anything on the trace that did not come from the heart. Three are common enough to recognise on sight. Switch one on, see what it looks like, then find the filter that removes it — and notice what that filter costs you.

Baseline wander · looks like slow rolling
The whole trace drifts up and down beneath the beats. Comes from breathing moving the chest, or an electrode losing grip so its own voltage changes. Slow — under 1 Hz.
Muscle tremor · looks like fuzzy grass
A rapid ragged jitter riding on everything. Comes from skeletal muscle: a cold, tense or shivering patient. Fast and irregular — roughly 20 to 100 Hz.
Mains hum · looks like a thick fuzzy line
A perfectly regular buzz at exactly 50 Hz (or 60 Hz in some countries). Comes from the building wiring, picked up by the leads. Regular is the clue — muscle noise never looks this even.
Baseline wander
Respiration / loose electrode (0.3 Hz)
Muscle tremor (EMG)
Shivering / tense patient (55–85 Hz)
AC mains
Unshielded cable (50 Hz)
7A parallel path — counting beats

Not part of drawing the trace at all. A separate copy is deliberately distorted so that beats become easy to detect.

Where rectification actually happens

Not in the displayed trace — rectifying that would destroy polarity, and polarity carries the diagnosis (a Q and an R differ only in sign). Rectification lives in the QRS detector, a parallel path used to find beats.

Beats detected
Rate from detector
This is the Pan–Tompkins chain. Squaring is the rectifying step: it makes every deflection positive and exaggerates tall sharp ones, so the QRS dominates P and T. Only then can a simple threshold find beats reliably.

The signal is clean. Now: what does the paper it is printed on actually mean?

Live strip

The square pulse on the left is the 1 mV calibration mark.

1 small box
1 large box
Cal pulse height
QRS on paper

Paper speed

Horizontal time scale only. Read it off the strip — never assume 25.

Gain

Vertical amplitude only. Half-standard when complexes are too tall to fit.

Here is the engine. Every trace in this simulator is a projection of this one rotating vector.

The heart vector loop

At any moment the heart's electricity is one arrow. Over a beat the tip of that arrow draws a loop. Drag the slider to watch it move.

Time through beat

The three QRS vectors

The loop is not one arrow — it is three, firing one after another. Change any of them and the loop reshapes.

● 1 · Septal (makes the q)
● 2 · Free wall (makes the R)
● 3 · Basal (makes the S)

Top slider of each pair sets direction, bottom sets size.

Projection makes the lead

Each bar shows how much of the arrow that lead can see. That number is exactly the height of the trace at the gold line.

Rotate the loop

Turn the whole loop and every lead changes shape together. This is what axis deviation means.

QRS axis
Rotation about long axis (Z)

Full 12-lead

All twelve come straight from the loop above. None of these shapes are drawn by hand.

QRS duration
Transition zone

With a real trace on real paper, rate becomes arithmetic.

Heart rate75 bpm

Drawn at the paper speed set in the Paper module: 25 mm/s. QT shortens with rate automatically (Bazett).

6-second method

For irregular rhythms. At 25 mm/s, 6 s = 150 mm = 30 large boxes.

Complexes counted
Estimate (×10)
Resolution is ±1 complex = ±10 bpm. At 75 bpm you count 7 and read 70 — the method working correctly, not an error.

Box counting — regular rhythms

Gold calipers mark one R–R interval.

Large-box method
Small-box method

Conduction blocks

If one pathway is blocked, that part of the ventricle is reached late and by slow muscle-to-muscle spread. A new, late vector appears — and the whole 12-lead changes with it. Picking a block overrides the sliders above.

Loop — grey is normal
The leads that give it away
QRS duration
Axis

Play the loop. The dot is where the vector is now; the number is milliseconds since the QRS began.

What it does to all twelve leads

The same block, shown everywhere. The normal beat is drawn faintly behind each one for comparison.

Why is a ventricular beat so big?

A VPC is usually taller and wider than the patient's own QRS. Both facts come from the same cause.

Normal beat
Ventricular beat
A normal beat runs down the His–Purkinje system, so both ventricles fire at the same moment, in roughly opposite directions. Most of that cancels, exactly like the scattered cells in the Vectors module — what is left over is a modest 1 mV.

A ventricular beat starts in one ventricle and crawls across muscle. The two ventricles fire one after the other, not together, so there is far less to cancel and a much larger vector survives. The slow muscle-to-muscle spread is also what makes it wide. Big and wide are the same fact seen twice.

The first 40 ms tells you where the beat started

A beat that gets into the His–Purkinje system early begins fast. One that has to crawl through muscle begins slowly. Compare the shaded start and end of each.

Initial speed (first 40 ms)
Terminal speed (last 40 ms)
Ratio Vi / Vt
QRS width

Now break the loop and see what the twelve leads report.

Infarct location → injury vector

Move the infarct around the heart. The red arrow is the injury current. It always points outward through the damaged wall.

Location
Severity

Stage

ST across all 12 leads

Green = elevation, violet = reciprocal depression, grey = near-perpendicular.

Quiz

0 / 0

Question 1

Now put it together. Same engine, but you call it.

Case

0 correct

Rhythm strip — lead II, 10 seconds

Scroll it sideways. Second marks are along the bottom; the shaded band is 6 seconds.

Paper speed
25 mm/s
Gain
10 mm/mV

Work through it in order

Answer each step. The tool checks you before moving on, so you learn the sequence, not just the answer.