Download this file

133 lines (132 with data), 3.7 kB

{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Exercise 2: Interpolation"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "You want to use your (still hypothetical) R wave detection algorithm to output heart rate. You can easily compute heart rate by taking the difference between successive R wave peak times because the R wave corresponds to a heart beat. The heart rate is then just the reciprocal of the inter-beat-interval time. \n",
    "\n",
    "You find a dataset that has an ECG signal and a reference heart rate datastream. After running your algorithm on the dataset, you have a series of R wave peak times. The heart rates that you get from the inter-beat-interval times will be non-uniformly sequenced because the heart beats at non-uniform intervals. The reference heart rate is uniformly sampled, however. To compare these two datastreams you will need to interpolate your heart rate onto the reference stream first.\n",
    "\n",
    "The data you need is stored in the `npz` file as follows:  \n",
    " - `est_r_peaks` - the timestamps in seconds of the r peaks detected by your algorithm\n",
    " - `ref_ts` - the timestamps in seconds of the reference heart rate\n",
    " - `ref_hr` - the reference heart rate values in beats per minute\n",
    "\n",
    "You must first derive heart rate from your sequence of R peaks. Then interpolate your estimate heart rate stream to match up with the reference stream. Finally, compute the mean absolute error between the reference stream your estimate heart rate. The mean absolute error is the average absolute difference between each estimate heart rate and its reference value."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Load Data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "npz = np.load(\"./exercise2.npz\")\n",
    "est_r_peaks = npz['est_r_peaks']\n",
    "ref_ts = npz['ref_ts']\n",
    "ref_hr = npz['ref_hr']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Estimate heart rate"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Your Code Goes Here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Interpolate\n",
    "Interpolate the heart rate estimates to align with the reference."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Your Code Goes Here"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Compute MAE"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "## Your Code Goes Here"
   ]
  }
 ],
 "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.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}