In [1]:
import numpy as np
import plotly.graph_objects as go

from scipy import signal, fft

from ecg import ECG
from wfdb_db_reader import WfdbDbReader
In [2]:
ECG_SIGNALS_DIR = './physionet.org/files/mitdb/1.0.0/'

wfdb_db_reader = WfdbDbReader(ECG_SIGNALS_DIR)
ecg_inst = wfdb_db_reader.get_ecg('100')
Getting list of record names from './physionet.org/files/mitdb/1.0.0/RECORDS'...

ECG signal visualization of filtered and non-filtered signal

In [3]:
fig = go.Figure()

max_sample = ecg_inst.samp_freq * 10 # ten seconds of the signal
x_coords_to_max = ecg_inst.time[:max_sample]

fig.add_trace(go.Scatter(x=x_coords_to_max, 
                         y=ecg_inst.signal[:max_sample], 
                         mode='lines', name='raw signal'))

fig.add_trace(go.Scatter(x=x_coords_to_max, 
                         y=ecg_inst.filt_signal[:max_sample], 
                         mode='lines', name='filtered signal'))

r_peaks_locs = ecg_inst.r_peaks_locs[ecg_inst.r_peaks_locs < max_sample]
fig.add_trace(go.Scatter(x=[ecg_inst.time[r_peak_loc] for r_peak_loc in r_peaks_locs],
                         y=[ecg_inst.signal[r_peak_loc] for r_peak_loc in r_peaks_locs],
                         mode='markers', name='R Peaks'))

fig.update_xaxes(title_text='Time (s)')
fig.update_yaxes(title_text='Voltage (mV)')

fig.show()
Learning initial signal parameters...
Found 8 beats during learning. Initializing using learned parameters
Running QRS detection...
QRS detection complete.