[24c4a6]: / 2-Generating Synthetic ECG Data / sample_code_for_simulation.ipynb

Download this file

92 lines (91 with data), 2.2 kB

{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import ecg_simulation_multichannel as s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating normal dataset\n",
      "Creating abnormal dataset\n"
     ]
    }
   ],
   "source": [
    "'''\n",
    "Function Name: simulation\n",
    "Input: \n",
    "        normal_N: the number of normal ECG data;\n",
    "        abnormal_N: the number of abnormal ECG data;\n",
    "        save_params: whether save parameters for each ecg sample, default value is False.\n",
    "Output:\n",
    "        'sim_ecg_data.npy': output file, an array of shape (normal_N + abnormal_N, 12, sampling_rate*duration);\n",
    "        'sim_ecg_labels.npy': file to save labels;\n",
    "        'sim_ecg_params.npy': depend on save_params, file to save parameters for each ecg sample.\n",
    "The saved data is already shuffled.\n",
    "\n",
    "For more parameters' settings, please check 'parameters.py' file.\n",
    "'''\n",
    "normal_N = 3\n",
    "abnormal_N = 3\n",
    "save_params = False\n",
    "s.simulation(normal_N,abnormal_N,save_params)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data shape:  (6, 12, 2500)\n",
      "[0 1 0 0 1 1]\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "data_shape = np.load('sim_ecg_data.npy').shape\n",
    "print('data shape: ',data_shape)\n",
    "labels = np.load('sim_ecg_labels.npy')\n",
    "print(labels)"
   ]
  }
 ],
 "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.8.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}