374 lines
481 KiB
Plaintext
374 lines
481 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"# Signal Processing\n",
|
||
|
"\n",
|
||
|
"The notebook goes into more detail on the processing of the 12 ECG data per patient. First, the signal itself is considered and then the ECG signal processing methods integrated in the 'wfdb' module are explored. Various approaches are then used to normalize the data and reduce noise in order to make the signals as comparable as possible."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"from matplotlib import pyplot as plt\n",
|
||
|
"import wfdb.processing\n",
|
||
|
"import sys\n",
|
||
|
"import json\n",
|
||
|
"import scipy\n",
|
||
|
"import numpy as np\n",
|
||
|
"\n",
|
||
|
"sys.path.append('../scripts')\n",
|
||
|
"import data_helper"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"## Load Data"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Reading SB\n",
|
||
|
"Reading AFIB\n",
|
||
|
"Reading GSVT\n",
|
||
|
"Reading SR\n",
|
||
|
"Number of patients per category:\n",
|
||
|
"SB: 16559\n",
|
||
|
"AFIB: 9839\n",
|
||
|
"GSVT: 948\n",
|
||
|
"SR: 9720\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"data = data_helper.load_data(only_demographic=False)\n",
|
||
|
"\n",
|
||
|
"print(\"Number of patients per category:\")\n",
|
||
|
"for cat_name in data.keys():\n",
|
||
|
" print(f\"{cat_name}: {len(data[cat_name])}\")"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Load the parameters needed to filter the data"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"with open('../filter_params.json', 'r') as f:\n",
|
||
|
" filter_params = json.load(f)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"example_data = data['SB'][0]\n",
|
||
|
"sig_channel= 0"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {},
|
||
|
"source": [
|
||
|
"Filter the data"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"filtered_data = data_helper.filter_data(example_data, filter_params)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"Learning initial signal parameters...\n",
|
||
|
"Failed to find 8 beats during learning.\n",
|
||
|
"Initializing using default parameters\n",
|
||
|
"Running QRS detection...\n",
|
||
|
"QRS detection complete.\n",
|
||
|
"[ 544 1114 1683 2281 2855 3452 4016 4606]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1kAAAHWCAYAAACFeEMXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAAC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NTmm266CTfddBOqqqqwfft2fPTRR/j8889x9dVX4+DBg7KCF2fPngUAIZxNTOfOnWUX9GJDEIBgcJWXlwvHysrKsHjxYnz55Zce/VRZWenT7xEzevRoLFu2DCdPnsSpU6fAMAyGDx8uGF933nknNm/ejJEjR6oSG3H/bQD3+8S/rTGuvfZazJs3DwzDICEhAb169UJcXBwALhSRZVk8/vjjePzxx2XfX1RUhKysLDgcDvzrX//CW2+9hby8PNjtduGcli1berxv/vz5aGhowN69e2XDGl944QXMnj0bbdu2xaBBg5CTk4PbbrsNHTt29Ol3EQRBBBoysgiCIC4DHA4HAOCWW27xaiTx+UE8Yu+N+DNefPFFD88CT3x8PMxms8rWSklMTMTkyZMxefJkRERE4OOPP8b27dsxduxYTT7faDTKHmdZVnh8ww03YOvWrXjooYfQv39/xMfHw+FwYNq0aUK/KGHUqFEAgE2bNuH06dMYOHAg4uLiMHr0aLz22muoqanB3r178cwzz/j3o5z48tsao02bNpg0aZLsa/zvfvDBB716KHlj99lnn8Xjjz+OO+64A08//TRSUlJgMBgwf/582f679tpr8eWXX+K
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x500 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# Normalize data by setting qrs peaks to index position 0 (“X-axis normalization”)\n",
|
||
|
"indicies = wfdb.processing.xqrs_detect(filtered_data.p_signal[:,sig_channel],example_data.fs,0,5000)\n",
|
||
|
"print(indicies)\n",
|
||
|
"\n",
|
||
|
"peak_points_y = [filtered_data.p_signal[:,sig_channel][i] for i in indicies] \n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(10, 5))\n",
|
||
|
"plt.plot(filtered_data.p_signal[:,sig_channel])\n",
|
||
|
"plt.scatter(indicies, peak_points_y, color='red', label='Peaks')\n",
|
||
|
"plt.xlabel('Time')\n",
|
||
|
"plt.ylabel('Amplitude')\n",
|
||
|
"plt.title('Filtered XQRS Signal with Peaks')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1kAAAHWCAYAAACFeEMXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAAEAAElEQVR4nOydd3wT9f/HX5d0Lwp0Ugpl771EqICyrCJYUb64AHH/QBFx4ADBgbJEFMSF4EARrCgOhghSBEFBBBSQPUrpgu6R5HK/Pz65y11Gm+SuNAnv5+PRR3OXT5JP3vnc5z7vz3txgiAIIAiCIAiCIAiCIDRBV9cdIAiCIAiCIAiC8CdIySIIgiAIgiAIgtAQUrIIgiAIgiAIgiA0hJQsgiAIgiAIgiAIDSEliyAIgiAIgiAIQkNIySIIgiAIgiAIgtAQUrIIgiAIgiAIgiA0hJQsgiAIgiAIgiAIDSEliyAIgiAIgiAIQkNIySIIgvARTp8+DY7jsGLFCuncSy+9BI7j6q5TbqJ1fx3JpC5ZsWIFOI7D6dOna+X9U1JSMH78eJfb3nzzzbXSj9pi27Zt4DgOa9eureuuEARBqIKULIIgCC9BXKA7+nv22Wddfp/XXnsN69atq72OXiHWr1+PAQMGIC4uDmFhYWjevDnuuOMObNiwoa675jX8+++/eOmll2pFqZOPP51Oh0aNGmHo0KHYtm2b5p9FEAThbwTUdQcIgiAIJbNnz0azZs0U5zp27IimTZuioqICgYGB1b7+tddew+jRozFq1Kha7GXtMn/+fDz11FMYMGAApk+fjrCwMBw/fhw///wzvvzySwwfPhwAXJaJv3D06FHodNb90X///RezZs3CwIEDkZKSovnnDRkyBPfeey8EQcCpU6ewdOlSXH/99fjhhx9w4403av55BEEQ/gIpWQRBEF7GjTfeiJ49ezp8LiQk5Ar3hlFZWYmgoCDFAr+2MJlMePnllzFkyBBs2rTJ7vnc3FzpMcdxdSaTuiA4OPiKfl7r1q1x9913S8e33norOnfujEWLFpGSRRAEUQ3kLkgQBOEjuBJ/xHEcysrKsHLlSsnVSx7Dk5WVhfvuuw/x8fEIDg5Ghw4dsHz5csV7iHExX375JV544QUkJSUhLCwMxcXFAIDdu3dj+PDhqFevHsLCwjBgwAD89ttvdn3ZsWMHevXqhZCQELRo0QLvvfeeS98zPz8fxcXF6Nevn8Pn4+LiapTJmjVr0L59e4SEhKBjx4745ptvMH78eIW1R3zt/Pnz8f7776NFixYIDg5Gr1698Mcffyje78CBAxg/fjyaN2+OkJAQJCQk4L777kNBQYFL30nOd999B47jcODAAenc119/DY7jkJ6ermjbrl07jBkzRjqWx2StWLECt99+OwBg0KBB0u9t6863Y8cO9O7dGyEhIWjevDk++eQTt/ss0qlTJ8TExODUqVPSuSNHjmD06NFo0KABQkJC0LNnT3z33XeK1126dAnTpk1Dp06dEBERgaioKNx44434+++/a/zMqqoq3HzzzahXrx527twJACgpKcGUKVOQkpKC4OBgxMXFYciQIdi3b5/H340gCEJLyJJFEAThZRQVFSE/P19xLiYmxqXXfvrpp7j//vvRu3dvPPjggwCAFi1aAABycnJwzTXXgOM4TJo0CbGxsfjpp58wceJEFBcXY8qUKYr3evnllxEUFIRp06ahqqoKQUFB+OWXX3DjjTeiR48emDlzJnQ6HT7++GNcf/31yMzMRO/evQEABw8exNChQxEbG4uXXnoJJpMJM2fORHx8fI3fIS4uDqGhoVi/fj0mT56MBg0auPTdRX744QeMGTMGnTp1wpw5c3D58mVMnDgRSUlJDtuvWrUKJSUleOihh8BxHObOnYv09HScPHlSckPcvHkzTp48iQkTJiAhIQH//PMP3n//ffzzzz/4/fff3Urm0b9/f3Ach+3bt6Nz584AgMzMTOh0OuzYsUNql5eXhyNHjmDSpEkO3+e6667DY489h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KjIzMwEw17e///4bDz74IGJiYqTzmZmZiI6ORseOHd1+f5H27dtL3wcAYmNj0aZNG8V3q46PPvoIsbGxiIuLQ58+ffDbb79h6tSpmDJlCi5duoRffvkFd9xxB0pKSqTxUFBQgGHDhuHYsWPIysoCwGLJxHg+nudRUFCAiIgItGnTxqH8ioqKMHToUBw5cgTbtm1D165dFc9HR0dj9+7duHDhgoeSIQiCqF3IXZAgCMLL6N27t9PEF56Sl5eHwsJCvP/++3j//fcdtpEnlABgl+Hw2LFjAJjy5YyioiJUVVWhoqICrVq1snu+TZs2+PHHH13q89ixYzF27FgUFxdj9+7dWLFiBVatWoURI0bg0KFDDhNenDlzBgAkdzY5LVu2dLiglyuCACSF6/Lly9K5S5cuYdasWfjyyy/t5FRUVOTS95GTmpqKZcuW4fjx4zhx4gQ4jkPfvn0l5euBBx5AZmYm+vXrpyrZiO13A9j3k3+36hg5ciQmTZoEjuMQGRmJDh06IDw8HABzRRQEAS+++CJefPFFh6/Pzc1FUlISzGYz3nrrLSxduhSnTp0Cz/NSm4YNG9q9bsqUKaisrMRff/3l0K1x7ty5GDduHJKTk9GjRw+kpaXh3nvvRfPmzV36XgRBELUNKVkEQRBXAWazGQBw9913O1WSxPggEbn1Rv4e8+bNs7MsiERERKCqqkplb5VERUVhyJAhGDJkCAIDA7Fy5Urs3r0bAwYM0OT99Xq9w/OCIEiP77jjDuzcuRNPPfUUunbtioiICJjNZgwfPlySizv0798fALB9+3acPHkS3bt3R3h4OFJTU7F48WKUlpbir7/+wquvvurZl7LgynerjsaNG2Pw4MEOnxO/97Rp05xaKEVl97XXXsOLL76I++67Dy+//DIaNGgAnU6HKVOmOJTfyJEj8eWXX+L111/HJ59
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x500 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"indicies = wfdb.processing.find_local_peaks(filtered_data.p_signal[:,sig_channel],radius=3) \n",
|
||
|
"peak_points_y = [filtered_data.p_signal[:,sig_channel][i] for i in indicies] \n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(10, 5))\n",
|
||
|
"plt.plot(filtered_data.p_signal[:,sig_channel])\n",
|
||
|
"plt.scatter(indicies, peak_points_y, color='red', label='Peaks')\n",
|
||
|
"plt.xlabel('Time')\n",
|
||
|
"plt.ylabel('Amplitude')\n",
|
||
|
"plt.title('Filtered Signal with Peaks')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "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9bunbtKvwegLM4dOrUSfLbGiIpKQljx47Ft99+C4CzSA0aNEiwsniLN3L2xMiRIyX
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x500 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
},
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"[]\n"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.figure(figsize=(10, 5))\n",
|
||
|
"plt.plot(filtered_data.p_signal[:,sig_channel])\n",
|
||
|
"plt.xlabel('Time')\n",
|
||
|
"plt.ylabel('Amplitude')\n",
|
||
|
"plt.title('Cut Signal with Minimas Q, S detection')\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"\n",
|
||
|
"for peak in indicies:\n",
|
||
|
" start_idx = 20\n",
|
||
|
" end_idx = 25\n",
|
||
|
" signal_section = filtered_data.p_signal[:,sig_channel][peak-start_idx:peak+end_idx]\n",
|
||
|
" minimas = scipy.signal.argrelextrema(signal_section, comparator=np.less, order=5)\n",
|
||
|
" \n",
|
||
|
" # map the minimas to the original signal\n",
|
||
|
" minimas = minimas[0] + peak - start_idx\n",
|
||
|
" minimas_y = [filtered_data.p_signal[:,sig_channel][i] for i in minimas]\n",
|
||
|
" # if minimas more than 2 take those with biggest difference in y\n",
|
||
|
" if len(minimas) > 2:\n",
|
||
|
" minimas_y = [filtered_data.p_signal[:,sig_channel][i] for i in minimas]\n",
|
||
|
" minimas_y = sorted(minimas_y)\n",
|
||
|
" minimas_y = minimas_y[:2]\n",
|
||
|
" minimas = [minimas[i] for i in range(0,2)]\n",
|
||
|
"\n",
|
||
|
" # plot the minimas\n",
|
||
|
" plt.plot(minimas, minimas_y, 'ro')\n",
|
||
|
"\n",
|
||
|
"plt.legend(['Signal', 'Minimas'])\n",
|
||
|
"plt.show()\n",
|
||
|
"\n",
|
||
|
"#print y values of minimas\n",
|
||
|
"print(minimas_y)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 20,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1kAAAHWCAYAAACFeEMXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAADmmElEQVR4nOydd3gU5fbHv7O76YUQEhJ66L03KaEXjYqIoGAD7AXFG9vlegWxXBQUUS/KT72oF3vhWpEqSAvSRHqvgfQQ0rfO74/ZmZ3ZnU12dmaT2eV8noeH3dnZ3XffvPPOe95zzvcwLMuyIAiCIAiCIAiCIDTBUN8NIAiCIAiCIAiCCCXIyCIIgiAIgiAIgtAQMrIIgiAIgiAIgiA0hIwsgiAIgiAIgiAIDSEjiyAIgiAIgiAIQkPIyCIIgiAIgiAIgtAQMrIIgiAIgiAIgiA0hIwsgiAIgiAIgiAIDSEjiyAIgiAIgiAIQkPIyCIIgriKGDFiBEaMGKHZ53388cdgGAZnz57V7DPVMGPGDKSlpQXks8+ePQuGYfDxxx/7fO7rr78ekLYEihdeeAEMw6CwsDCg35ORkYH7778/oN/hD1OnTsWtt95a380gCCIEICOLIAhCJadOncKDDz6INm3aIDIyEvHx8RgyZAjeeustVFVVKf687du344UXXkBJSYn2jfURi8WCt956C71790Z8fDwSEhLQtWtXPPDAAzh69Gi9tUtvrFq1Ci+88ILmn7tp0yYwDCP8CwsLQ5s2bXD33Xfj9OnTmn9fXbJt2zasXbsWzz77rOT42bNnMXPmTLRt2xaRkZFITU3FsGHDMG/ePAAug762f7yRzRuM/L/o6Gi0bNkSN954Iz766COYzWaPtj377LP47rvv8NdffwW8HwiCCG1M9d0AgiCIYOaXX37BlClTEBERgbvvvhvdunWDxWLB1q1b8fTTT+P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vX84WFBSwly5dYn/55Rc2LS2NZRiG3bVrF1tWVsYmJCSw999/v+S9ubm5bIMGDSTH5frviy++YAGwmzdvFo7NmzePBcAWFBSwR44cYZs2bcr2799f8hv+/PNPFgD7zTff1Pgb5Bg6dCjbt29fj+MHDx5ko6KiWABsr1692NmzZ7Pff/89W1FRUePnxcTESMaUGPFvkePy5cssAPbmm2/2eK1Dhw7sddddV/sPIgiC8AJ5sgiCIPygtLQUABAXF1dn37ly5Uo4HA7ceuutKCwsFP6lpqaiffv22LhxIwBg9+7dyM/Px0MPPYTw8HDh/TNmzECDBg1q/R6GYbBmzRq8/PLLaNiwIb744gs8+uijaNWqFW677bYavRUbNmyAzWbDI488Ijn+2GOPeX3PAw88IAmzS09Ph91ux7lz54RjUVFRwuOysjIUFhYiPT0dlZWVitUOk5OT0alTJ2zevBkAp3ZnNBrx9NNPIy8vDydOnADAebKGDh0qGwLoK7fddhsaNmwo+W0AfFYIvOeee5CcnIymTZvi+uuvR0VFBT755BP069cP69atQ0lJCaZNmyYZD0ajEQMHDhTGAyDtv+rqahQWFuKaa64BAOzdu9fjew8ePIjhw4cjLS0N69evl/wGfgytWbMGlZWVCnoDKCoqknwWT9euXbFv3z7ceeedOHv2LN566y1MnDgRKSkp+OCDDxR9h6/w+VZlZWUerzVs2DDgMvYEQYQ2JHxBEAThB/Hx8QDkF2iB4sSJE2BZFu3bt5d9nVe9440T9/N4GXBfiIiIwHPPPYfnnnsOOTk5+P333/HWW2/h66+/RlhYGD799FPZ9/HfLVaOA4DExETZxTUAtGzZUvKcP+/y5cvCsUOHDuGf//wnfvvtN8HA5aktD0iO9PR0rFq1CgBnTPXr1w/9+vV
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x500 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"# find peaks in the cut signal\n",
|
||
|
"hard = wfdb.processing.find_local_peaks(filtered_data.p_signal[:,sig_channel],radius=3)\n",
|
||
|
"#peak_points_y = [cut_signal[i] for i in hard]\n",
|
||
|
"\n",
|
||
|
"tolerance = 1\n",
|
||
|
"# get standard deviation of the hard peaks\n",
|
||
|
"std = filtered_data.p_signal[:,sig_channel][hard].std() * tolerance\n",
|
||
|
"mean = np.mean(filtered_data.p_signal[:,sig_channel])\n",
|
||
|
"\n",
|
||
|
"#hard = [i for i in hard if abs(filtered_data.p_signal[:,sig_channel][i] - mean) > std]\n",
|
||
|
"# filter peaks with std\n",
|
||
|
"hard = [i for i in hard if filtered_data.p_signal[:,sig_channel][i] > std]\n",
|
||
|
"# get the y values of the peaks\n",
|
||
|
"peak_points_y = [filtered_data.p_signal[:,sig_channel][i] for i in hard]\n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(10, 5))\n",
|
||
|
"plt.plot(filtered_data.p_signal[:,sig_channel])\n",
|
||
|
"plt.plot(hard, peak_points_y, 'ro', label='Peaks')\n",
|
||
|
"plt.xlabel('Time')\n",
|
||
|
"plt.ylabel('Amplitude')\n",
|
||
|
"plt.title('Cuted Signal with Peaks (STD)')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1kAAAHWCAYAAACFeEMXAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjUuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8qNh9FAAAACXBIWXMAAA9hAAAPYQGoP6dpAADhF0lEQVR4nOydd5gT5fbHv5NkewW2F1h6770svdtwxYKFIvaLykW9il4LehUrol6Va/fen4pXRK8F6SAgTUCk975s7zWbMr8/JjOZSSa7mcxkUzif5+EhmZ0kb96888573nPO9zAsy7IgCIIgCIIgCIIgNEHn6wYQBEEQBEEQBEEEE2RkEQRBEARBEARBaAgZWQRBEARBEARBEBpCRhZBEARBEARBEISGkJFFEARBEARBEAShIWRkEQRBEARBEARBaAgZWQRBEARBEARBEBpCRhZBEARBEARBEISGkJFFEARBEARBEAShIWRkEQRBBAjnzp0DwzD47LPPhGPPPfccGIbxXaMUonV75frEl3z22WdgGAbnzp3zyvtnZWVh9uzZbp979dVXe6Ud3mLz5s1gGAYrVqzwdVMIgiBUQUYWQRCEn8Av0OX+PfHEE26/z0svvYTvv//eew1tJn788UeMGjUKSUlJiIyMRLt27XDTTTdh9erVvm6a33DkyBE899xzXjHqxONPp9MhLS0NEydOxObNmzX/LIIgiGDD4OsGEARBEFKef/55tG3bVnKsR48eaNOmDerq6hASEtLo61966SVMnz4d06ZN82Irvcvrr7+Oxx57DKNGjcLChQsRGRmJU6dOYf369Vi+fDkmT54MAG73SbBw/Phx6HT2/dEjR45g0aJFGD16NLKysjT/vAkTJmDmzJlgWRZnz57Fe++9h7Fjx+Lnn3/GlClTNP88giCIYIGMLIIgCD9jypQpGDBggOzfwsPDm7k1HPX19QgNDZUs8L2F2WzGCy+8gAkTJmDt2rVOfy8sLBQeMwzjsz7xBWFhYc36eZ06dcLtt98uPL/++uvRq1cvLF26lIwsgiCIRqBwQYIgiADBnfwjhmFQU1ODzz//XAj1Eufw5Obm4s4770RycjLCwsLQvXt3fPLJJ5L34PNili9fjr///e9IT09HZGQkKisrAQC7du3C5MmTERcXh8jISIwaNQq//fabU1u2bduGgQMHIjw8HO3bt8e//vUvt75ncXExKisrMXz4cNm/JyUlNdkn33zzDbp164bw8HD06NED3333HWbPni3x9vCvff311/HBBx+gffv2CAsLw8CBA/H7779L3u/AgQOYPXs22rVrh/DwcKSkpODOO+9ESUmJW99JzA8//ACGYXDgwAHh2LfffguGYZCTkyM5t2vXrrj55puF5+KcrM8++ww33ngjAGDMmDHC7+0Yzrdt2zYMGjQI4eHhaNeuHf79738rbjNP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kWVZPP3003j66adlX19YWIj09HRYrVa89dZbeO+993D27FlYLBbhnFatWjm9bv78+aivr8cff/whG9b46quvYtasWcjMzET//v0xdepUzJw5E+3atXPrexEEQXgbMrIIgiCuAKxWKwDg9ttvd2kk8flBPGLvjfg9XnvtNSfPAk90dDSMRqPK1kqJjY3FhAkTMGHCBISEhODzzz/Hrl27MGrUKE3eX6/Xyx5nWVZ4fNNNN2H79u147LHH0KdPH0RHR8NqtWLy5MlCvyhhxIgRAIAtW7bgzJkz6NevH6KiopCdnY23334b1dXV+OOPP/Diiy969qVsuPPdGiMjIwPjx4+X/Rv/vR999FGXHkre2H3ppZfw9NNP484778QLL7yAli1bQqfTYf78+bL9d91112H58uV4+eWX8e9//9v
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x500 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"#Find peaks in Channel 6 of Record 25\n",
|
||
|
"hard = wfdb.processing.find_local_peaks(filtered_data.p_signal[:,sig_channel],radius=50)\n",
|
||
|
"record = filtered_data.p_signal[:,sig_channel]\n",
|
||
|
"peak_points_y = [record[i] for i in hard] \n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(10, 5))\n",
|
||
|
"plt.plot(record)\n",
|
||
|
"plt.plot(hard, peak_points_y, 'ro', label='Peaks')\n",
|
||
|
"plt.xlabel('Time')\n",
|
||
|
"plt.ylabel('Amplitude')\n",
|
||
|
"plt.title('Filtered Signal with Peaks')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA1kAAAHWCAYAAACFeEMXAAAAOXRFWHR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IHTGkCFDPApf+EpJSQkqKyvxzjvv4J133pE9RywoAcBN4fDUqVMAOOPLE1VVVTCZTGhoaECXLl3cXu/WrRtWrVrlVZtvu+023HbbbaiursaOHTvw4Ycf4tNPP8X111+Pw4cPywpeXLhwAQCEcDYxnTt3ll3Qiw1BAILBVVFRIRwrLy/H4sWLsWLFCrd+qqqq8ur3iBk9ejSWL1+O06dP48yZM2AYBsOHDxeMr7vvvhtbtmzByJEjVYmNuP42gPt94t/WFDfeeCPmz58PhmEQHx+PXr16ITY2FgAXisiyLB577DE89thjsu8vLi5GVlYW7HY7Xn31Vbz11ls4d+4cbDabcE5KSorb+xYsWIDGxkbs27dPNqzxhRdewJw5c9C2bVvk5uZi+vTpmD17Njp27OjV7yIIgvA3ZGQRBEFcBdjtdgDAHXfc4dFI4vODeMTeG/FnvPjii26eBZ64uDiYTCaVrZWSkJCASZMmYdKkSQgPD8dHH32EHTt2YOzYsZp8vtFolD3Osqzw+JZbbsG2bdvw8MMPo3///oiLi4PdbsfUqVOFflHCqFGjAACbN2/G2bNnMXDgQMTGxmL06NF47bXXUFtbi3379uGZZ57x7Uc58Oa3NUV2djYmTpwo+xr/ux966CGPHkre2H322Wfx2GOP4a677sLTTz+N5ORkGAwGLFiwQLb/brzxRqxYsQLPPfc
|
||
|
"text/plain": [
|
||
|
"<Figure size 1000x500 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"#Find peaks in Channel 6 of Record 25\n",
|
||
|
"hard, soft = wfdb.processing.find_peaks(filtered_data.p_signal[:,sig_channel])\n",
|
||
|
"record = filtered_data.p_signal[:,sig_channel]\n",
|
||
|
"peak_points_y = [record[i] for i in hard] \n",
|
||
|
"\n",
|
||
|
"plt.figure(figsize=(10, 5))\n",
|
||
|
"plt.plot(record)\n",
|
||
|
"plt.plot(hard, peak_points_y, 'ro', label='Peaks')\n",
|
||
|
"plt.xlabel('Time')\n",
|
||
|
"plt.ylabel('Amplitude')\n",
|
||
|
"plt.title('Filtered Signal with Peaks')\n",
|
||
|
"plt.legend()\n",
|
||
|
"plt.grid(True)\n",
|
||
|
"plt.show()"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.10.4"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 2
|
||
|
}
|