betaFeedback

WorksComputer Science

Few-Shot Prototype Head Adaptation for On-Device ECG Personalization on PSoC~6

Abstract

Wearable and bedside electrocardiogram (ECG) monitors must adapt to patient-specific morphology to maintain arrhythmia detection accuracy across users, yet personalization is typically performed offline and cannot account for individual physiology, electrode placement, or recording drift. On-device adaptation by backpropagation is expensive for microcontroller-class medical devices because it requires an optimizer state, repeated backward passes through convolutional layers, and labeled arrhythmic beats that may not be available at deployment time. This letter proposes prototype-only head adaptation as a compact personalization primitive for TinyML ECG systems. A one-dimensional convolutional neural network (1-D CNN; 1,314 parameters and 72.6k multiply-accumulate operations per beat) is trained offline on the MIT-BIH Arrhythmia Database under an inter-patient protocol, frozen as a feature extractor, and exported to a PSoC 6 microcontroller. Patient-specific adaptation then reduces to computing closed-form class means in a 32-dimensional embedding space, requiring no convolutional backward pass, no iterative optimization, and only one forward pass per support beat. Prototype adaptation improves inter-patient macro-F1 from 0.635/0.639/0.646 to 0.731/0.771/0.797 at 1/5/10-shot, outperforming linear stochastic-gradient-descent (SGD) head fine-tuning at every shot count for the target tiny backbone. On-device replay over 18 one-shot episodes on a PSoC 6 Cortex-M4F matches the host macro-F1 for the prototype head (0.798), with 11.39 ms per beat, 5.2 KB flash, and 22.2 KB SRAM. A restricted variant that updates only the normal-class prototype from passively buffered sinus beats yields a consistent +0.05 macro-F1 gain, reducing the annotation burden during initial

Introduction

Patient-specific ECG morphology varies with physiology, electrode placement, and recording conditions, causing models trained on one population to degrade on unseen individuals under inter-patient evaluation protocols [1]. Wearable and bedside arrhythmia monitors, therefore, need a mechanism to personalize a deployed classifier for each new user without re-running a full training pipeline in the cloud. Tiny machine learning (TinyML) has made neural-network inference feasible on microcontroller-class IoT devices [2, 3], bringing the classifier physically close to the sensor, but the question of how to adapt that classifier on the same constrained device remains open.

Two barriers make on-device ECG personalization hard. The first is computational. Backpropagation through convolutional layers requires optimizer state, repeated backward passes, and working memory that exceeds the budget of sub-milliwatt medical microcontrollers. Prior work has shown that on-device training is possible under 256 KB SRAM [4] and that 1-D CNN personalization for human activity recognition is feasible on STM32 hardware [5], yet both approaches rely on gradient-based updates that are costly relative to a medical device’s strict power and latency envelope. The second barrier is annotation. Since arrhythmic events are rare, the newly deployed monitor accumulates hundreds of normal sinus beats before a single labeled abnormal beat is available. Gradient-based head fine-tuning cannot begin calibration from normal-only data because it requires labeled examples from every class to update the weight matrix meaningfully. Self-supervised and human-in-the-loop methods have highlighted this gap but remain constrained by limited medical equipment resources [6].

This letter addresses both barriers with a prototype-only head adaptation mechanism. A compact 1-D CNN (1,314 parameters, 72.6k multiply–accumulate operations – MACs – per beat) is trained offline on the MIT-BIH Arrhythmia Database [7] under the inter-patient protocol [1], and its convolutional backbone is then frozen and exported to a PSoC 6 microcontroller. Patient-specific adaptation reduces to computing closed-form class means in a 32-dimensional embedding space, one forward pass per support beat, no backward pass, no optimizer state. A restricted variant further reduces the annotation burden by updating only the normal-class prototype from passively buffered sinus beats, inheriting the abnormal prototype from offline training.

We verify the proposal through three complementary evaluations. (i) Accuracy: prototype adaptation improves inter-patient macro-F1 from 0.635/0.639/0.646 to 0.731/0.771/0.797 at 1/5/10-shot on eligible DS2 patients (vs. 0.664 pre-adaptation on all 22 DS2 records), outperforming a linear-SGD head baseline on a tiny backbone neural network. The restricted normal-only variant yields a consistent +0.05 macro-F1 gain without any arrhythmia annotations. (ii) On-device fidelity: aggregate replay over one-shot DS2 episodes on the target Cortex-M4F matches host macro-F1 (0.798 macro-F1, absolute deviation 0.000), confirming that the closed-form update is numerically faithful on fp32 hardware. (iii) Embedded cost: Data Watchpoint and Trace (DWT) cycle counter profiling reports 11.39 ms per beat (2.8% of the 400 ms RR interval at 150 BPM), with a model-centric footprint of 5.2 KB flash and 22.2 KB SRAM on a device with 1 MB flash and 288 KB SRAM.

