{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8322be9c-01b2-4b9e-b70f-e4cf253c377f",
   "metadata": {},
   "source": [
    "# Determination of CS input stage's $g_m$ and $c_{iss}$"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "id": "7d8772e5-dde6-4545-b2be-744702191511",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Compiling library: SLiCAP.lib.\n",
      "Compiling library: SLiCAPmodels.lib.\n"
     ]
    }
   ],
   "source": [
    "import SLiCAP as sl\n",
    "import sympy as sp\n",
    "import numpy as np\n",
    "from scipy.optimize import fsolve\n",
    "from scipy.integrate import quad\n",
    "%store -r DIN_A\n",
    "sl.initProject(\"g_m C_iss\", notebook=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a9afb28-b153-4116-b6cb-495014674b24",
   "metadata": {},
   "source": [
    "## Specifications"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "id": "b8b1035d-b04f-43bb-b8c9-3ef93a10a2ce",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h3>design specification</h3>\n",
       "<table><a id=\"table_design\"></a><caption>Table design specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$C_{i}$</td><td class=\"left\">Required value of integrator capacitor</td><td class=\"left\">$1.798 \\cdot 10^{-9}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$I_{fb}$</td><td class=\"left\">Maximum peak-peak current through feedback network</td><td class=\"left\">$4.542 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{A}$</td></tr>\n",
       "<td class=\"left\">$R_{i}$</td><td class=\"left\">Selected value of integrator resistor</td><td class=\"left\">$8900$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$Ri_{max}$</td><td class=\"left\">Max. value of integrator resistor</td><td class=\"left\">$8945.0$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$Ri_{min}$</td><td class=\"left\">Min. value of integrator resistor</td><td class=\"left\">$3380$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$SRCnoise$</td><td class=\"left\">DIN A weighted RMS output noise, source + termination</td><td class=\"left\">$1.571 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$S_{Ri}$</td><td class=\"left\">Squared DIN A weighted RMS output noise due to source and feedback network</td><td class=\"left\">$2.491 \\cdot 10^{-11}$</td><td class=\"left\">$\\mathrm{\\frac{V^{2}}{Hz}}$</td></tr>\n",
       "<td class=\"left\">$c_{issN}$</td><td class=\"left\">Selected input capacitance NMOS</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss costs minN}$</td><td class=\"left\">Required c_iss NMOS for minimum costs</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss g m minN}$</td><td class=\"left\">Required c_issN at g_m_minN</td><td class=\"left\">$9.87 \\cdot 10^{-10}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$g_{mN}$</td><td class=\"left\">Selected transconductance input stage NMOS</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m costs minN}$</td><td class=\"left\">g_m NMOS for minimum costs</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m minN}$</td><td class=\"left\">Minimum transconductance input stage NMOS</td><td class=\"left\">$3.926 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$n_{Ri obtained}$</td><td class=\"left\">Relative contribution of source and feedback network to squared DIN A weighted output noise</td><td class=\"left\">$0.199$</td><td></td></tr>\n",
       "</table>\n",
       "<h3>performance specification</h3>\n",
       "<table><a id=\"table_performance\"></a><caption>Table performance specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$L_{s}$</td><td class=\"left\">Source inductance</td><td class=\"left\">$0.12$</td><td class=\"left\">$\\mathrm{H}$</td></tr>\n",
       "<td class=\"left\">$P_{max}$</td><td class=\"left\">Maximum power dissipation at maximum supply voltage</td><td class=\"left\">$0.001$</td><td class=\"left\">$\\mathrm{W}$</td></tr>\n",
       "<td class=\"left\">$R_{s}$</td><td class=\"left\">Source resistance</td><td class=\"left\">$875$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$R_{t}$</td><td class=\"left\">Termination resistance</td><td class=\"left\">$1.0 \\cdot 10^{4}$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$V_{DD}$</td><td class=\"left\">Maximum supply voltage</td><td class=\"left\">$1.3$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$V_{onoise}$</td><td class=\"left\">DIN A weighted output voltage noise</td><td class=\"left\">$1.062 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$Vi_{ADC}$</td><td class=\"left\">Peak-peak input voltage ADC</td><td class=\"left\">$0.9$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$Vi_{pp}$</td><td class=\"left\">Maximum peak-peak input voltage</td><td class=\"left\">$0.2932$</td><td></td></tr>\n",
       "<td class=\"left\">$f_{fp}$</td><td class=\"left\">Maximum full-power frequency</td><td class=\"left\">$5000$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$f_{max}$</td><td class=\"left\">-3dB low-pass cut-off frequency</td><td class=\"left\">$6000$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$f_{min}$</td><td class=\"left\">-3dB high-pass cut-off frequency</td><td class=\"left\">$600$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$\\tau_{i}$</td><td class=\"left\">Integration time constant</td><td class=\"left\">$1.6 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{s}$</td></tr>\n",
       "</table>\n",
       "<h3>achievements specification</h3>\n",
       "<table><a id=\"table_achievements\"></a><caption>Table achievements specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$V_{onoise gmCissN}$</td><td class=\"left\">DIN A weighted RMS output noise with NMOS and selected g_m and c_iss</td><td class=\"left\">$9.021 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "</table>\n",
       "<h3>budgets specification</h3>\n",
       "<table><a id=\"table_budgets\"></a><caption>Table budgets specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$n_{MN}$</td><td class=\"left\">Relative contribution controller NMOS input stagenoise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.5$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{Ri}$</td><td class=\"left\">Relative contribution of R_i noise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.2$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{SRC}$</td><td class=\"left\">Relative contribution of source noise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.02189$</td><td></td></tr>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "specs = sl.csv2specs('A1specs.csv')\n",
    "sl.specs2html(specs)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2a5862e9-26dc-44a1-82a2-c48c548e8af5",
   "metadata": {},
   "source": [
    "## Circuit model"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "9cc60ddf-2212-40c7-8d02-8acff1c2cbed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating netlist of kicad/noise_ciss_gm/noise_ciss_gm.kicad_sch using KiCAD\n",
      "Creating drawing-size SVG and PDF images of kicad/noise_ciss_gm/noise_ciss_gm.kicad_sch\n",
      "Plotted to '/home/anton/DATA/www/SEDwebsite/_build/SEDwebsite/EE4109-2024-2025/designExample/HearingLoop/SLiCAP/img/noise_ciss_gm.svg'.\n",
      "Done\n",
      "Checking netlist: cir/noise_ciss_gm.cir\n",
      "Warning less than two connections at node: 'out'.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<figure><img src=\"img/noise_ciss_gm.svg\" alt=\"\" style=\"width:700px\">\n",
       "</figure>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cir = sl.makeCircuit(\"kicad/noise_ciss_gm/noise_ciss_gm.kicad_sch\")\n",
    "sl.specs2circuit(specs, cir)\n",
    "f_min   = cir.getParValue('f_min')\n",
    "f_max   = cir.getParValue('f_max')\n",
    "V_noise = cir.getParValue('V_onoise')\n",
    "n_SRC   = cir.getParValue('n_SRC')\n",
    "n_Ri    = cir.getParValue('n_Ri')\n",
    "sl.img2html('noise_ciss_gm.svg', 700)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7b8c0158-139a-4605-9799-5ad28a1f33d4",
   "metadata": {},
   "source": [
    "## Selection of input stage type MOS type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "id": "84a76b21-f67e-437d-b930-aefbb71c5907",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "Please select N or P type input CS stage:\n",
      ">>>  P\n"
     ]
    }
   ],
   "source": [
    "# Input NMOS or PMOS CS input stage\n",
    "mosType = False\n",
    "while not mosType:\n",
    "    mosType = input(\"Please select N or P type input CS stage:\\n>>> \").upper()\n",
    "    if mosType != \"N\" and mosType != \"P\":\n",
    "        mosType = False\n",
    "if mosType == \"N\":\n",
    "    cir.defPar(\"n\", \"N_s_N18\")\n",
    "    cir.defPar(\"C_OX\", \"C_OX_N18\")\n",
    "    cir.defPar(\"KF\", \"KF_N18\")\n",
    "    cir.defPar(\"AF\", \"AF_N18\")\n",
    "    fT_peak = 50e9\n",
    "elif mosType == \"P\":\n",
    "    cir.defPar(\"n\", \"N_s_P18\")\n",
    "    cir.defPar(\"C_OX\", \"C_OX_P18\")\n",
    "    cir.defPar(\"KF\", \"KF_P18\")\n",
    "    cir.defPar(\"AF\", \"AF_P18\")\n",
    "    fT_peak = 10e9"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73a96782-a832-459f-96c0-54c56de88c82",
   "metadata": {},
   "source": [
    "## Budgeting of input stage noise contribution"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "id": "6b91e0eb-ef75-47df-a208-36d09bfd428e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdin",
     "output_type": "stream",
     "text": [
      "\n",
      "Assign a relative budget for the contribution of the noise of the controller PMOS input stage to the squared DIN-A weighted RMS output noise (> 0 and < 0.778):\n",
      ">>>  0.5\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "N_{required}=8.138 \\cdot 10^{-11}\\,\\left[ \\mathrm{V^{2}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "n_M = 0\n",
    "while n_M > 1-n_SRC - n_Ri or n_M <= 0:\n",
    "    try:\n",
    "        n_M = float(input(\"\\nAssign a relative budget for the contribution \" +\n",
    "                          \"of the noise of the controller %sMOS input \"%(mosType) +\n",
    "                          \"stage to the squared DIN-A weighted RMS output \" +\n",
    "                          \"noise (> 0 and < %s):\\n>>> \"%(sp.N(1 - n_SRC - n_Ri , 3))))\n",
    "    except ValueError:\n",
    "        n_M=0\n",
    "N_required  = V_noise**2 * (n_M + n_SRC + n_Ri)\n",
    "sl.eqn2html(\"N_required\", N_required, units=\"V^2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9ad7a912-828a-4537-8492-196df2101b59",
   "metadata": {},
   "source": [
    "## Calculation of the unweighted output noise spectrum and variance"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "7cde7ae8-1f73-496a-817f-511e738971b5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning less than two connections at node: 'out'.\n",
      "Warning less than two connections at node: 'out'.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "S_{onoise}=\\frac{6.474 \\cdot 10^{-7} f^{2} + 0.8718}{f^{2} \\left(39.48 f^{2} + 8.213 \\cdot 10^{9}\\right)} + \\frac{1.459 \\cdot 10^{-8}}{f^{2}} + \\frac{9.961}{f^{2} \\left(39.48 f^{2} + 8.213 \\cdot 10^{9}\\right)} + \\frac{0.8211 c_{iss}^{2} f^{4} + 4.504 \\cdot 10^{7} c_{iss}^{2} f^{2} - 0.09706 c_{iss} f^{2} + 5.823 \\cdot 10^{-11} f^{2} + 0.01212}{f^{2} g_{m} \\left(39.48 f^{2} + 8.213 \\cdot 10^{9}\\right)} + \\frac{2.853 \\cdot 10^{-18}}{c_{iss} f^{3.25}}\\,\\left[ \\mathrm{\\frac{V^{2}}{Hz}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "noiseResult = sl.doNoise(cir, pardefs=\"circuit\")\n",
    "S_onoise    = noiseResult.onoise\n",
    "sl.eqn2html(\"S_onoise\", sp.N(S_onoise, 4), units=\"V^2/Hz\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b2cd9387-d53a-4f0c-b371-8ba3ce0b53b6",
   "metadata": {},
   "source": [
    "The variance of the output voltage is obtained after integration over the frequency range of interest. It is a function of $g_m$ and $c_{iss}$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "id": "110d91aa-69f0-425b-9d20-516de7cd83c2",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "N_{obtained}=\\frac{112.4 c_{iss}^{2}}{g_{m}} - \\frac{2.004 \\cdot 10^{-8} c_{iss} \\left(3.888 \\cdot 10^{9} c_{iss} + 3.0\\right)}{g_{m}} + 2.423 \\cdot 10^{-11} + \\frac{2.213 \\cdot 10^{-15}}{g_{m}} + \\frac{7.076 \\cdot 10^{-25}}{c_{iss}}\\,\\left[ \\mathrm{V^{2}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "onoiseVar   = sl.rmsNoise(noiseResult, 'onoise', f_min, f_max)**2\n",
    "sl.eqn2html(\"N_obtained\", sp.N(onoiseVar, 4), units=\"V^2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5e345d3d-f039-4aba-9d3a-01a66f52ffc1",
   "metadata": {},
   "source": [
    "## Determination of show-stopper values\n",
    "Expressing $N_{obtained}$ in the process cut-off frequency $f_T$, shows that the lowest noie is obtaine at the peak $f_T$ of the process:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "71aa1f78-d406-4686-a57d-6afa2fdf460a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "N_{obtained}=\\frac{17.88 c_{iss}}{f_{T}} + 2.423 \\cdot 10^{-11} - \\frac{12.4 c_{iss} + 9.567 \\cdot 10^{-9}}{f_{T}} + \\frac{7.076 \\cdot 10^{-25}}{c_{iss}} + \\frac{3.522 \\cdot 10^{-16}}{c_{iss} f_{T}}\\,\\left[ \\mathrm{V^{2}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "g_m   = sp.Symbol(\"g_m\")\n",
    "c_iss = sp.Symbol(\"c_iss\")\n",
    "f_T   = sp.Symbol(\"f_T\")\n",
    "onoiseVar_fT = onoiseVar.subs(g_m, 2*sp.pi*f_T*c_iss)\n",
    "sl.eqn2html(\"N_obtained\", sp.N(onoiseVar_fT, 4), units=\"V^2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "137d7deb-bbd2-4788-910a-626de4e8b513",
   "metadata": {},
   "source": [
    "For the selected MOS type we have:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "id": "d1aa0687-cd40-4be2-baac-992a69e05970",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "f_{Tmax}=1.0 \\cdot 10^{10}\\,\\left[ \\mathrm{Hz}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sl.eqn2html(\"f_Tmax\", fT_peak, units=\"Hz\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "73d9d8c8-1a80-4a19-883e-59dd630fa9eb",
   "metadata": {},
   "source": [
    "With this value we obtain:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "id": "542efe5e-da64-4e20-937e-dc6fe1f29d27",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "N_{obtained}=5.48 \\cdot 10^{-10} c_{iss} + 2.423 \\cdot 10^{-11} + \\frac{7.428 \\cdot 10^{-25}}{c_{iss}}\\,\\left[ \\mathrm{V^{2}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "onoiseVar_fTpeak = onoiseVar_fT.subs(f_T, fT_peak)\n",
    "sl.eqn2html(\"N_obtained\", sp.N(onoiseVar_fTpeak, 4), units=\"V^2\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c81d678d-7801-47ef-b332-b67e7c9c6aeb",
   "metadata": {},
   "source": [
    "This expression has a minimum for:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "id": "9a33a17d-3dcc-4354-9a5a-0d694389c592",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "c_{iss Opt}=3.682 \\cdot 10^{-8}\\,\\left[ \\mathrm{F}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c_iss_best = float(sp.solve(sp.diff(onoiseVar_fTpeak, c_iss))[1])\n",
    "sl.eqn2html(\"c_iss_Opt\", sp.N(c_iss_best, 4), units=\"F\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "991a9d5b-1e12-4575-a93d-0cf044fd4f7a",
   "metadata": {},
   "source": [
    "Hence the minimum unweighted noise that can be achieved is:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "e4cfdd42-0b65-48a7-b5dd-4b53b4c10cff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "Vn_{min}=4.923 \\cdot 10^{-6}\\,\\left[ \\mathrm{V}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "onoiseRMS_min = sp.sqrt(onoiseVar_fTpeak.subs(c_iss, c_iss_best))\n",
    "sl.eqn2html(\"Vn_min\", sp.N(onoiseRMS_min, 4), units=\"V\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57d52a1a-78c6-4aa6-915a-a98bd3833f3f",
   "metadata": {},
   "source": [
    "## Calculation of optimum values\n",
    "Valid combinations of $g_m$ and $c_{iss}$ for which $N_{obtained}=N_{required}$ are found from solving $g_m$ from\n",
    "$N_{obtained}-N_{required}=0$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "id": "691850d3-e002-407f-b251-c97f56984ff1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "gm_{ciss}=\\frac{3.787 \\cdot 10^{26} c_{iss} \\left(1.218 \\cdot 10^{19} c_{iss}^{2} - 2.127 \\cdot 10^{10} c_{iss} + 783.0\\right)}{7.657 \\cdot 10^{33} c_{iss} - 9.48 \\cdot 10^{19}}\\,\\left[ \\mathrm{\\mathtt{\\text{S}}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "onoiseVar = sl.assumePosParams(onoiseVar)\n",
    "g_m       = sp.Symbol('g_m', positive = True)\n",
    "gm_ciss   = sp.solve(onoiseVar - N_required, g_m)[0]\n",
    "sl.eqn2html(\"gm_ciss\", sp.N(gm_ciss, 4), units=\"S\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f000b2e6-dd75-41f0-bb34-3a97e33308ca",
   "metadata": {},
   "source": [
    "The denominator of this expression must be positive. This yields a minimum value for $c_{iss}$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "b023fddd-0ae3-4db9-8341-18696c21e5fd",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "c_{issMin}=1.238 \\cdot 10^{-14}\\,\\left[ \\mathrm{F}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "num, den     = gm_ciss.as_numer_denom()\n",
    "ciss_min     = float(sp.solve(den)[0])\n",
    "sl.eqn2html(\"c_issMin\", sp.N(ciss_min, 4), units=\"F\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "92bcc438-3040-4075-80f8-51ce53c059be",
   "metadata": {},
   "source": [
    "The optimum value for the lowest $g_m$ == lowest current consumption is found at a much larger value of $c_{iss}$. This can be seen from the plot!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "id": "6ec45cec-8e05-489d-a3e6-bec9c8c86a1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 37704 characters]",
      "text/plain": [
       "<Figure size 400x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "<SLiCAP.SLiCAPplots.figure at 0x7a6ef47e7800>"
      ]
     },
     "execution_count": 84,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gm_ciss_func = sp.lambdify(sp.Symbol(\"c_iss\"), gm_ciss)\n",
    "ciss_num     = np.geomspace(ciss_min * 1.1, c_iss_best/10, 500)\n",
    "gm_func_ciss = gm_ciss_func(ciss_num)\n",
    "trc          = sl.trace([ciss_num, gm_func_ciss])\n",
    "trc.label    = \"gm_ciss\"\n",
    "sl.plot(\"gm_ciss\", \"Required $g_m$ versus $c_{iss}$\", \"log\", {\"gm_ciss\": trc}, show=True, xScale=\"p\", xUnits=\"F\", yUnits=\"S\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9970ebc3-c8c6-4ec3-915d-21a6f9c1b922",
   "metadata": {},
   "source": [
    "The minimum value of $g_m$ is found from solving the derivative of gm_ciss for $c_{iss} > c_{issMin}$. We will determine the derivative symbolically and solve it for $c_{iss}$ numerically:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "66ae4043-8cf2-40b6-9571-13257dccdbfc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "g_{mMin}=3.827 \\cdot 10^{-5}\\,\\left[ \\mathrm{\\mathtt{\\text{S}}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c_iss                = sp.Symbol('c_iss', positive = True)\n",
    "diff_gm_ciss         = sp.diff(gm_ciss, c_iss)\n",
    "func_diff_gm_ciss    = sp.lambdify(c_iss, diff_gm_ciss)\n",
    "ciss_gm_min          = fsolve(func_diff_gm_ciss, float(ciss_min) + 1e-15)[0]\n",
    "gm_min               = gm_ciss.subs(c_iss, ciss_gm_min)\n",
    "sl.eqn2html(\"g_mMin\", sp.N(gm_min, 4), units=\"S\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "765ff1ca-efb0-4f68-be5e-03448fcb1279",
   "metadata": {},
   "source": [
    "## Solution for minimum costs\n",
    "The product of $c_{iss}$ and $g_m$ can be taken as a measure for the costs: the product of the current consumtion and the area. We obtain minimum cost when $c_{iss}=c_{issMinCosts}$ satisfies $\\frac{d\\,g_m c_{iss}}{d\\,c_{iss}} = 0$. The corresponsing value of $g_{mMinCosts}$ is obtained after substitution of $c_{issMinCosts}$ in $gm_{ciss}$:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "id": "5f2fec83-6270-4a84-9259-1d0904e77115",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "c_{issMinCosts}=2.476 \\cdot 10^{-14}\\,\\left[ \\mathrm{F}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "costs                = gm_ciss * c_iss\n",
    "diff_costs_ciss      = sp.diff(costs, c_iss)\n",
    "func_diff_costs_ciss = sp.lambdify(c_iss, diff_costs_ciss)\n",
    "ciss_costs_min       = fsolve(func_diff_costs_ciss, float(ciss_min) + 1e-15)[0]\n",
    "gm_costs_min         = gm_ciss.subs(c_iss, ciss_costs_min)\n",
    "sl.eqn2html(\"c_issMinCosts\", sp.N(ciss_costs_min, 4), units=\"F\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "9d5401d8-acef-4a77-b4a8-733e5a83bff3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "g_{mMinCosts}=7.745 \\cdot 10^{-5}\\,\\left[ \\mathrm{\\mathtt{\\text{S}}}\\right]\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sl.eqn2html(\"g_mMinCosts\", sp.N(gm_costs_min, 4), units=\"S\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d792605a-e695-4aaa-85bb-c3a8dd06400c",
   "metadata": {},
   "source": [
    "## Calculation of the weighted variance at minimum costs\n",
    "After substitution of the optimum cost values for $c_{iss}$ and $g_m$, in the expression for the output noise voltage spectrum ([11]), we hsve the output variance \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 88,
   "id": "64da7e48-cb55-46e5-9415-103f4dd9fd0b",
   "metadata": {},
   "outputs": [],
   "source": [
    "S_onoise     = sl.assumePosParams(S_onoise)\n",
    "S_weighted   = S_onoise.subs({c_iss: ciss_costs_min, g_m: gm_costs_min}) * DIN_A**2\n",
    "S_weighted_f = sp.lambdify(sl.ini.frequency, S_weighted)\n",
    "N_weighted   = quad(S_weighted_f, f_min, f_max)[0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f2456bc3-d9f0-4097-92e1-c91257501c99",
   "metadata": {},
   "source": [
    "## Correction for DIN-A weighting\n",
    "We will adjust the requirement and re-run the above instructions until the DIN-A weighted noise equals the initial requirement."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 89,
   "id": "c840c3b4-9c1b-4dc6-886f-f072ff425fa9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\\begin{equation}\n",
       "correction=1.019\n",
       "\\end{equation}\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 89,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "correction = N_required/N_weighted\n",
    "sl.eqn2html(\"correction\", sp.N(correction, 4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 90,
   "id": "7e11b41c-6ecd-49bf-b1a6-2ffc86c73004",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.00038455584976\n"
     ]
    }
   ],
   "source": [
    "N_corrected = correction * N_required\n",
    "while np.abs(1 - correction) > 0.001:\n",
    "    gm_ciss              = sp.solve(onoiseVar - N_corrected, g_m)[0]\n",
    "    costs                = gm_ciss * c_iss\n",
    "    diff_costs_ciss      = sp.diff(costs, c_iss)\n",
    "    func_diff_costs_ciss = sp.lambdify(c_iss, diff_costs_ciss)\n",
    "    ciss_costs_min       = fsolve(func_diff_costs_ciss, float(ciss_min) + 1e-15)[0]\n",
    "    gm_costs_min         = gm_ciss.subs(c_iss, ciss_costs_min)\n",
    "    S_weighted           = S_onoise.subs({c_iss: ciss_costs_min, g_m: gm_costs_min}) * DIN_A**2\n",
    "    S_weighted_f         = sp.lambdify(sl.ini.frequency, S_weighted)\n",
    "    N_weighted           = quad(S_weighted_f, f_min, f_max)[0]\n",
    "    correction           = N_required/N_weighted\n",
    "    N_corrected          = correction * N_required\n",
    "    print(correction)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1818a1b6-9c02-4084-b9a2-f12261fc8c64",
   "metadata": {},
   "source": [
    "## Summary of results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 91,
   "id": "ef355a37-d6af-4aeb-ab7c-7399ae51a740",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      "PMOS design results:\n",
      "--------------------\n",
      "RMS DIN A weighted required : 9.021e-6 V\n",
      "RMS DIN A weighted obtained : 9.020e-6 V\n",
      "DIN A RMS correction factor : 1.000\n",
      "Selected value of c_iss MOS : 2.410e-14 F\n",
      "Required value of g_m MOS   : 7.537e-5 S\n"
     ]
    }
   ],
   "source": [
    "print(\"\\n%sMOS design results:\\n--------------------\"%(mosType))\n",
    "print(\"RMS DIN A weighted required :\", sp.N(sp.sqrt(N_required), 4), 'V')\n",
    "print(\"RMS DIN A weighted obtained :\", sp.N(sp.sqrt(N_weighted), 4), 'V')\n",
    "print(\"DIN A RMS correction factor :\", sp.N(correction, 4))\n",
    "print(\"Selected value of c_iss MOS :\", sp.N(ciss_costs_min, 4), 'F')\n",
    "print(\"Required value of g_m MOS   :\", sp.N(gm_costs_min, 4), 'S')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a13159b-331a-47ef-96c1-444dfa757f81",
   "metadata": {},
   "source": [
    "## Update specifications"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 92,
   "id": "2738f8c8-3228-4df1-9b81-c42b1549c829",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<h3>design specification</h3>\n",
       "<table><a id=\"table_design\"></a><caption>Table design specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$C_{i}$</td><td class=\"left\">Required value of integrator capacitor</td><td class=\"left\">$1.798 \\cdot 10^{-9}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$I_{fb}$</td><td class=\"left\">Maximum peak-peak current through feedback network</td><td class=\"left\">$4.542 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{A}$</td></tr>\n",
       "<td class=\"left\">$R_{i}$</td><td class=\"left\">Selected value of integrator resistor</td><td class=\"left\">$8900$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$Ri_{max}$</td><td class=\"left\">Max. value of integrator resistor</td><td class=\"left\">$8945.0$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$Ri_{min}$</td><td class=\"left\">Min. value of integrator resistor</td><td class=\"left\">$3380$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$SRCnoise$</td><td class=\"left\">DIN A weighted RMS output noise, source + termination</td><td class=\"left\">$1.571 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$S_{Ri}$</td><td class=\"left\">Squared DIN A weighted RMS output noise due to source and feedback network</td><td class=\"left\">$2.491 \\cdot 10^{-11}$</td><td class=\"left\">$\\mathrm{\\frac{V^{2}}{Hz}}$</td></tr>\n",
       "<td class=\"left\">$c_{issN}$</td><td class=\"left\">Selected input capacitance NMOS</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{issP}$</td><td class=\"left\">Selected input capacitance PMOS</td><td class=\"left\">$2.41 \\cdot 10^{-14}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss costs minN}$</td><td class=\"left\">Required c_iss NMOS for minimum costs</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss costs minP}$</td><td class=\"left\">Required c_iss PMOS for minimum costs</td><td class=\"left\">$2.41 \\cdot 10^{-14}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss g m minN}$</td><td class=\"left\">Required c_issN at g_m_minN</td><td class=\"left\">$9.87 \\cdot 10^{-10}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$c_{iss g m minP}$</td><td class=\"left\">Required c_issN at g_m_minP</td><td class=\"left\">$8.736 \\cdot 10^{-10}$</td><td class=\"left\">$\\mathrm{F}$</td></tr>\n",
       "<td class=\"left\">$g_{mN}$</td><td class=\"left\">Selected transconductance input stage NMOS</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{mP}$</td><td class=\"left\">Selected transconductance input stage PMOS</td><td class=\"left\">$7.537 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m costs minN}$</td><td class=\"left\">g_m NMOS for minimum costs</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m costs minP}$</td><td class=\"left\">g_m PMOS for minimum costs</td><td class=\"left\">$7.537 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m minN}$</td><td class=\"left\">Minimum transconductance input stage NMOS</td><td class=\"left\">$3.926 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$g_{m minP}$</td><td class=\"left\">Minimum transconductance input stage PMOS</td><td class=\"left\">$3.827 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{\\mathtt{\\text{S}}}$</td></tr>\n",
       "<td class=\"left\">$n_{Ri obtained}$</td><td class=\"left\">Relative contribution of source and feedback network to squared DIN A weighted output noise</td><td class=\"left\">$0.199$</td><td></td></tr>\n",
       "</table>\n",
       "<h3>performance specification</h3>\n",
       "<table><a id=\"table_performance\"></a><caption>Table performance specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$L_{s}$</td><td class=\"left\">Source inductance</td><td class=\"left\">$0.12$</td><td class=\"left\">$\\mathrm{H}$</td></tr>\n",
       "<td class=\"left\">$P_{max}$</td><td class=\"left\">Maximum power dissipation at maximum supply voltage</td><td class=\"left\">$0.001$</td><td class=\"left\">$\\mathrm{W}$</td></tr>\n",
       "<td class=\"left\">$R_{s}$</td><td class=\"left\">Source resistance</td><td class=\"left\">$875$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$R_{t}$</td><td class=\"left\">Termination resistance</td><td class=\"left\">$1.0 \\cdot 10^{4}$</td><td class=\"left\">$\\mathrm{\\Omega}$</td></tr>\n",
       "<td class=\"left\">$V_{DD}$</td><td class=\"left\">Maximum supply voltage</td><td class=\"left\">$1.3$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$V_{onoise}$</td><td class=\"left\">DIN A weighted output voltage noise</td><td class=\"left\">$1.062 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$Vi_{ADC}$</td><td class=\"left\">Peak-peak input voltage ADC</td><td class=\"left\">$0.9$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$Vi_{pp}$</td><td class=\"left\">Maximum peak-peak input voltage</td><td class=\"left\">$0.2932$</td><td></td></tr>\n",
       "<td class=\"left\">$f_{fp}$</td><td class=\"left\">Maximum full-power frequency</td><td class=\"left\">$5000$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$f_{max}$</td><td class=\"left\">-3dB low-pass cut-off frequency</td><td class=\"left\">$6000$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$f_{min}$</td><td class=\"left\">-3dB high-pass cut-off frequency</td><td class=\"left\">$600$</td><td class=\"left\">$\\mathrm{Hz}$</td></tr>\n",
       "<td class=\"left\">$\\tau_{i}$</td><td class=\"left\">Integration time constant</td><td class=\"left\">$1.6 \\cdot 10^{-5}$</td><td class=\"left\">$\\mathrm{s}$</td></tr>\n",
       "</table>\n",
       "<h3>achievements specification</h3>\n",
       "<table><a id=\"table_achievements\"></a><caption>Table achievements specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$V_{onoise gmCissN}$</td><td class=\"left\">DIN A weighted RMS output noise with NMOS and selected g_m and c_iss</td><td class=\"left\">$9.021 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "<td class=\"left\">$V_{onoise gmCissP}$</td><td class=\"left\">DIN A weighted RMS output noise with PMOS and selected g_m and c_iss</td><td class=\"left\">$9.02 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></tr>\n",
       "</table>\n",
       "<h3>budgets specification</h3>\n",
       "<table><a id=\"table_budgets\"></a><caption>Table budgets specification </caption><tr><th class=\"left\">symbol</th><th class=\"left\">description</th><th class=\"left\">value</th><th class=\"left\">units</th></tr>\n",
       "<td class=\"left\">$n_{MN}$</td><td class=\"left\">Relative contribution controller NMOS input stagenoise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.5$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{MP}$</td><td class=\"left\">Relative contribution controller PMOS input stagenoise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.5$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{Ri}$</td><td class=\"left\">Relative contribution of R_i noise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.2$</td><td></td></tr>\n",
       "<td class=\"left\">$n_{SRC}$</td><td class=\"left\">Relative contribution of source noise to the squared DIN-A weighted RMS output noise</td><td class=\"left\">$0.02189$</td><td></td></tr>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 92,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "specs.append(\n",
    "        sl.specItem('n_M%s'%(mosType),\n",
    "        description = 'Relative contribution controller %sMOS input stage'%(mosType)  +\n",
    "        'noise to the squared DIN-A weighted RMS output noise',\n",
    "        value       = n_M,\n",
    "        units       = \"\",\n",
    "        specType    = \"budgets\")\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('c_iss%s'%(mosType),\n",
    "        description = \"Selected input capacitance %sMOS\"%(mosType),\n",
    "        value       = ciss_costs_min,\n",
    "        units       = \"F\",\n",
    "        specType    = \"design\",\n",
    "        )\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('g_m%s'%(mosType),\n",
    "        description = \"Selected transconductance input stage %sMOS\"%(mosType),\n",
    "        value       = gm_costs_min,\n",
    "        units       = \"S\",\n",
    "        specType    = \"design\",\n",
    "        )\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('g_m_min%s'%(mosType),\n",
    "        description = \"Minimum transconductance input stage %sMOS\"%(mosType),\n",
    "        value       = gm_min,\n",
    "        units       = \"S\",\n",
    "        specType    = \"design\",\n",
    "        )\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('c_iss_g_m_min%s'%(mosType),\n",
    "        description = \"Required c_issN at g_m_min%s\"%(mosType),\n",
    "        value       = ciss_gm_min,\n",
    "        units       = \"F\",\n",
    "        specType    = \"design\",\n",
    "        )\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('c_iss_costs_min%s'%(mosType),\n",
    "        description = \"Required c_iss %sMOS for minimum costs\"%(mosType),\n",
    "        value       = ciss_costs_min,\n",
    "        units       = \"F\",\n",
    "        specType    = \"design\",\n",
    "        )\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('g_m_costs_min%s'%(mosType),\n",
    "        description = \"g_m %sMOS for minimum costs\"%(mosType),\n",
    "        value       = gm_costs_min,\n",
    "        units       = \"S\",\n",
    "        specType    = \"design\",\n",
    "        )\n",
    ")\n",
    "\n",
    "specs.append(\n",
    "        sl.specItem('V_onoise_gmCiss%s'%(mosType),\n",
    "        description = \"DIN A weighted RMS output noise with %sMOS and selected g_m and c_iss\"%(mosType),\n",
    "        value       = sp.sqrt(N_weighted),\n",
    "        units       = \"V\",\n",
    "        specType    = \"achievements\",\n",
    "        )\n",
    ")\n",
    "sl.specs2csv(specs, 'A1specs.csv')\n",
    "sl.specs2html(specs)"
   ]
  }
 ],
 "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.12.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
