---
title: Bias and gain lab
heading: Operating points, β spread and stage gain in NumPy
eyebrow: C5 · Lesson 51 · Bias and gain lab
xp: 50
---

::: hook
Hand analysis with 0.7 V and a single β is how you design a stage; checking it means asking what happens with the real exponential, and with every β the parts on the shelf might have. In this lab you'll solve a divider-biased transistor's operating point exactly, sweep β across a whole batch of transistors to compare two bias schemes, and compute the small-signal gain and input resistance that follow from the bias. It's the same chain of reasoning as lessons 23 to 49, run as code.
:::

::: play
- Collector current against β for two designs that both give 1 mA at β = 150: a single base resistor, and a divider with an emitter resistor.
- The base-resistor design's current is proportional to β, so a batch from β = 50 to 400 spreads eightfold. The divider design barely moves.
- Make the divider stiffer (lower $R_{TH}$) or raise $R_E$: the divider curve flattens further.
:::
:::

```sim plot
view: graph
x: beta = 50..400
y: IC = 0..3 mA
slider: RTH = 1..50 step 1 = 8 kΩ
slider: RE = 0.5..3 step 0.1 = 1 kΩ
plot: beta/150 | label: base resistor, 1 mA at β = 150
plot: beta/(beta + 1)*151/150*(RE + RTH/151)/(RE + RTH/(beta + 1)) | label: divider and emitter resistor | dashed | color: ch2
readout: divider design, current at β 400 over β 50 = (RE + RTH/51)/(RE + RTH/401)*400/401*51/50 | digits: 4
```

::: predict
## A divider-biased stage has $R_E$ = 1 kΩ and $R_{TH}$ = 8 kΩ. Across a batch of transistors with β from 50 to 400, how much does its current vary?

- [ ] Eightfold, like β
- [ ] About twofold
- [x] About 15%
- [ ] Not at all

::: reveal
About 15%. The current is $\frac{V_{TH} - 0.7}{R_E + R_{TH}/(\beta + 1)}$; $R_{TH}/(\beta + 1)$ goes from 157 Ω to 20 Ω, against 1 kΩ of $R_E$. The α in front adds 1.5% more. A base-resistor design over the same batch would vary eightfold.
:::
:::

::: nameit
## The exact operating point

With the Thevenin equivalent of the divider, the base loop is

$$V_{TH} = I_E\frac{R_{TH}}{\beta + 1} + V_T\ln\frac{\alpha I_E}{I_S} + I_ER_E$$

The 0.7 V of hand analysis replaced by the true exponential. Solve it by Newton's method in $I_E$, with

$$f(I_E) = V_{TH} - V_T\ln\frac{\alpha I_E}{I_S} - I_E\left(R_E + \frac{R_{TH}}{\beta + 1}\right) \qquad f'(I_E) = -\frac{V_T}{I_E} - R_E - \frac{R_{TH}}{\beta + 1}$$

starting from 1 mA. Then $I_C = \alpha I_E$, $V_C = V_{CC} - I_CR_C$ and $V_E = I_ER_E$.

## Vectorizing over β

NumPy applies a formula to a whole array at once: if `beta` is an array, `beta / 150` is an array of currents, one per transistor. The constant-0.7 V formulas need no loop.

## From bias to gain

With the T model, $r_e = \alpha V_T/I_C$, and for a CE stage with unbypassed $R_{E1}$ (zero when fully bypassed):

$$A_v = -\frac{\alpha(R_C \parallel R_L)}{r_e + R_{E1}} \qquad R_\text{in} = R_B \parallel (\beta + 1)(r_e + R_{E1})$$

which reduces to $-g_m(R_C \parallel R_L)$ and $R_B \parallel r_\pi$ when $R_{E1}$ = 0.
:::

::: example
## Solve the operating point of lesson 42's stage exactly: 12 V, $R_1$ = 47 kΩ, $R_2$ = 10 kΩ, $R_C$ = 4.7 kΩ, $R_E$ = 1 kΩ, β = 100, $I_S = 10^{-16}$ A.

::: solution
1. **Thévenin equivalent.** $V_{TH}$ = 2.105 V and $R_{TH}$ = 8.25 kΩ.
2. **Newton's method.** It settles at $I_E$ = 1.226 mA with $V_{BE}$ = 0.779 V.
3. **The rest of the operating point.**
   $$\begin{aligned} I_C &= 1.214\ \text{mA} \\ V_C &= 6.30\ \text{V} \\ V_E &= 1.23\ \text{V} \end{aligned}$$
4. **Compare with the estimate.** The 0.7 V estimate gave 1.30 mA: 6% high, because this transistor's small $I_S$ needs more than 0.7 V.

**Answer:** $I_C$ = 1.214 mA, $V_C$ = 6.30 V and $V_E$ = 1.23 V, with $V_{BE}$ = 0.779 V.
:::
:::

::: example
## What gain and input resistance does a stage at 1 mA (β = 100) with $R_C$ = 4.7 kΩ, a 10 kΩ load and $R_B$ = 8.25 kΩ have, fully bypassed and with 100 Ω unbypassed?

