{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2b60df67-af61-4ee2-b6a0-ee13f6561239",
   "metadata": {},
   "source": [
    "# Differential-pair NMOS"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "343366af-1995-4a87-b4da-6717b0735d76",
   "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",
    "sl.initProject(\"Differential pair NMOS\", notebook=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "28b2bac4-fe4a-422d-98f3-8a3c38ba6a26",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Creating netlist of kicad/diffpair_n/diffpair_n.kicad_sch using KiCAD\n",
      "Creating drawing-size SVG and PDF images of kicad/diffpair_n/diffpair_n.kicad_sch\n",
      "Plotted to '/home/anton/DATA/www/SEDwebsite/_build/SEDwebsite/EE4109-2024-2025/designExample/HearingLoop/SLiCAPnoiseDesignNotebooks/WithTermination/img/diffpair_n.svg'.\n",
      "Done\n",
      "Checking netlist: cir/diffpair_n.cir\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<figure><img src=\"img/diffpair_n.svg\" alt=\"\" style=\"width:500px\">\n",
       "</figure>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cir=sl.makeCircuit(\"kicad/diffpair_n/diffpair_n.kicad_sch\")\n",
    "sl.img2html(\"diffpair_n.svg\",500)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7d2dfcdd-6abd-4b39-a901-2f31493811c4",
   "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\">$IC_{N}$</td><td class=\"left\">Inversion coefficient input stage NMOS</td><td class=\"left\">$0.001163$</td><td></td></tr>\n",
       "<td class=\"left\">$ID_{N}$</td><td class=\"left\">Operating current input stage NMOS</td><td class=\"left\">$2.827 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{A}$</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\">$L_{N}$</td><td class=\"left\">Selected length input stage NMOS</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{m}$</td></tr>\n",
       "<td class=\"left\">$M_{N}$</td><td class=\"left\">Number of fingers input stage NMOS</td><td class=\"left\">$2358$</td><td></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\">$W_{F N}$</td><td class=\"left\">Finger width input stage NMOS</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{m}$</td></tr>\n",
       "<td class=\"left\">$W_{N}$</td><td class=\"left\">Selected width input stage NMOS</td><td class=\"left\">$0.002358$</td><td class=\"left\">$\\mathrm{m}$</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 N o}$</td><td class=\"left\">Obtained input capacitance input stage NMOS</td><td class=\"left\">$6.911 \\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 N o}$</td><td class=\"left\">Obtained 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 WLI N}$</td><td class=\"left\">DIN A weighted RMS output noise with NMOS, W, L, and ID</td><td class=\"left\">$7.83 \\cdot 10^{-6}$</td><td class=\"left\">$\\mathrm{V}$</td></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": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "specs = sl.csv2specs('A1specs.csv')\n",
    "sl.specs2html(specs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7dd870fc-75bd-4920-922f-f6a4906704d3",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table><caption>Table: Element data of expanded netlist 'noise_ciss_gm'</caption>\n",
       "<tr><th class=\"left\">RefDes</th><th class=\"left\">Nodes</th><th class=\"left\">Refs</th><th class=\"left\">Model</th><th class=\"left\">Param</th><th class=\"left\">Symbolic</th><th class=\"left\">Numeric</th></tr>\n",
       "<tr><td class=\"left\">C1</td><td class = \"left\">out 3 </td><td class = \"left\"></td><td class = \"left\">C</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$\\frac{\\tau_{i}}{R_{i}}$</td><td class=\"left\">$1.798 \\cdot 10^{-9}$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">vinit</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td class=\"left\">C2</td><td class = \"left\">out 0 </td><td class = \"left\"></td><td class = \"left\">C</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$C_{\\ell}$</td><td class=\"left\">$1.0 \\cdot 10^{-11}$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">vinit</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td class=\"left\">Cdd_M1_X1</td><td class = \"left\">0 out </td><td class = \"left\"></td><td class = \"left\">C</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$0.5 c_{db X1}$</td><td class=\"left\">$2.122 \\cdot 10^{-13}$</td></tr>\n",
       "<tr><td class=\"left\">Cdg1_M1_X1</td><td class = \"left\">0 in </td><td class = \"left\"></td><td class = \"left\">C</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$c_{dg X1}$</td><td class=\"left\">$7.781 \\cdot 10^{-13}$</td></tr>\n",
       "<tr><td class=\"left\">Cdg2_M1_X1</td><td class = \"left\">out 3 </td><td class = \"left\"></td><td class = \"left\">C</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$c_{dg X1}$</td><td class=\"left\">$7.781 \\cdot 10^{-13}$</td></tr>\n",
       "<tr><td class=\"left\">Cgg_M1_X1</td><td class = \"left\">in 3 </td><td class = \"left\"></td><td class = \"left\">C</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$0.5 c_{gb X1} + 0.5 c_{gs X1}$</td><td class=\"left\">$3.208 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">Gm_M1_X1</td><td class = \"left\">0 out in 3 </td><td class = \"left\"></td><td class = \"left\">g</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$0.5 g_{m X1}$</td><td class=\"left\">$0.0007292$</td></tr>\n",
       "<tr><td class=\"left\">Go_M1_X1</td><td class = \"left\">0 out 0 out </td><td class = \"left\"></td><td class = \"left\">g</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$0.5 g_{o X1}$</td><td class=\"left\">$5.677 \\cdot 10^{-7}$</td></tr>\n",
       "<tr><td class=\"left\">L1</td><td class = \"left\">1 in </td><td class = \"left\"></td><td class = \"left\">L</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$L_{s}$</td><td class=\"left\">$0.12$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">iinit</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td class=\"left\">R1</td><td class = \"left\">1 2 </td><td class = \"left\"></td><td class = \"left\">R</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$R_{s}$</td><td class=\"left\">$875.0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noisetemp</td><td class=\"left\">$T$</td><td class=\"left\">$300.0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noiseflow</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvar</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvarlot</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td class=\"left\">R2</td><td class = \"left\">in 0 </td><td class = \"left\"></td><td class = \"left\">R</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$R_{t}$</td><td class=\"left\">$1.0 \\cdot 10^{4}$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noisetemp</td><td class=\"left\">$T$</td><td class=\"left\">$300.0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noiseflow</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvar</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvarlot</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td class=\"left\">R3</td><td class = \"left\">3 0 </td><td class = \"left\"></td><td class = \"left\">R</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$R_{i}$</td><td class=\"left\">$8900.0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noisetemp</td><td class=\"left\">$T$</td><td class=\"left\">$300.0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noiseflow</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvar</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvarlot</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td class=\"left\">V1</td><td class = \"left\">2 0 </td><td class = \"left\"></td><td class = \"left\">V</td>\n",
       "<td class=\"left\">value</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">noise</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dc</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "<tr><td></td><td></td><td></td><td></td><td class=\"left\">dcvar</td><td class=\"left\">$0$</td><td class=\"left\">$0$</td></tr>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sl.specs2circuit(specs, cir)\n",
    "cir.defPar(\"ID_N\", 0.6*cir.getParValue(\"I_fb\"))\n",
    "sl.elementData2html(cir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d707a3f0-172a-45f2-aa41-9b3965b8ccd0",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<table><caption>Table: Parameter definitions in 'noise_ciss_gm'.</caption>\n",
       "<tr><th class=\"left\">Name</th><th class=\"left\">Symbolic</th><th class=\"left\">Numeric</th></tr>\n",
       "<tr><td class=\"left\">$CGBO_{N18}$</td><td class=\"left\">$1.0 \\cdot 10^{-12}$</td><td class=\"left\">$1.0 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$CGSO_{N18}$</td><td class=\"left\">$3.3 \\cdot 10^{-10}$</td><td class=\"left\">$3.3 \\cdot 10^{-10}$</td></tr>\n",
       "<tr><td class=\"left\">$CJB_{0 N18}$</td><td class=\"left\">$0.001$</td><td class=\"left\">$0.001$</td></tr>\n",
       "<tr><td class=\"left\">$C_{OX N18}$</td><td class=\"left\">$\\frac{\\epsilon_{0} \\epsilon_{SiO2}}{TOX_{N18}}$</td><td class=\"left\">$0.008222$</td></tr>\n",
       "<tr><td class=\"left\">$C_{\\ell}$</td><td class=\"left\">$1.0 \\cdot 10^{-11}$</td><td class=\"left\">$1.0 \\cdot 10^{-11}$</td></tr>\n",
       "<tr><td class=\"left\">$C_{i}$</td><td class=\"left\">$1.798 \\cdot 10^{-9}$</td><td class=\"left\">$1.798 \\cdot 10^{-9}$</td></tr>\n",
       "<tr><td class=\"left\">$E_{CRIT N18}$</td><td class=\"left\">$1.07 \\cdot 10^{7}$</td><td class=\"left\">$1.07 \\cdot 10^{7}$</td></tr>\n",
       "<tr><td class=\"left\">$IC_{N}$</td><td class=\"left\">$0.001163$</td><td class=\"left\">$0.001163$</td></tr>\n",
       "<tr><td class=\"left\">$ID$</td><td class=\"left\">$2 ID_{N}$</td><td class=\"left\">$5.45 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$ID_{N}$</td><td class=\"left\">$2.725 \\cdot 10^{-5}$</td><td class=\"left\">$2.725 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$I_{0 N18}$</td><td class=\"left\">$2 C_{OX N18} N_{s N18} U_{T}^{2} u_{0 N18}$</td><td class=\"left\">$1.031 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$I_{fb}$</td><td class=\"left\">$4.542 \\cdot 10^{-5}$</td><td class=\"left\">$4.542 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$L$</td><td class=\"left\">$L_{N}$</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$LDS_{N18}$</td><td class=\"left\">$1.8 \\cdot 10^{-7}$</td><td class=\"left\">$1.8 \\cdot 10^{-7}$</td></tr>\n",
       "<tr><td class=\"left\">$L_{N}$</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$L_{s}$</td><td class=\"left\">$0.12$</td><td class=\"left\">$0.12$</td></tr>\n",
       "<tr><td class=\"left\">$M_{N}$</td><td class=\"left\">$2358$</td><td class=\"left\">$2358.0$</td></tr>\n",
       "<tr><td class=\"left\">$N_{s N18}$</td><td class=\"left\">$1.38$</td><td class=\"left\">$1.38$</td></tr>\n",
       "<tr><td class=\"left\">$P_{max}$</td><td class=\"left\">$0.001$</td><td class=\"left\">$0.001$</td></tr>\n",
       "<tr><td class=\"left\">$R_{i}$</td><td class=\"left\">$8900$</td><td class=\"left\">$8900.0$</td></tr>\n",
       "<tr><td class=\"left\">$R_{s}$</td><td class=\"left\">$875$</td><td class=\"left\">$875.0$</td></tr>\n",
       "<tr><td class=\"left\">$R_{t}$</td><td class=\"left\">$1.0 \\cdot 10^{4}$</td><td class=\"left\">$1.0 \\cdot 10^{4}$</td></tr>\n",
       "<tr><td class=\"left\">$Ri_{max}$</td><td class=\"left\">$8945.0$</td><td class=\"left\">$8945.0$</td></tr>\n",
       "<tr><td class=\"left\">$Ri_{min}$</td><td class=\"left\">$3380$</td><td class=\"left\">$3380.0$</td></tr>\n",
       "<tr><td class=\"left\">$SRCnoise$</td><td class=\"left\">$1.571 \\cdot 10^{-6}$</td><td class=\"left\">$1.571 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$S_{Ri}$</td><td class=\"left\">$2.491 \\cdot 10^{-11}$</td><td class=\"left\">$2.491 \\cdot 10^{-11}$</td></tr>\n",
       "<tr><td class=\"left\">$T$</td><td class=\"left\">$300$</td><td class=\"left\">$300.0$</td></tr>\n",
       "<tr><td class=\"left\">$TOX_{N18}$</td><td class=\"left\">$4.2 \\cdot 10^{-9}$</td><td class=\"left\">$4.2 \\cdot 10^{-9}$</td></tr>\n",
       "<tr><td class=\"left\">$\\Theta_{N18}$</td><td class=\"left\">$0.41$</td><td class=\"left\">$0.41$</td></tr>\n",
       "<tr><td class=\"left\">$U_{T}$</td><td class=\"left\">$\\frac{T k}{q}$</td><td class=\"left\">$0.02585$</td></tr>\n",
       "<tr><td class=\"left\">$VAL_{N18}$</td><td class=\"left\">$4.8 \\cdot 10^{7}$</td><td class=\"left\">$4.8 \\cdot 10^{7}$</td></tr>\n",
       "<tr><td class=\"left\">$V_{DD}$</td><td class=\"left\">$1.3$</td><td class=\"left\">$1.3$</td></tr>\n",
       "<tr><td class=\"left\">$V_{onoise}$</td><td class=\"left\">$1.062 \\cdot 10^{-5}$</td><td class=\"left\">$1.062 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$V_{onoise WLI N}$</td><td class=\"left\">$7.83 \\cdot 10^{-6}$</td><td class=\"left\">$7.83 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$V_{onoise gmCissN}$</td><td class=\"left\">$9.021 \\cdot 10^{-6}$</td><td class=\"left\">$9.021 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$Vi_{ADC}$</td><td class=\"left\">$0.9$</td><td class=\"left\">$0.9$</td></tr>\n",
       "<tr><td class=\"left\">$Vi_{pp}$</td><td class=\"left\">$0.2932$</td><td class=\"left\">$0.2932$</td></tr>\n",
       "<tr><td class=\"left\">$Vth_{N18}$</td><td class=\"left\">$0.42$</td><td class=\"left\">$0.42$</td></tr>\n",
       "<tr><td class=\"left\">$W$</td><td class=\"left\">$W_{N}$</td><td class=\"left\">$0.002358$</td></tr>\n",
       "<tr><td class=\"left\">$W_{F N}$</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td><td class=\"left\">$1.0 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$W_{N}$</td><td class=\"left\">$0.002358$</td><td class=\"left\">$0.002358$</td></tr>\n",
       "<tr><td class=\"left\">$c$</td><td class=\"left\">$2.998 \\cdot 10^{8}$</td><td class=\"left\">$2.998 \\cdot 10^{8}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{issN}$</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{iss N o}$</td><td class=\"left\">$6.911 \\cdot 10^{-12}$</td><td class=\"left\">$6.911 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{iss costs minN}$</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td><td class=\"left\">$6.912 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{iss g m minN}$</td><td class=\"left\">$9.87 \\cdot 10^{-10}$</td><td class=\"left\">$9.87 \\cdot 10^{-10}$</td></tr>\n",
       "<tr><td class=\"left\">$\\epsilon_{0}$</td><td class=\"left\">$\\frac{1}{c^{2} \\mu_{0}}$</td><td class=\"left\">$8.854 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$\\epsilon_{SiO2}$</td><td class=\"left\">$3.9$</td><td class=\"left\">$3.9$</td></tr>\n",
       "<tr><td class=\"left\">$f_{fp}$</td><td class=\"left\">$5000$</td><td class=\"left\">$5000.0$</td></tr>\n",
       "<tr><td class=\"left\">$f_{max}$</td><td class=\"left\">$6000$</td><td class=\"left\">$6000.0$</td></tr>\n",
       "<tr><td class=\"left\">$f_{min}$</td><td class=\"left\">$600$</td><td class=\"left\">$600.0$</td></tr>\n",
       "<tr><td class=\"left\">$g_{mN}$</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$g_{m N o}$</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$g_{m costs minN}$</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td><td class=\"left\">$7.854 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$g_{m minN}$</td><td class=\"left\">$3.926 \\cdot 10^{-5}$</td><td class=\"left\">$3.926 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$k$</td><td class=\"left\">$1.381 \\cdot 10^{-23}$</td><td class=\"left\">$1.381 \\cdot 10^{-23}$</td></tr>\n",
       "<tr><td class=\"left\">$\\mu_{0}$</td><td class=\"left\">$4.0 \\cdot 10^{-7} \\pi$</td><td class=\"left\">$1.257 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$n_{MN}$</td><td class=\"left\">$0.5$</td><td class=\"left\">$0.5$</td></tr>\n",
       "<tr><td class=\"left\">$n_{Ri}$</td><td class=\"left\">$0.2$</td><td class=\"left\">$0.2$</td></tr>\n",
       "<tr><td class=\"left\">$n_{Ri obtained}$</td><td class=\"left\">$0.199$</td><td class=\"left\">$0.199$</td></tr>\n",
       "<tr><td class=\"left\">$n_{SRC}$</td><td class=\"left\">$0.02189$</td><td class=\"left\">$0.02189$</td></tr>\n",
       "<tr><td class=\"left\">$q$</td><td class=\"left\">$1.602 \\cdot 10^{-19}$</td><td class=\"left\">$1.602 \\cdot 10^{-19}$</td></tr>\n",
       "<tr><td class=\"left\">$\\tau_{i}$</td><td class=\"left\">$1.6 \\cdot 10^{-5}$</td><td class=\"left\">$1.6 \\cdot 10^{-5}$</td></tr>\n",
       "<tr><td class=\"left\">$u_{0 N18}$</td><td class=\"left\">$0.068$</td><td class=\"left\">$0.068$</td></tr>\n",
       "<tr><td class=\"left\">$IC_{CRIT X1}$</td><td class=\"left\">$\\frac{0.0625}{N_{s N18}^{2} U_{T}^{2} \\left(\\Theta_{N18} + \\frac{1}{E_{CRIT N18} L}\\right)^{2}}$</td><td class=\"left\">$193.7$</td></tr>\n",
       "<tr><td class=\"left\">$IC_{X1}$</td><td class=\"left\">$IC_{i X1} \\left(1 + \\frac{2 IC_{i X1}}{IC_{CRIT X1}}\\right)^{0.5}$</td><td class=\"left\">$0.02241$</td></tr>\n",
       "<tr><td class=\"left\">$IC_{i X1}$</td><td class=\"left\">$\\frac{ID L}{I_{0 N18} W}$</td><td class=\"left\">$0.02241$</td></tr>\n",
       "<tr><td class=\"left\">$V_{GS X1}$</td><td class=\"left\">$2 N_{s N18} U_{T} \\log{\\left(e^{\\left(IC_{i X1} \\left(1 + \\frac{IC_{i X1}}{IC_{CRIT X1}}\\right)\\right)^{0.5}} - 1 \\right)} + Vth_{N18}$</td><td class=\"left\">$0.2899$</td></tr>\n",
       "<tr><td class=\"left\">$c_{db X1}$</td><td class=\"left\">$CJB_{0 N18} LDS_{N18} W$</td><td class=\"left\">$4.244 \\cdot 10^{-13}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{dg X1}$</td><td class=\"left\">$CGSO_{N18} W$</td><td class=\"left\">$7.781 \\cdot 10^{-13}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{gb X1}$</td><td class=\"left\">$2 CGBO_{N18} L + \\frac{0.3333 C_{OX N18} L W \\left(N_{s N18} - 1\\right) \\left(x_{X1} + 1\\right)}{N_{s N18}}$</td><td class=\"left\">$5.225 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$c_{gs X1}$</td><td class=\"left\">$CGSO_{N18} W + C_{OX N18} L W \\left(0.6667 - 0.3333 x_{X1}\\right)$</td><td class=\"left\">$1.191 \\cdot 10^{-12}$</td></tr>\n",
       "<tr><td class=\"left\">$g_{m X1}$</td><td class=\"left\">$\\frac{ID}{N_{s N18} U_{T} \\left(IC_{X1} \\left(1 + \\frac{IC_{X1}}{IC_{CRIT X1}}\\right) + 0.5 \\left(IC_{X1} \\left(1 + \\frac{IC_{X1}}{IC_{CRIT X1}}\\right)\\right)^{0.5} + 1\\right)^{0.5}}$</td><td class=\"left\">$0.001458$</td></tr>\n",
       "<tr><td class=\"left\">$g_{o X1}$</td><td class=\"left\">$\\frac{ID}{L VAL_{N18}}$</td><td class=\"left\">$1.135 \\cdot 10^{-6}$</td></tr>\n",
       "<tr><td class=\"left\">$x_{X1}$</td><td class=\"left\">$\\frac{\\left(IC_{X1} + 0.25\\right)^{0.5} + 1.5}{\\left(\\left(IC_{X1} + 0.25\\right)^{0.5} + 0.5\\right)^{2}}$</td><td class=\"left\">$1.936$</td></tr>\n",
       "</table>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sl.params2html(cir)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "835ac066-c6e3-4661-a8e5-fa7a2b494ac5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "[encoded data, 49428 characters]",
      "text/plain": [
       "<Figure size 400x300 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "gain        = sl.doLaplace(cir, pardefs=\"circuit\", numeric=True)\n",
    "asymptotic  = sl.doLaplace(cir, pardefs=\"circuit\", numeric=True, transfer=\"asymptotic\")\n",
    "loopgain    = sl.doLaplace(cir, pardefs=\"circuit\", numeric=True, transfer=\"loopgain\")\n",
    "servo       = sl.doLaplace(cir, pardefs=\"circuit\", numeric=True, transfer=\"servo\")\n",
    "direct      = sl.doLaplace(cir, pardefs=\"circuit\", numeric=True, transfer=\"direct\")\n",
    "\n",
    "fb_model    = [gain, asymptotic, loopgain, servo, direct]\n",
    "fbmodel_mag = sl.plotSweep(\"fb_mag\", \"Magnitude plots feedback model parameters\", fb_model, 10, 10e5, 200, show=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "827e2d87-0336-4d8a-8ea5-470feed9fd73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$\\displaystyle - \\frac{R_{i} g_{m X1}}{2}$"
      ],
      "text/plain": [
       "-R_i*g_m_X1/2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "lg_sym = sl.doLaplace(cir, transfer=\"loopgain\").laplace\n",
    "substitutions = {\"c_dg_X1\":0,\"c_gs_X1\":0,\"c_gb_X1\":0,\"c_db_X1\":0, \"g_o_X1:}\n",
    "L = sp.simplify(sp.limit(sp.simplify(lg_sym.subs(substitutions)), sp.Symbol(\"tau_i\"), sp.oo))\n",
    "L.subs({sl.ini.laplace:0, sp.Symbol(\"g_o_X1\"):0})"
   ]
  }
 ],
 "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
}
