Open In App

Scipy – Display electrocardiogram

Electrocardiography is the practice of using electrodes mounted on the skin to produce an electrocardiogram, which is a graph of voltage versus time of the electrical activity of the heart.

Applications:



In python using scipy we can generate electrocardiogram by using scipy.misc.electrocardiogram()

It is used to load an electrocardiogram and will return only 1-D signal.



The signal which is returned is a 5-minute-long electrocardiogram (ECG), which is a medical recording of the heart’s electrical activity, it basically returns an n -Dimensional array.

Approach:

Implementations:




# import electrocardiogram
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
  
# import numpy
import numpy as np
  
# define electrocardiogram as ecg model
ecg = electrocardiogram()
  
# frequency is 0
frequency = 360
  
# calculating time data with ecg size along with frequency
time_data = np.arange(ecg.size) / frequency
  
# plotting time and ecg model
plt.plot(time_data, ecg)
plt.xlabel("time in seconds")
plt.ylabel("ECG in milli Volts")
  
# display
plt.show()

Output:




# import electrocardiogram
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
  
# import numpy
import numpy as np
  
# define electrocardiogram as ecg model
ecg = electrocardiogram()
  
# frequency is 360
frequency = 360
  
# calculating time data with ecg size along with frequency
time_data = np.arange(ecg.size) / frequency
  
# plotting time and ecg model
plt.plot(time_data, ecg)
plt.xlabel("time in seconds")
plt.ylabel("ECG in milli Volts")
plt.xlim(9, 10.2)
plt.ylim(-1, 1.5)
# display
plt.show()

Output:




print(ecg)

Output:

[-0.245 -0.215 -0.185 ... -0.405 -0.395 -0.385]




#import electrocardiogram
import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram
  
#import numpy
import numpy as np
  
# define electrocardiogram as ecg model
ecg = electrocardiogram()
  
# frequency is 1
frequency = 1
  
# calculating time data with ecg size along with frequency
time_data = np.arange(ecg.size) / frequency
  
# plotting time and ecg model
plt.plot(time_data, ecg)
plt.xlabel("time in seconds")
plt.ylabel("ECG in milli Volts")
plt.xlim(9, 10.2)
plt.ylim(-1, 1.5)
  
# display
plt.show()

Output:


Article Tags :