::: solution
1. **Emitter resistance.** $r_e$ = 25.6 Ω.
2. **Fully bypassed.**
   $$\begin{aligned} A_v &= -\frac{0.99 \times 3197}{25.6} \\ &= -124 \end{aligned}$$
   and $R_\text{in} = 8.25\ \text{k} \parallel 2.59\ \text{k}$ = 1.97 kΩ.
3. **With 100 Ω unbypassed.** $A_v$ = −25.2 and $R_\text{in} = 8.25\ \text{k} \parallel 12.7\ \text{k}$ = 5.0 kΩ.

**Answer:** fully bypassed, the gain is −124 and the input resistance 1.97 kΩ; with 100 Ω unbypassed, they are −25.2 and 5.0 kΩ.
:::
:::

::: check
given: VTH = 1.5 | 3; RTH = 5 | 20; RE = 0.5 | 2; beta = 100 | 300
answer: (VTH - 0.7)/(RE + RTH/(beta + 1))
unit: mA
tolerance: 0.5%

## With 0.7 V for $V_{BE}$: what emitter current does $V_{TH}$ = {VTH} V, $R_{TH}$ = {RTH} kΩ, $R_E$ = {RE} kΩ and β = {beta} give?

::: right
Right. {answer}: the starting point for the exact solution.
:::

::: misses
- [any] Not yet. $\frac{V_{TH} - 0.7}{R_E + R_{TH}/(\beta + 1)}$.
:::
:::

::: check
given: IE = 0.5 | 1 | 2; RE = 0.5 | 2; RTH = 5 | 20; beta = 100
answer: -(0.025864/(IE*1e-3) + RE*1000 + RTH*1000/101)
unit: Ω
tolerance: 0.5%

## What is $f'(I_E)$ for Newton's method at $I_E$ = {IE} mA, with $R_E$ = {RE} kΩ, $R_{TH}$ = {RTH} kΩ and β = 100?

::: right
Right. $-\frac{V_T}{I_E} - R_E - \frac{R_{TH}}{\beta + 1}$ = {answer}, in volts per ampere.
:::

::: misses
- [-(RE*1000 + RTH*1000/101)] Include the slope of the logarithm, $-V_T/I_E$.
- [any] Not yet. Differentiate each term of f.
:::
:::

::: check
kind: python

## Write `bias_point(VCC, R1, R2, RC, RE, beta, IS=1e-16)` returning `(IC, VC, VE)` for a divider-biased NPN, solving the exact base loop by Newton's method in $I_E$. Use VT = 0.025864 V.

```python starter
import math

VT = 0.025864

def bias_point(VCC, R1, R2, RC, RE, beta, IS=1e-16):
    VTH = VCC * R2 / (R1 + R2)
    IE = (VTH - 0.7) / RE
    IC = IE
    return IC, VCC - IC * RC, IE * RE
```

```python solution
import math

VT = 0.025864

def bias_point(VCC, R1, R2, RC, RE, beta, IS=1e-16):
    VTH = VCC * R2 / (R1 + R2)
    RTH = R1 * R2 / (R1 + R2)
    a = beta / (beta + 1)
    R = RE + RTH / (beta + 1)
    IE = 1e-3
    for _ in range(100):
        f = VTH - VT * math.log(a * IE / IS) - IE * R
        df = -VT / IE - R
        step = f / df
        IE -= step
        if abs(step) < 1e-15:
            break
    IC = a * IE
    return IC, VCC - IC * RC, IE * RE
```

```python tests
cases = [((12, 47e3, 10e3, 4.7e3, 1e3, 100), (0.0012138231649220354, 6.2950311248664335, 1.2259613965712557)),
         ((12, 47e3, 10e3, 4.7e3, 1e3, 300), (0.0012849740202125724, 5.960622105000909, 1.2892572669466145)),
         ((9, 100e3, 22e3, 3.3e3, 1.5e3, 150), (0.0005306865290369294, 7.248734454178133, 0.8013366588457634)),
         ((15, 68e3, 12e3, 4.7e3, 1e3, 80), (0.0012888027700169334, 8.942626980920412, 1.3049128046421452))]
for args, want in cases:
    got = bias_point(*args)
    for g, w, name in zip(got, want, ("IC", "VC", "VE")):
        assert abs(g - w) <= 1e-9 * abs(w), f"For {args}: {name} should be {w:.6g}, got {g:.6g}."
```

::: right
Right. The starter ignored the base current and used 0.7 V, which puts $I_C$ 9 to 16% high in the first two cases.
:::
:::

::: check
kind: python

## Write `ic_base(beta, VCC, RB)` and `ic_divider(beta, VCC, R1, R2, RE)` returning collector currents for an array of β values (0.7 V for $V_{BE}$), and `spread(ic)` returning the ratio of the largest current to the smallest.

```python starter
import numpy as np

def ic_base(beta, VCC, RB):
    return np.full(len(beta), (VCC - 0.7) / RB * 150)

def ic_divider(beta, VCC, R1, R2, RE):
    VTH = VCC * R2 / (R1 + R2)
    return np.full(len(beta), (VTH - 0.7) / RE)

def spread(ic):
    return 1.0
```

