---
title: "Project: a microphone preamp"
heading: Forty decibels of clean gain, from 20 Hz to 20 kHz
eyebrow: C6 · Lesson 54 · Project
xp: 80
---

::: hook
A dynamic microphone puts out a few millivolts. Before anything else can happen, a mixer, a recorder, an ADC, those millivolts need raising to around a volt, without adding noise, without losing the bass or the treble, and without being disturbed by DC. This project builds that stage: a non-inverting op-amp amplifier with a gain of 100, a coupling capacitor for the low end, and an op amp fast enough for the high end. Then a code lab checks the design's full frequency response.

::: play
- The preamp: the microphone's signal comes in through $C_I$, $R_B$ biases the + input at ground, and $R_F$ and $R_G$ set the gain. The op amp has a 10 MHz gain-bandwidth.
- Read the gain in the middle of the band. Then find where it falls 3 dB at the low end and at the high end.
- Shrink $C_I$. Which end of the band moves?
:::
:::

```sim circuit
V1 mic 0 sine 10m V 1k Hz -90 °     @ 0,2 down 2
CI mic p 1u                         @ 0,2 right
RB p 0 10k                          @ 2,2 down 2
U1 p m out GBW=10M VSAT=12          @ 4,1 flip
RF m out 99k                        @ 4,-1 right 3
RG m 0 1k                           @ 4,-1 up 2
slider: CI 100n..10u log
slider: RF 9k..999k log
bode: v(out)/v(mic) | f = 1..1M Hz
scope: v(mic), v(out)
time: 0..3m s
```

::: predict
## With a gain of 100 from a 10 MHz op amp, where's the upper −3 dB frequency?

- [ ] 10 MHz
- [ ] 1 MHz
- [x] About 100 kHz
- [ ] 20 kHz

::: reveal
About 100 kHz: GBW ÷ noise gain = 10 MHz ÷ 100. That's comfortably above the 20 kHz audio limit, so the treble is safe. At the low end, the coupling capacitor and $R_B$ form a high-pass at $1/(2\pi R_BC_I)$, 16 Hz with 1 µF and 10 kΩ.
:::
:::

::: nameit
## The design

**Gain.** Non-inverting: $1 + R_F/R_G = 100$ (40 dB) with $R_F$ = 99 kΩ and $R_G$ = 1 kΩ. Non-inverting keeps the input impedance high (set by $R_B$, not by the gain resistors).

**Low end.** $C_I$ blocks any DC from the source, and with $R_B$ makes a high-pass:

$$f_L = \frac{1}{2\pi R_BC_I}$$

Choose it below 20 Hz. $R_B$ also gives the + input a DC path to ground; without it, the input bias current would charge $C_I$ and drift the output.

**High end.** The closed-loop bandwidth is $\text{GBW}/(1 + R_F/R_G)$. For 20 kHz with margin, the op amp needs a GBW of at least a few megahertz at a gain of 100.

**Other real concerns.**

- **DC gain.** The input offset is amplified by 100 too. A capacitor in series with $R_G$ cuts the DC gain to 1 while keeping the AC gain (a second, low corner at $1/(2\pi R_GC_G)$).
- **Noise.** At this gain, the op amp's input noise and the resistance at its input dominate; low-noise op amps and small resistors help.
- **Headroom.** With ±12 V of swing, the output clips above about 120 mV peak at the input, a loud shout into a dynamic microphone.
:::


::: example
## The preamp has a gain of 100 and its op amp a GBW of 10 MHz. What is its bandwidth, and what does the input network ($R_B$ = 100 kΩ, $C_I$ = 1 µF) do at the low end?

::: solution
1. **Upper limit.**
   $$\frac{10\ \text{MHz}}{100} = 100\ \text{kHz}$$
2. **Lower limit.** The input network's corner is
   $$\begin{aligned} f &= \frac{1}{2\pi \times 100\ \text{k} \times 1\ \mu\text{F}} \\ &= 1.6\ \text{Hz} \end{aligned}$$
3. **Compare the audio band.** Both are well outside 20 Hz to 20 kHz.

**Answer:** the bandwidth reaches 100 kHz, and the input network rolls off below 1.6 Hz, both well outside the audio band.
:::
:::

::: example
## For the response to be within 0.1 dB at 20 kHz, what GBW does the op amp need at a gain of 100?

::: solution
1. **Where a single pole is 0.1 dB down.** At
   $$f/f_c = 0.153$$
2. **Corner needed.** For 20 kHz,
   $$\begin{aligned} f_c &= \frac{20\ \text{kHz}}{0.153} \\ &= 131\ \text{kHz} \end{aligned}$$
3. **GBW.**
   $$100 \times 131\ \text{kHz} = 13\ \text{MHz}$$
   Flatness costs far more bandwidth than the 3 dB point suggests.

