I plotted a an ECG signal form a .dat file using this code :
import wfdb
record = wfdb.rdsamp('mitdb/100', sampto=3000)
annotation = wfdb.rdann('mitdb/100', 'atr', sampto=3000)
print(type(record))
wfdb.plotrec(record,
title='Record 100 from MIT-BIH Arrhythmia Database .dat form',
timeunits = 'seconds', figsize = (10,4), ecggrids = 'all')
and I got the following plot :
ecg plot out of a .dat file
Then i tried to plot the same signal out of a .wav file using this python code :
import matplotlib.pyplot as plt
import numpy as np
import wave
spf = wave.open('sig100.wav','r')
#Extract Raw Audio from Wav File
signal = spf.readframes(-1)
signal = np.fromstring(signal, 'Int16')
fs = spf.getframerate()
#If Stereo
if spf.getnchannels() == 2:
print ('Just mono files 11')
Time=np.linspace(0, len(signal)/fs, num=len(signal))
print(Time)
plt.figure(1)
plt.title('Record 100 from MIT-BIH Arrhythmia Database .wav form')
plt.plot(Time,signal)
plt.show()
ang I got the following result :
ecg plot out of .wav file
how can I get a plot similar to the first one out of a .wav file and why did I get a different result first place