WFDB Example¶
This example demonstrates how to load a WFDB record, specifically record 100 from the MIT-BIH Arrhythmia Database available on PhysioNet. This record includes signal data (.dat), header information (.hea), and annotations (.atr).
Loading Data and Annotations¶
The WFDBImporter automatically detects and loads annotations if the corresponding .atr file is found alongside the .hea and .dat files.
Key Steps Explained¶
- Import
EMG: The core class is imported. - Define Path: The path to the WFDB header file (
.hea) is specified. - Load Data:
EMG.from_file()is called with the header file path. EMGIO infers the importer ('wfdb') based on the.heaextension (this could also be explicitly set usingimporter='wfdb'). The importer reads the header, data, and automatically looks for100.atrto load annotations. - Access Metadata: Basic metadata like
record_nameandsampling_frequencyare accessed usingemg.get_metadata(). - Access Channels: Information about the loaded channels (
MLII,V5) is iterated throughemg.channels. - Access Annotations: The script checks if the
emg.eventsDataFrame is populated. If the.atrfile was loaded successfully, it prints the first and last few annotations. - Plotting: A short segment of the first channel is plotted using
emg.plot_signals(). - Exporting: The loaded data (including annotations) is exported to both EDF+ and BDF+ formats using
emg.to_edf(). The presence of annotations is noted in the output.
Running the Example¶
- Ensure you have the necessary files (
100.hea,100.dat,100.atr) in theexamples/directory. - Run the script from the project root directory:
python examples/wfdb_example.py
You should see output detailing the loaded metadata, channels, annotations, and the paths to the exported EDF and BDF files. A plot window showing the first 10 seconds of the 'MLII' channel will also appear.