{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "73c66aef-e868-476b-9323-32e91ad6b55a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import math\n",
    "import scipy.optimize\n",
    "from matplotlib import pyplot as plt\n",
    "%matplotlib widget"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "fe0614f6-12f2-422e-afe2-ac6f2484c4a9",
   "metadata": {},
   "outputs": [],
   "source": [
    "labels = ['PI3HDX12211', '74LVC1G157', 'MAX3748', 'TDP0604']\n",
    "lengths = np.array([1.07, 1.93, 2.86, 3.86])\n",
    "data = np.array([\n",
    "    [16.9, 26.0, 36.4, 46.1],\n",
    "    [17.1, 26.4, 36.6, 48.2],\n",
    "    [17.2, 26.4, 36.6, 45.6],\n",
    "    [17.0, 26.2, 36.5, 45.8]\n",
    "])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "108135c2-2a7f-4a62-b0a8-0b47f0c3255d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "c = 1.898e+08 m/s, Δt = 5.740 ns, corresponds to Δd = 1.09 m\n",
      "c = 1.796e+08 m/s, Δt = 5.009 ns, corresponds to Δd = 0.90 m\n",
      "c = 1.948e+08 m/s, Δt = 6.505 ns, corresponds to Δd = 1.27 m\n",
      "c = 1.923e+08 m/s, Δt = 6.098 ns, corresponds to Δd = 1.17 m\n"
     ]
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "2d86b32f398344d497950abe1bdda2cb",
       "version_major": 2,
       "version_minor": 0
      },
      "image/png": "[encoded data, 13848 characters]",
      "text/html": [
       "\n",
       "            <div style=\"display: inline-block;\">\n",
       "                <div class=\"jupyter-widgets widget-label\" style=\"text-align: center;\">\n",
       "                    Figure\n",
       "                </div>\n",
       "                <img src='data:image/png;base64,[encoded data, 13848 characters]' width=400.0/>\n",
       "            </div>\n",
       "        "
      ],
      "text/plain": [
       "Canvas(toolbar=Toolbar(toolitems=[('Home', 'Reset original view', 'home', 'home'), ('Back', 'Back to previous …"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "fig, ax = plt.subplots(figsize=(4, 2))\n",
    "\n",
    "for series, label in zip(data, labels):\n",
    "    ax.plot(lengths, series, label=label)\n",
    "    f = lambda t, c, t_off: (t - t_off) * c\n",
    "    (c, t_off), p_cov = scipy.optimize.curve_fit(f, series*1e-9, 2*lengths, (3e8/2, 1e-9))\n",
    "    print(f'c = {c:8.4g} m/s, Δt = {t_off*1e9:.3f} ns, corresponds to Δd = {t_off * c:.2f} m')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6f4ad237-3601-47d8-843f-32375ac674c1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.13.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