**Answer:** the op amp needs a GBW of about 13 MHz.
:::
:::

::: check
kind: design
choose: RF, CI
goal: gain_db(v(out)/v(mic), 1k) = 40 ± 0.3; gain_db(v(out)/v(mic), 20) = 37 ± 0.5
solution: RF = 99k; CI = 1/(2*pi*20*10000)

## Choose $R_F$ and $C_I$ so the preamp has 40 dB of gain at 1 kHz and is exactly 3 dB down at 20 Hz.

```sim circuit
V1 mic 0 sine 10m V 1k Hz           @ 0,2 down 2
CI mic p 10n                        @ 0,2 right
RB p 0 10k                          @ 2,2 down 2
U1 p m out GBW=10M VSAT=12          @ 4,1 flip
RF m out 9k                         @ 4,-1 right 3
RG m 0 1k                           @ 4,-1 up 2
bode: v(out)/v(mic) | f = 1..1M Hz
```

::: right
Right. $R_F = 99$ kΩ for a gain of 100, and $C_I = 1/(2\pi \times 20 \times 10\text{ k}) \approx 800$ nF.
:::
:::

::: check
kind: python
given: G = 10 | 100; GBW = 1e6 | 1e7; fL = 10 | 20

## Model the preamp's response as a high-pass at {fL} Hz times a gain of {G} whose bandwidth is limited by a {GBW} Hz op amp: $H = G\frac{jf/f_L}{1 + jf/f_L}\cdot\frac{1}{1 + jfG/\text{GBW}}$. Evaluate it on 5000 log-spaced points from 1 Hz to 10 MHz, and set `f_lo` and `f_hi` to the lower and upper −3 dB frequencies (relative to the peak gain).

```python starter
import numpy as np

f = np.logspace(0, 7, 5000)
H = G * (1j * f / fL) / (1 + 1j * f / fL) / (1 + 1j * f * G / GBW)
gain = np.abs(H)
f_lo = 0   # replace
f_hi = 0   # replace
print(f_lo, f_hi)
```

```python solution
import numpy as np

f = np.logspace(0, 7, 5000)
H = G * (1j * f / fL) / (1 + 1j * f / fL) / (1 + 1j * f * G / GBW)
gain = np.abs(H)
edge = gain.max() / np.sqrt(2)
above = np.where(gain >= edge)[0]
lo, hi = above[0], above[-1]
f_lo = 10 ** np.interp(edge, [gain[lo - 1], gain[lo]], [np.log10(f[lo - 1]), np.log10(f[lo])])
f_hi = 10 ** np.interp(edge, [gain[hi + 1], gain[hi]], [np.log10(f[hi + 1]), np.log10(f[hi])])
print(f_lo, f_hi)
```

```python tests
import numpy as np
fH = GBW / G
assert abs(f_lo - fL) < 0.02 * fL, f"The lower edge should be close to {fL} Hz; yours is {f_lo}."
assert abs(f_hi - fH) < 0.02 * fH, f"The upper edge should be close to {fH:.0f} Hz; yours is {f_hi}."
```

::: right
Right. With the corners decades apart, each edge sits where its own pole is: $f_L$ and GBW/G.
:::
:::

::: explain
## Why is a non-inverting configuration a good choice for a microphone preamp?

::: model
A microphone has a significant internal impedance, so the preamp's input impedance must be much higher to avoid losing signal. In a non-inverting amplifier the signal goes straight to the op amp's input, which draws almost no current, so the input impedance is set by the bias resistor and can be made high independently of the gain. An inverting amplifier's input impedance equals its input resistor, which would have to be small to get high gain with reasonable feedback resistors, loading the microphone.
:::
:::

::: practice

::: check
given: dB = 6 | 20 | 26
answer: 10^(dB/20) - 1
tolerance: 0.5%

## A non-inverting stage must have {dB} dB of gain. What ratio $R_F/R_G$?

::: misses
- [10^(dB/20)] The gain is $1 + R_F/R_G$.
- [any] $10^{dB/20} - 1$.
:::
:::

::: check
given: RB = 10 | 47 | 100; fL = 10 | 20
answer: 1/(2*pi*fL*RB*1e3)*1e6
unit: µF
tolerance: 0.5%

## Coupling capacitor for a {fL} Hz corner with $R_B$ = {RB} kΩ?

::: misses
- [1/(fL*RB*1e3)*1e6] Include 2π.
- [any] $1/(2\pi f_LR_B)$.
:::
:::

::: check
given: Vsat = 10 | 12; G = 100 | 1000
answer: Vsat/G*1000
unit: mV
tolerance: 0.5%

## A stage with gain {G} clips at ±{Vsat} V. Largest input peak before clipping?

::: misses
- [any] $V_\text{sat}/G$.
:::
:::
:::
