📜  Scipy – 显示心电图

📅  最后修改于: 2022-05-13 01:54:19.551000             🧑  作者: Mango

Scipy – 显示心电图

心电图是使用安装在皮肤上的电极来产生心电图的做法,心电图是心脏电活动的电压与时间的关系图。

应用:

  • 心跳分析
  • 癌症治疗

在使用 scipy 的Python中,我们可以使用scipy.misc.electrocardiogram()生成心电图

它用于加载心电图并且仅返回一维信号。

返回的信号是5分钟长的心电图(ECG),它是心脏电活动的医学记录,它基本上返回一个n维数组。



方法:

  • 导入 numpy 和 scipy 模块。
  • 创建心电图模型。
  • 用频率计算时间数据。
  • 显示图形。

实现:

Python
# 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 tine and ecg model
plt.plot(time_data, ecg)
plt.xlabel("time in seconds")
plt.ylabel("ECG in milli Volts")
  
# display
plt.show()


Python3
# 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 tine 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()


Python
print(ecg)


Python3
#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 tine 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()


输出:

  • 更改 x、y 限制以实现清晰可视化。

蟒蛇3

# 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 tine 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()

输出:



  • 心电图显示阵列:

Python

print(ecg)

输出:

[-0.245 -0.215 -0.185 ... -0.405 -0.395 -0.385]
  • 将频率更改为 1

蟒蛇3

#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 tine 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()

输出: