Home > Enterprise >  plot ECG from .mat file
plot ECG from .mat file

Time:07-12

I'm new to python, how we can plot an ECG signal from a .mat file in python?

Code:

import matplotlib.pyplot as plt
import ecg_plot
import scipy.io as sio
import numpy as np
from scipy.misc import electrocardiogram
ecg=sio.loadmat('/content/hc001.mat')
print(ecg)

Answer:

{'val': array([[ 21,  22,  24, ..., 236, 174,  84]], dtype=int16)}

CodePudding user response:

This is one fairly easy method using the ecg_plot package:

Install in terminal: pip install ecg_plot

Then in Python:

import ecg_plot
    
ecg=sio.loadmat('/content/hc001.mat')
ecg_plot.plot(ecg, sample_rate = 500)
ecg_plot.show()

CodePudding user response:

For the following example, I have downloaded the ECG mat files from enter image description here For further details, take a look at this example from scipy.

  • Related