Prototype-Only Head Adaptation

Figure 1 summarizes the deployment flow. In the offline phase, a compact 1-D CNN is trained on DS1. At export time, the convolutional backbone is frozen and stored as constant CC arrays. At deployment, support beats from the target patient are passed through the frozen backbone, and only the classification head is adapted.

Prototype-only ECG personalisation deployment pipeline

Figure 1. Prototype-only ECG personalisation pipeline. Offline: a compact 1-D CNN is trained on DS1 under an inter-patient split; the frozen backbone is exported as native-C arrays. On-device (PSoC 6): the backbone maps support beats to 32-D embeddings; per-class prototypes are computed as closed-form means. Query beats are classified by nearest-prototype distance—with no backward pass, no optimizer state, and no backbone writes.

Each ECG beat is represented as a 200-sample window centered at an annotated R-peak. The target backbone has two convolutional blocks (1→8→16), each with a kernel size of 5, ReLU, max-pooling, global average pooling, and a linear projection to D=32D = 32. A 2-way head map embedding to normal/abnormal logits. The tiny model has 1,314 parameters and 72,576 MACs per beat; medium and large variants (Table 3) scale to 2,618/157k and 4,930/274k, respectively. Beat segmentation and R-peak detection are assumed to be provided upstream by the monitoring system; this work focuses on the embedded personalization primitive.

Let fθ:R200→RDf_\theta: \mathbb{R}^{200} \to\mathbb{R}^{D} denote the frozen backbone, with D=32D = 32. In the full few-shot setting, the patient-specific support set is

S={(xi,yi)}i=1K⋅C.(1)S = \{(x_i, y_i)\}_{i=1}^{K \cdot C}. \tag*{(1)}

where xi∈R200x_i \in\mathbb{R}^{200}, yi∈{0,…,C−1}y_i \in\{0, \ldots, C - 1\}, C=2C = 2, and KK is the number of support beats per class. For class cc, define

Sc={xi∣(xi,yi)∈S, yi=c}.(2)S_c = \{x_i \mid(x_i, y_i) \in S,\ y_i = c\}. \tag*{(2)}

with ∣Sc∣=K|S_c| = K in the balanced protocol. Each support beat is embedded as zi=fθ(xi)z_i = f_\theta(x_i), and the class prototype is the mean embedding

pc=1∣Sc∣∑xi∈Scfθ(xi).(3)p_c = \frac{1}{|S_c|} \sum_{x_i \in S_c} f_\theta(x_i). \tag*{(3)}

Although richer prototype estimators have been proposed in recent few-shot learning work, including task-guided diffusion [8] and prototype–neighbor hybrid methods [9], these approaches typically rely on meta-training, auxiliary networks, or iterative inference. Such mechanisms are not aligned with the memory and latency constraints of a Cortex-M4F deployment. We, therefore, deliberately use the closed-form class mean, since it is the simplest estimator, requires only support-set inference and vector additions, and remains effective when the frozen backbone yields a compact embedding space.

A query beat xqx_q is embedded by the frozen backbone and scored against each prototype using the negative squared Euclidean distance:

sc(xq)=−∥fθ(xq)−pc∥22.(4)s_c(x_q) = -\lVert f_\theta(x_q) - p_c \rVert_2^2. \tag*{(4)}

The predicted class is

y^(xq)=arg⁡max⁡csc(xq)=arg⁡min⁡c∥fθ(xq)−pc∥22.(5)\hat{y}(x_q) = \arg\max_c s_c(x_q) = \arg\min_c \lVert f_\theta(x_q) - p_c \rVert_2^2. \tag*{(5)}

This update requires only support-set inference and class-wise additions in a 32-D space. It avoids storing the optimizer state and avoids backward propagation through the convolutional layers. Support beats from each class cluster around their respective centroids in the frozen embedding space, and the resulting prototypes define patient-specific decision boundaries without any gradient steps. We compare it against a linear-SGD head baseline, in which the frozen backbone is held fixed while the final linear layer is updated for 50 SGD steps using cross-entropy.

