The model gets one ECG lead and the time of every R-peak, the tall spike of each beat. Here the R-peaks come from the database annotations; the model has no beat detector of its own.
1 Clean
2 Windows
3 Normal beat
4 Timing
5 Cascade
6 Inside
Clean the signal
Breathing and movement make the signal drift. Two median filters (200 ms, then 600 ms) estimate the drift, and it is subtracted. A notch removes mains hum at 50 and 60 Hz, a low-pass removes everything above 35 Hz, and every database is resampled to 128 samples per second. The filters run forwards and backwards, so no beat moves in time.
Cut one window per beat
A beat's window runs from halfway to the previous beat to halfway to the next one. Windows are not stretched: a long beat keeps a long window, because its duration is information. Model 1 reads the beat alone, padded to 1.72 s; Model 2 reads it with its two neighbours, padded to 5.16 s. The models ignore the padding.
Compare with the patient's normal beat
A ventricular beat looks different in every patient, but it always differs from that patient's own normal beat. For each beat, the median of the previous 64 beats that arrived on time becomes a template; early beats are left out, so the template stays normal even when every second beat is ventricular. The residual, beat minus template divided by the template's spread, is a second input to both models. It uses only past beats, so it works on a live recording.
Measure the timing
Premature beats arrive early and are often followed by a pause. Four numbers describe it, each compared with the mean distance between the 8 beats before: the distance from the previous beat, the distance to the next one, the ratio of the two, and how irregular the recent rhythm was. A beat exactly on time scores 1, 1, 1 and close to 0.
Two models in a cascade
Model 1 asks whether the beat is ventricular. If not, Model 2 asks whether it is supraventricular; otherwise the beat is normal. Both cuts are fixed at 0.5 and were never tuned on test data. The classes were weighted equally in training, so the models rarely miss an S or V beat, at the price of flagging some normal ones.
Model 1, a ventricular beat
Model 2, a supraventricular beat
Click the boxes
Animation
Inside each model
Left, the model as a diagram: boxes are layers, arrows carry the data, with its size (samples × channels, or numbers). Right, the data of one real beat at the box you pick, or, in the animation, at every layer in turn. All values are the model's real ones. Both models share this design, about 120,000 weights each; Model 2 reads three beats instead of one and has a second dense layer.