This repository contains accompanying code for our IEEE Engineering in Medicine & Biology (EMBC) 2023 paper (available on IEEE or accepted manuscript can be found on University of Bath's ResearchPortal) on denoising and decoding spontaneous vagus nerve recordings with machine learning. More specifically, two ML models (VAE and Noise2Noise) were adapted, implemented, and compared with conventional bandpass filtering. Note that this repository is not actively maintained, and the related dataset is only available upon request.
generate_mov_rms_figure.py: Generates time-domain and moving RMS plots for draft paper, and prints some of the metrics. Requires models to have been run and inputs/reconstructions to have been saved.preprocess.py: Take the originalbaselineFast.matfile containing ENG data and generate train, validation, and test sets (currently labelled as "n2n" but being used for both VAE and N2N models)train_n2n.py: Train Noise2Noise modeltrain_vae.py: Train VAE modeldatasets/vagus_dataset.py: Take processed datasets and prepare them to be used in PyTorch (e.g. with DataLoader, batches, etc)models/noise2noise_model.py: PyTorch implementation for Noise2Noise model.models/vae.py: PyTorch implementation for VAE model.utils/preprocessing.py: Useful functions for processing/splitting data.
Code can be run as follows:
-
Install dependencies from
requirements.txt(Windows) orrequirements.ubuntu22.txt(Linux) in a venv, as follows:# Create new venv if needed python -m venv .venv pip install -r requirements.txt -
Create the directories
data/Metcalfe-2014/,plots/, andresults/at the top level of the repo -
Copy
baselineFast.matfile intodata/Metcalfe-2014/ -
Run
preprocess.pyto generate training, validation, and test sets. -
Train VAE and Noise2Noise models using the corresponding training scripts and modifying any hyperparameters if needed (see file descriptions above)
-
Run
generate_mov_rms_figure.pyto generate plots and metrics from the manuscript.
Alternatively, steps 4-6 can also be replaced by just using pretrained/previously obtained results.