The per-class structure of the prototype update enables a clinically important restricted variant. In routine monitoring, arrhythmic beats are rare, and a device may accumulate hundreds of normal sinus beats before any arrhythmic event occurs, making annotation-dependent calibration impractical. We therefore evaluate a setting in which only normal-beat support is used; p0p_0 is updated via Equation (3) while p1p_1 is inherited from DS1 training, enabling passive annotation-free calibration that begins as soon as sufficient normal beats have been buffered.

Protocol and PSoC 6 Implementation

Experiments use the MIT-BIH Arrhythmia Database [7] under the inter-patient split of de Chazal et al. [1]. Dataset 1 (DS1) is used for training/validation, and dataset 2 (DS2), for held-out testing. The task is binary normal-versus-abnormal classification, where the abnormal class pools non-normal morphologies. We report macro-F1 to account for imbalance. The abnormal class pools structurally distinct morphologies (LBBB, RBBB, PVC, APB), justifying macro-F1 as the primary metric. Few-shot personalization uses K∈{1,5,10}K \in\{1, 5, 10\} support examples per class. Records without at least K+1K + 1 minority-class beats are excluded for that shot count.

Firmware validation targets the CY8CPROTO-063-BLE board, which integrates a PSoC 6 BLE device with a Cortex-M4F application core and 1 MB Flash / 288 KB SRAM [10]. The replay firmware stores exported weights and capped support/query episodes in flash, executes the frozen backbone and both head rules on the CM4, and logs metrics over UART. DWT cycle counts are collected from the CM4 Release build. The measured HF0 clock during profiling is 100 MHz.

Table 1 reports the model-centric memory budget for the deployable adaptation path. We report this separately from the full replay firmware image, which also contains board-support code, UART/profiling logic, the C runtime, and embedded replay assets. The source code to fully reproduce the work is available in https://github.com/eduluzufop/TinyML-ECG-Prototype-Adaptation.

ItemFlashSRAM
Backbone weights4.9 KB–
Head/prototypes0.3 KB0.3 KB
Peak activation buffer–6.3 KB
Support buffer, K=10K = 10–15.6 KB
Subtotal5.2 KB22.2 KB
PSoC 6 budget1024 KB288 KB
Utilization0.5%7.7%

Table 1. Model-centric memory budget of the deployable adaptation path on PSoC 6. Weights are stored as float32 constants in flash.

Results

Table 2 summarizes the accuracy and measured embedded costs for the target tiny backbone. Prototype adaptation consistently outperforms the pre-adaptation model and linear SGD. On the full eligible DS2 protocol, prototypes improve macro-F1 from 0.635 to 0.731 at 1-shot, from 0.639 to 0.771 at 5-shot, and from 0.646 to 0.797 at 10-shot. Linear SGD improves over the baseline but remains lower across all shot counts.

MethodKKDS2 F1Device F1Adapt. time
No adaptation–0.66420.611–
Linear SGD10.6710.68224.49 ms
Prototype10.7310.79822.83 ms
Prototype50.771–114.03 ms
Prototype100.797–228.04 ms
Normal-only proto100.699–≈10 ms1

Table 2. Accuracy and embedded cost for the target tiny backbone. Device F1 is computed on the capped 18-record 1-shot replay subset. Timing is measured with the Arm Data Watchpoint and Trace (DWT) cycle counter on the PSoC 6 CM4.

Figure 2 shows that the prototype F1 curve rises monotonically from 0.731 to 0.797 as KK increases, while SGD gains are smaller, and that prototype calibration is 17× faster than SGD at 1-shot in the host reference implementation (216 ms vs. 3690 ms; on-device, the gap is negligible at 22.83 ms vs. 24.49 ms). The pre-adaptation baseline rises with KK because the eligibility filter progressively removes the harder, more class-imbalanced records rather than reflecting any adaptation benefit.

Figure 2. Aggregate DS2 results across shot counts. Left: macro-F1 for each method. Right: software-side adaptation time from the host reference implementation. The pre-adaptation curve rises with KK because the eligibility filter excludes harder records, not due to any adaptation effect.

The aggregate on-device replay benchmark replaces a single-episode sanity check with hardware evidence over 18 DS2 1-shot episodes and 576 query beats. The device-side macro-F1 values are 0.611, 0.682, and 0.798 for pre-adaptation, linear SGD, and prototypes, respectively. Compared with the host reference on the exact same capped subset, the absolute differences are 0.000, 0.007, and 0.000. This confirms that the replay, embedding extraction, and prototype update remain faithful on target hardware.

