---
title: Stage lab
heading: Small-signal stages, cascodes, followers and time constants, in Python
eyebrow: S2 · Lesson 6 · Stage lab
xp: 60
---

::: hook
Hand analysis of a single stage is quick but error-prone once body effect, $r_o$ and degeneration all appear at once. Analog designers keep a small toolbox of exact expressions in a script and check their hand estimates against it before going to the simulator. This lab builds that toolbox: the degenerated common-source stage, the cascode's output resistance, the source follower's gain, and the open-circuit time-constant estimate compared with a stage's exact poles.
:::

::: play
- The curve is a degenerated common-source stage's gain against its source resistor, from the exact small-signal result with $g_m$ = 2 mS, $g_{mb}$ = 0.3 mS and $r_o$ = 50 kΩ into a 20 kΩ load.
- With no degeneration the gain is $g_m(r_o \parallel R_L)$, 28.6; degeneration trades gain for linearity and output resistance.
- The dashed line is the simple estimate $R_L/R_S$, which the exact curve approaches only when $g_mR_S$ is large and $r_o$ is far above $R_L$.
:::

```sim plot
view: graph
x: R = 10..10000 Ω log
y: A = 0.1..100 log
plot: 0.002/(1 + 0.0023*R + R/50000)*((50000 + (1 + 0.0023*50000)*R)*20000/(50000 + (1 + 0.0023*50000)*R + 20000)) | label: exact gain
plot: 20000/R | dashed | label: R_L/R_S
```

::: predict
## The common-source stage ($g_m$ = 2 mS, $g_{mb}$ = 0.3 mS, $r_o$ = 50 kΩ) gets $R_S$ = 1 kΩ and drives 20 kΩ. What gain does it have?

- [ ] About 28
- [ ] About 20
- [x] About 11
- [ ] About 2

::: reveal
$G_m = g_m/(1 + (g_m + g_{mb})R_S + R_S/r_o) = 0.60$ mS, and the output resistance rises to $r_o + (1 + (g_m + g_{mb})r_o)R_S = 166$ kΩ, so the gain is $0.60\text{ mS} \times (166\text{ k} \parallel 20\text{ k}) = 10.8$. The estimate $R_L/R_S = 20$ is far off, because $g_mR_S = 2$ isn't large.
:::
:::

::: nameit
## The formulas

- **Degenerated CS:** $G_m = \dfrac{g_m}{1 + (g_m + g_{mb})R_S + R_S/r_o}$, $R_\text{out} = r_o + (1 + (g_m + g_{mb})r_o)R_S$, gain $-G_m(R_\text{out} \parallel R_L)$.
- **Cascode output resistance:** the same $R_\text{out}$ with $R_S$ replaced by the resistance below the cascode device.
- **Source follower:** $A = g_m/(g_m + g_{mb} + 1/r_o + 1/R_L)$.
- **Open-circuit time constants:** for a CS stage with $C_{gs}$, $C_{gd}$ and $C_{db}$, $b_1 = R_sC_{gs} + [R_s(1 + g_mR_L) + R_L]C_{gd} + R_LC_{db}$, and the exact denominator $1 + b_1s + b_2s^2$ has $b_2 = R_sR_L(C_{gs}C_{gd} + C_{gs}C_{db} + C_{gd}C_{db})$.
:::

::: check
kind: python

## Write `cs_stage(gm, gmb, ro, RS, RL)`: return (gain, Gm, Rout) for the degenerated common-source stage.

```python starter
def cs_stage(gm, gmb, ro, RS, RL):
    return (-gm * RL, gm, ro)
```

```python solution
def cs_stage(gm, gmb, ro, RS, RL):
    Gm = gm / (1 + (gm + gmb) * RS + RS / ro)
    Rout = ro + (1 + (gm + gmb) * ro) * RS
    Rp = Rout * RL / (Rout + RL)
    return (-Gm * Rp, Gm, Rout)
```

```python tests
a, G, R = cs_stage(2e-3, 0.3e-3, 50e3, 1e3, 20e3)
assert abs(a + 10.753) < 1e-3 and abs(R - 166e3) < 1, "The predict: gain −10.75, output resistance 166 kΩ."
a0, _, _ = cs_stage(2e-3, 0, 50e3, 0, 1e15)
assert abs(a0 + 100) < 1e-3, "No degeneration, no load: the intrinsic gain gm ro = 100."
```

::: right
Right. The $R_S/r_o$ term is small but completes the exact result; dropping it is fine when $r_o \gg R_S$.
:::
:::

::: check
kind: python

## Write `cascode_rout(gm, gmb, ro, Rbelow)` and `follower_gain(gm, gmb, ro, RL)`.

