SciPy - electrocardiogram() 方法



SciPy electrocardiogram() 方法是 scipy.misc 模組的一部分,該模組代表訊號處理和分析。它用於表示心臟的電活動。簡而言之,我們可以將此方法稱為 ECG,它有助於構建醫療裝置。

語法

以下是 SciPy electrocardiogram() 方法的語法 -

electrocardiogram()

引數

此方法不採用任何引數。

返回值

此方法不返回值。

示例 1

以下是 SciPy electrocardiogram() 方法的基本示例,它說明了 ECG 訊號的繪製。

import matplotlib.pyplot as plt
from scipy.misc import electrocardiogram

# load the ECG signal
ecg = electrocardiogram()

# Plot the ECG signal
plt.plot(ecg)
plt.title('Electrocardiogram (ECG) Signal')
plt.xlabel('Number')
plt.ylabel('Amplitude')
plt.show()

輸出

以上程式碼產生以下輸出 -

scipy_electrocardium_method_one

示例 2

在這裡,您可以看到使用 scipy.signal 模組中的 butterfiltfilt 函式在 ECG 訊號中演示低通濾波器。經過濾波後,它會去除噪聲(高頻)並並行繪製兩個訊號。

import numpy as np
from scipy.signal import butter, filtfilt
from scipy.misc import electrocardiogram

# load the ECG signal
ecg = electrocardiogram()

# design a low-pass filter
fs = 360  # Sampling frequency (assumed)
cutoff = 50  # Desired cutoff frequency of the filter, Hz
nyq = 0.5 * fs
normal_cutoff = cutoff / nyq
b, a = butter(5, normal_cutoff, btype='low', analog=False)

# apply the filter to the ECG signal
filtered_ecg = filtfilt(b, a, ecg)

# Plot the original and filtered ECG signals
import matplotlib.pyplot as plt
plt.figure(figsize=(12, 6))
plt.plot(ecg, label='Original ECG')
plt.plot(filtered_ecg, label='Filtered ECG', linestyle='--')
plt.title('Low-pass Filtered Electrocardiogram (ECG) Signal')
plt.xlabel('Number')
plt.ylabel('Amplitude')
plt.legend()
plt.show()

輸出

以上程式碼產生以下輸出 -

scipy_electrocardium_method_two

示例 3

from scipy.signal import find_peaks
from scipy.misc import electrocardiogram
import matplotlib.pyplot as plt

# Load the ECG signal
ecg = electrocardiogram()

# Detect R-peaks in the ECG signal
peaks, _ = find_peaks(ecg, distance=150)

# Plot the ECG signal with detected R-peaks
plt.plot(ecg, label='ECG Signal')
plt.plot(peaks, ecg[peaks], "x", label='R-peaks')
plt.title('R-peak Detection in Electrocardiogram (ECG) Signal')
plt.xlabel('Number')
plt.ylabel('Amplitude')
plt.legend()
plt.show()

輸出

以上程式碼產生以下輸出 -

scipy_electrocardium_method_three
scipy_reference.htm
廣告
© . All rights reserved.