```python solution
import numpy as np

def ic_base(beta, VCC, RB):
    beta = np.asarray(beta, dtype=float)
    return beta * (VCC - 0.7) / RB

def ic_divider(beta, VCC, R1, R2, RE):
    beta = np.asarray(beta, dtype=float)
    VTH = VCC * R2 / (R1 + R2)
    RTH = R1 * R2 / (R1 + R2)
    return beta / (beta + 1) * (VTH - 0.7) / (RE + RTH / (beta + 1))

def spread(ic):
    return float(np.max(ic) / np.min(ic))
```

```python tests
import numpy as np
beta = np.linspace(50, 400, 36)
b = ic_base(beta, 12, 1.695e6)
assert b.shape == beta.shape, "Return one current per β."
assert abs(b[0] - 50 * 11.3 / 1.695e6) < 1e-12 and abs(spread(b) - 8) < 1e-9, f"Base bias is proportional to β: the spread should be 8, got {spread(b):.4f}."
d = ic_divider(beta, 12, 47e3, 10e3, 1e3)
want = beta / (beta + 1) * (12 * 10 / 57 - 0.7) / (1e3 + 47e3 * 10e3 / 57e3 / (beta + 1))
assert np.allclose(d, want, rtol=1e-12), "Use alpha times (VTH - 0.7) / (RE + RTH / (beta + 1))."
assert abs(spread(d) - want.max() / want.min()) < 1e-12, f"Divider spread should be {want.max() / want.min():.4f}."
```

::: right
Right. Over β = 50 to 400 the divider design's current varies by 15%, against eightfold for the base resistor.
:::
:::

::: check
kind: python

## Write `ce_stage(IC, beta, RC, RL, RE1, RB)` returning `(Av, Rin)` for a CE stage with unbypassed emitter resistance `RE1` (0 if fully bypassed), using the T model with VT = 0.025864 V.

```python starter
VT = 0.025864

def ce_stage(IC, beta, RC, RL, RE1, RB):
    gm = IC / VT
    return -gm * RC, beta / gm
```

```python solution
VT = 0.025864

def ce_stage(IC, beta, RC, RL, RE1, RB):
    a = beta / (beta + 1)
    re = a * VT / IC
    RCL = RC * RL / (RC + RL)
    Av = -a * RCL / (re + RE1)
    Rbase = (beta + 1) * (re + RE1)
    return Av, RB * Rbase / (RB + Rbase)
```

```python tests
cases = [((1e-3, 100, 4.7e3, 10e3, 0, 8.25e3), (-123.61888770355034, 1969.0856742091473)),
         ((1e-3, 100, 4.7e3, 10e3, 100, 8.25e3), (-25.202412911185412, 4999.082936894595)),
         ((2e-3, 200, 2.2e3, 1e3, 47, 20e3), (-11.426529492911397, 7513.033271522849))]
for args, (wa, wr) in cases:
    Av, Rin = ce_stage(*args)
    assert abs(Av - wa) < 1e-9 * abs(wa), f"For {args}: gain should be {wa:.4f}, got {Av:.4f}."
    assert abs(Rin - wr) < 1e-9 * wr, f"For {args}: input resistance should be {wr:.1f} Ω, got {Rin:.1f} Ω."
```

::: right
Right. The starter left out the load, the bias divider and any emitter degeneration, which together change the gain by a factor of fifteen in the third case.
:::
:::

::: explain
## Why is the exact operating point usually within a few percent of the 0.7 V estimate?

::: model
The base-emitter voltage enters only through a logarithm of the current, so it changes very little over the range of currents a stage might carry: about 60 mV per tenfold change. Whatever the exact value is, it differs from 0.7 V by at most a few tenths of a volt for ordinary transistors, and that difference is a small part of the voltage across the emitter resistor and the base resistance. So the current, which is set by that voltage over those resistors, moves by only a few percent. The more voltage the design puts across $R_E$, the less the exact $V_{BE}$ matters.
:::
:::

::: practice

::: check
given: beta = 50 | 80 | 100 | 200 | 250 | 300 | 400; IC1 = 1
answer: beta/150*IC1
unit: mA
tolerance: 0.5%

## A base-resistor design gives 1 mA at β = 150. What does it give at β = {beta}?

::: misses
- [any] Proportional to β.
:::
:::

::: check
given: IC = 0.5 | 2; beta = 100 | 300
answer: beta/(beta + 1)*0.025864/(IC*1e-3)
unit: Ω
tolerance: 0.5%

## What is $r_e = \alpha V_T/I_C$ at {IC} mA with β = {beta}?

::: misses
- [any] $\alpha V_T/I_C$.
:::
:::

::: check
given: VTH = 1.8 | 2.5; RTH = 8 | 15; VCC = 9 | 12
answer: RTH*VCC/VTH
unit: kΩ
tolerance: 0.5%

## What upper divider resistor $R_1$ gives $V_{TH}$ = {VTH} V and $R_{TH}$ = {RTH} kΩ on {VCC} V?

::: misses
- [any] $R_1 = R_{TH}V_{CC}/V_{TH}$.
:::
:::
:::