```python starter
def cascode_rout(gm, gmb, ro, Rbelow):
    return ro

def follower_gain(gm, gmb, ro, RL):
    return 1.0
```

```python solution
def cascode_rout(gm, gmb, ro, Rbelow):
    return ro + (1 + (gm + gmb) * ro) * Rbelow

def follower_gain(gm, gmb, ro, RL):
    return gm / (gm + gmb + 1 / ro + 1 / RL)
```

```python tests
assert abs(cascode_rout(2e-3, 0.3e-3, 50e3, 50e3) - 5.85e6) < 1, "A cascode on a 50 kΩ source: 5.85 MΩ."
assert abs(follower_gain(2e-3, 0.3e-3, 50e3, 20e3) - 0.8439) < 1e-4, "Follower into 20 kΩ: 0.844, body effect costing most of the loss."
assert follower_gain(2e-3, 0, 1e12, 1e12) > 0.999, "Ideal follower: gain 1."
```

::: right
Right. Body effect alone limits a follower to $g_m/(g_m + g_{mb})$, here 0.87, even with no load.
:::
:::

::: check
kind: python

## Write `cs_poles(Rs, gm, RL, Cgs, Cgd, Cdb)`: return (the open-circuit time-constant estimate $1/b_1$, and the exact poles $p_1 < p_2$ of $1 + b_1s + b_2s^2$), all in rad/s.

```python starter
import math

def cs_poles(Rs, gm, RL, Cgs, Cgd, Cdb):
    return (0.0, 0.0, 0.0)
```

```python solution
import math

def cs_poles(Rs, gm, RL, Cgs, Cgd, Cdb):
    b1 = Rs * Cgs + (Rs * (1 + gm * RL) + RL) * Cgd + RL * Cdb
    b2 = Rs * RL * (Cgs * Cgd + Cgs * Cdb + Cgd * Cdb)
    d = math.sqrt(b1 * b1 - 4 * b2)
    return (1 / b1, (b1 - d) / (2 * b2), (b1 + d) / (2 * b2))
```

```python tests
est, p1, p2 = cs_poles(10e3, 2e-3, 20e3, 100e-15, 10e-15, 20e-15)
assert abs(est - 1.754e8) / 1.754e8 < 1e-3, "OCT: 1.75e8 rad/s."
assert abs(p1 - 1.790e8) / 1.790e8 < 1e-3, "Exact dominant pole: 1.79e8 rad/s, 2% above the estimate."
assert est < p1 and p2 > 40 * p1, "OCT is slightly pessimistic when the poles are well separated."
```

::: right
Right. When the second pole is far away, $1/b_1$ is within a few percent of the dominant pole, and always on the safe side.
:::
:::

::: check
kind: python

## Write `pair_cmrr(gm, Rtail, mismatch)`: the CMRR (as a ratio) of a differential pair with per-side $g_m$, tail resistance $R_\text{tail}$ and fractional load mismatch, $2g_mR_\text{tail}/\text{mismatch}$; and `cmrr_db(x)`.

```python starter
import math

def pair_cmrr(gm, Rtail, mismatch):
    return 1.0

def cmrr_db(x):
    return 0.0
```

```python solution
import math

def pair_cmrr(gm, Rtail, mismatch):
    return 2 * gm * Rtail / mismatch

def cmrr_db(x):
    return 20 * math.log10(x)
```

```python tests
r = pair_cmrr(0.5e-3 / 0.02585, 100e3, 0.01)
assert abs(cmrr_db(r) - 111.7) < 0.1, "0.5 mA per side, 100 kΩ tail, 1% mismatch: about 112 dB."
assert abs(cmrr_db(pair_cmrr(1e-3, 1e6, 0.01)) - cmrr_db(pair_cmrr(1e-3, 1e5, 0.01)) - 20) < 1e-9, "Ten times the tail resistance: 20 dB more."
```

::: right
Right. Cascoding the tail current source multiplies $R_\text{tail}$ and is the usual route to high CMRR.
:::
:::

::: explain
## Why does the simple gain estimate $R_L/R_S$ for a degenerated common-source stage often disagree badly with the exact result?

::: model
The estimate assumes the transistor's transconductance is so large that all of the input voltage appears across the source resistor, and that the transistor's output resistance is so high it doesn't load the output. In practice $g_mR_S$ is often only 2 to 5, so part of the input still appears across the gate-source junction, and the body effect adds to the feedback through $g_{mb}$; both reduce the effective transconductance below $1/R_S$. If $r_o$ isn't far above $R_L$, the output resistance also shares the load. The exact formula keeps all three effects and is worth computing whenever $g_mR_S$ isn't large.
:::
:::