The normal-only calibration mode is weaker than full prototype adaptation but is clinically meaningful. At K=10K = 10, it reaches 0.699 macro-F1 on the common eligible subset, compared with 0.649 before adaptation and 0.797 with full prototype support. This indicates that patient-specific normal morphology alone can shift the decision geometry in a useful direction, even though it cannot replace labeled abnormal support. Figure 3 shows that the gain is consistent across all shot counts (+0.045–0.050 macro-F1), representing roughly one-third of the full prototype improvement at K=10K=10 without requiring any arrhythmia annotation from the target patient. This is the intended deployment role of the restricted mode, an initial calibration step based on abundant (normal) sinus beats.

Figure 3. Restricted vs. full prototype adaptation on the common eligible DS2 subset. The restricted variant (only normal-beat support from the target patient) provides a consistent positive gain at a fraction of the cost of full prototype adaptation.

Measured DWT profiling reports 1,139,141 cycles per beat for the tiny backbone, corresponding to 11.39 ms at 100 MHz, 2.8% of the 400 ms beat-to-beat interval (a.k.a RR interval) at 150 BPM, confirming that the device classifies each beat in time even at clinically elevated heart rates. Figure 4 plots end-to-end calibration time on the CM4 as a function of KK for both methods. Both curves grow linearly with KK because each method requires one backbone forward pass per support beat. The narrow gap between them reflects only the head-update rule (closed-form mean vs. 50 SGD iterations). A 10-shot prototype calibration takes 228.04 ms (22,804,485 cycles), and the corresponding SGD calibration takes 244.66 ms, both within the 400 ms RR interval, so calibration is a short initialization event rather than a recurring per-beat cost.

Figure 4. End-to-end calibration time on the PSoC 6 CM4 at 100 MHz vs. number of support shots KK for prototype and linear SGD adaptation. Both methods scale linearly with KK (one backbone forward pass per support beat); the gap between the two curves is due solely to the head-update rule. The 400 ms RR interval at 150 BPM is shown for clinical reference.

Table 3 evaluates whether the prototype advantage is preserved under backbone scaling. The tiny backbone is both the primary embedded target and the setting where prototypes most consistently outperform SGD. Larger backbones narrow or reverse this advantage at low shot counts, indicating that the prototype-versus-SGD trade-off is capacity-dependent rather than a universal property of the head-adaptation approach.

VariantParamsMACsPre F11-shot10-shot
Tiny1,31472.6k0.664Proto .731Proto .797
Medium2,618157.0k0.642SGD .713Proto .764
Large4,930274.2k0.651SGD .720Proto .759

Table 3. Scaling study across backbone sizes. DS2 test F1 is reported before personalization. Few-shot columns show the best retuned head-adaptation method.

The consistent prototype advantage on the tiny backbone can be attributed to the geometry of its compressed embedding space. With D=32D = 32 and only 1,314 parameters, the intra-class variance is tightly bounded, making the closed-form mean a stable representative [11], a condition that more expressive estimators such as task-guided diffusion [8] or prototype-neighbor hybrids [9] are designed to relax, at the cost of auxiliary networks and iterative inference that exceed the MCU budget. Larger backbones produce richer manifolds where the mean prototype becomes a less faithful class summary, shifting the advantage toward SGD at low shot counts (Table 3).

Discussion, Limitations, and Conclusion

For the target tiny backbone, prototype adaptation is preferable to linear SGD because it directly matches the embedded constraint: no convolutional backward pass, no optimizer state, and a closed-form update in a 32-D embedding space. This is particularly attractive for patient-specific ECG calibration, where the support set is extremely small and gradient-based head updates can be ill-conditioned. The result complements prior on-device training work [4] and on-device HAR personalization [5] by exploring a point in the design space where adaptation is reduced to nearest-centroid updates rather than training. The per-class independence of this update also underlies the restricted normal-only variant, because p0p_0 and p1p_1 are updated separately, calibration can begin from passively buffered sinus (normal) beats alone (with no arrhythmia annotation required), a property that SGD-based head fine-tuning does not share, since it requires labeled examples from all classes to update the weight matrix meaningfully.

The scaling study shows that larger backbones do not automatically improve inter-patient macro-F1, and they make the prototype-versus-SGD ranking shot-dependent. Therefore, our claim is not that prototypes dominate all personalization regimes, but that they are especially well matched to the target tiny model and MCU deployment path.

