SMF sequentially applies matched filters (MFs) designed by a signal-aware neural network policy, and identifies ECG R-peaks at the final step. The policy is trained end-to-end using Reinforcement Learning (RL).
This is the official implementation of the Sequential Matched Filter (SMF) algorithm, presented in:
Machine Intelligence on the Edge: Interpretable Cardiac Pattern Localisation Using Reinforcement Learning
Haozhe Tian, Qiyu Rao, Nina Moutonnet, Pietro Ferraro, Danilo Mandic
Machine Intelligence Research [arXiv]
SMF is a lightweight, interpretable ECG R-peak detector that uses matched filters (MFs) to iteratively refine signals. SMF bridges classical signal processing and reinforcement learning, offering an interpretable alternative to black-box deep models for ECG analysis. You can run a quick, cloud-based trial of SMF via Code Ocean. (If the link does not open directly, please copy and paste https://doi.org/10.24433/CO.8370367.v1 into your browser.)
Tested on Ubuntu 22.04 with Python 3.8+. Set up the conda environment by running:
conda env create -f environment.yml
conda activate SMFpython compare.pyA demonstration notebook test.ipynb is provided for running inference with trained checkpoints. The core is a validate function:
from agents.ppo import PPO
from env import SMF
# Initialise environment: 3 MF steps, template length 8
env = SMF(eps_len=3, template_len=8)
# Load pre-trained PPO agent
agent = PPO(env, ckpt_path='saved/eps_len_3/PPO_best.pt', use_tb=False)
# Run validation
ecg, sig, peaks, preds, TP, FP, FN = validate(env, agent)| Argument | Description |
|---|---|
eps_len |
Number of sequential MF steps |
template_len |
Length of each matched filter template |
ckpt_path |
Path to a saved model checkpoint |
python train.py --agent ppo --eps_len 3 --template_len 8If you find the code in this repository useful, please cite:
@article{tian2025machine,
title={Machine Intelligence on the Edge: Interpretable Cardiac Pattern Localisation Using Reinforcement Learning},
author={Tian, Haozhe and Rao, Qiyu and Moutonnet, Nina and Ferraro, Pietro and Mandic, Danilo},
journal={arXiv preprint arXiv:2508.21652},
year={2025}
}If you use the PhysioNet/CinC 2017 dataset included in this repository, please also cite:
@inproceedings{clifford2017af,
title={AF Classification from a Short Single Lead ECG Recording: The PhysioNet/Computing in Cardiology Challenge 2017},
author={Clifford, Gari D and Liu, Chengyu and Moody, Benjamin and Lehman, Li-wei H and Silva, Ikaro and Li, Qiao and Johnson, Alistair E and Mark, Roger G},
booktitle={2017 Computing in Cardiology (CinC)},
pages={1--4},
year={2017},
organization={IEEE}
}