Since this work focuses on the embedded personalization primitive rather than a complete diagnostic pipeline, beat segmentation and R-peak detection are assumed to be upstream, and the classification task is binary (normal versus abnormal) rather than the full AAMI five-class taxonomy. The aggregate on-device replay uses a flash-capped subset of 18 one-shot DS2 episodes, although it matches the host reference on that subset. The current firmware uses native C float32 kernels rather than an int8 deployment with TensorFlow Lite for Microcontrollers (TFLM) [12].

In conclusion, this letter presents a prototype-only head adaptation mechanism for TinyML ECG personalization on a PSoC 6 microcontroller. By freezing the 1-D CNN backbone and replacing gradient-based head fine-tuning with closed-form class means, the method improves inter-patient macro-F1 for the target tiny model while remaining feasible within a small measured memory and timing footprint. The restricted normal-only variant further demonstrates that a meaningful personalization gain could be achievable from passively buffered normal beats alone, reducing the need for arrhythmia annotations during initial device deployment. Future work will extend the firmware to int8/TFLM, integrate upstream beat detection, and evaluate the full AAMI five-class setting.

References

  1. [1]P. de Chazal, M. O’Dwyer, R. B. Reilly, Automatic classification of heartbeats using ecg morphology and heartbeat interval features, IEEE Transactions on Biomedical Engineering 51 (7) (2004) 1196–1206.pubmed.ncbi.nlm.nih.gov/15248536
  2. [2]C. Banbury, V. J. Reddi, P. Torelli, N. Jeffries, C. Kiraly, J. Holleman, P. Montino, D. Kanter, P. Warden, D. Pau, U. Thakker, A. Torrini, J. Cordaro, G. D. Guglielmo, J. Duarte, H. Tran, N. Tran, N. Wenxu, X. Xuesong, MLPerf tiny benchmark, in: NeurIPS 2021, 2021.arxiv.org/abs/2106.07597
  3. [3]J. Lin, W.-M. Chen, Y. Lin, J. Cohn, C. Gan, S. Han, Mcunet: Tiny deep learning on iot devices, in: NeurIPS 2020, 2020, pp. 11711–11722.arxiv.org/abs/2007.10319
  4. [4]J. Lin, L. Zhu, W.-M. Chen, W.-C. Wang, C. Gan, S. Han, On-device training under 256kb memory, in: NeurIPS 2022, 2022, pp. 22941–22954.arxiv.org/abs/2206.15472
  5. [5]M. Craighero, D. Quarantiello, B. Rossi, D. Carrera, P. Fragneto, G. Boracchi, On-device personalization for human activity recognition on stm32, IEEE Embedded Systems Letters 16 (2) (2024) 106–109. doi : 10.1109/LES.2023.3293458.DOI
  6. [6]G. Silva, P. Silva, G. Moreira, E. Luz, Bridging the gap in ecg classification: Integrating self-supervised learning with human-in-the-loop amid medical equipment hardware constraints, in: International Symposium on Applied Reconfigurable Computing, 2024, pp. 63–74.DOI
  7. [7]G. B. Moody, R. G. Mark, The impact of the mit-bih arrhythmia database, IEEE Engineering in Medicine and Biology Magazine 20 (3) (2001) 45–50.pubmed.ncbi.nlm.nih.gov/11446209
  8. [8]Y. Du, Z. Xiao, S. Liao, C. G. M. Snoek, Protodiff: Learning to learn prototypical networks by task-guided diffusion, in: NeurIPS 2023, 2023, pp. 46304–46322.arxiv.org/abs/2306.14770
  9. [9]Z. Jiang, Z. Feng, B. Niu, Prototype-neighbor networks with task-specific enhanced meta-learning for few-shot classification, Neural Networks 190 (2025) 107761. doi : 10.1016/j.neunet.2025.107761.DOI
  10. [10]Infineon Technologies, CY8CPROTO-063-BLE PSoC 6 BLE Prototyping Board Guide, Infineon Technologies (2020).
  11. [11]J. Snell, K. Swersky, R. Zemel, Prototypical networks for few-shot learning, in: NeurIPS 2017, 2017, pp. 4080–4090.arxiv.org/abs/1703.05175
  12. [12]R. David, J. Duke, A. Jain, V. J. Reddi, N. Jeffries, J. Li, N. Kreeger, I. Nappier, M. Natraj, T. Wang, P. Warden, R. Rhodes, Tensorflow lite micro: Embedded machine learning for tinym l systems, in: Proceedings of Machine Learning and Systems, Vol. 3, 2021, pp. 800–811.

Paper details

vlnc:W_t98yg943
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

Not recorded for this paper

View statement
Looking for related papers…
Contents