Skip to main content

Envelope Detector Circuit

What is an envelope detector?​

An envelope detector is a circuit that follows the slowly changing peak amplitude of a fast oscillation and outputs that outline, the envelope, without the oscillation itself. The simplest one is a diode followed by a capacitor and a resistor in parallel. It recovers the audio from an AM radio signal and measures the level of RF, audio and ultrasound signals.

A diode envelope detector simulation in a dark navy theme: an amplitude-modulated carrier in blue with the detector output in orange tracing its upper edge and the true envelope dashed, and below it a chart of the output minus the true envelope showing a small sawtooth ripple

A 1 MHz carrier modulated 80% by a 5 kHz tone (blue), the true envelope (dashed) and the output of a diode detector with R = 10 kΩ and C = 2.2 nF (orange); below, the output minus the envelope in millivolts (simulated). Try the interactive version and change R, C, the diode and the signal.

Key takeaways
  • A diode envelope detector rectifies the carrier, holds each peak on a capacitor and lets it leak away through a resistor.
  • The time constant must sit between two limits: 1/fc≪RC≪1/W1/f_c \ll RC \ll 1/W, with fcf_c the carrier frequency and WW the highest message frequency.
  • Too short an RC leaves carrier ripple; too long an RC gives diagonal clipping, which starts above RC=1−m2/(2πWm)RC = \sqrt{1-m^2}/(2\pi W m).
  • A diode's forward drop loses weak signals and makes clipping worse; a precision (op-amp) detector removes it.
  • An envelope detector can't demodulate overmodulated AM, DSB-SC or SSB; those need a synchronous detector.

How a diode envelope detector works​

The classic circuit has three parts: a diode, a capacitor and a resistor. The input is an amplitude-modulated (AM) signal, a fast carrier whose size follows a slower message such as audio.

A diode envelope detector circuit: an AM input source feeds a diode D; after the diode a capacitor C and a resistor R in parallel go to ground, and the voltage across them is the envelope output. A note gives the rule 1/fc much less than RC much less than 1/W, where fc is the carrier frequency and W the message bandwidth. Below, three simulated outputs for one AM input: RC too short drops back every carrier cycle and leaves a large sawtooth ripple; RC about right follows the envelope with a small ripple; RC too long can't fall fast enough and cuts across the troughs of the envelope

  1. The diode rectifies. On each positive peak of the carrier, the input rises above the capacitor voltage, the diode conducts, and the capacitor charges up to the peak (less the diode's forward drop).
  2. The capacitor holds the peak. Once the carrier falls past its peak, the diode is reverse-biased and switches off. The capacitor holds its charge.
  3. The resistor discharges it. Between peaks, the capacitor discharges through the resistor, falling by the factor e−t/RCe^{-t/RC}. On the next peak the diode tops it up again.

The output is a sawtooth that rides along the tops of the carrier peaks. If the discharge between two carrier peaks is small, and the capacitor can still fall as fast as the message does, the sawtooth is a close copy of the envelope. Without the resistor, the circuit is a peak detector: it holds the highest peak it has ever seen and never comes down.

In software, the same circuit is a few lines. At each time step, the held voltage decays by e−Δt/RCe^{-\Delta t/RC}, and if the input minus the diode drop is higher, the output jumps to that value. This model is what the simulator below runs.

Choosing R and C: carrier ripple vs diagonal clipping​

Only the product RCRC, the time constant, sets how fast the capacitor discharges. It has to satisfy two opposing limits:

1fc≪RC≪1W\frac{1}{f_c} \ll RC \ll \frac{1}{W}

where fcf_c is the carrier frequency and WW the highest frequency in the message (the envelope's bandwidth).

The lower limit: carrier ripple​

Between two carrier peaks, a time 1/fc1/f_c apart, the output droops by the fraction

1−e−1/(fcRC)≈1fcRC1 - e^{-1/(f_c RC)} \approx \frac{1}{f_c RC}

An RCRC of 10 carrier periods leaves about 10% ripple, 20 periods about 5%, 100 periods about 1%. The ripple is a sawtooth at the carrier frequency, far above the audio band, so a small low-pass filter after the detector removes most of what is left.

The upper limit: diagonal clipping​

When the envelope falls, the capacitor can only follow it by discharging through RR. If RCRC is too long, the envelope drops faster than the capacitor, the diode stays off for many carrier cycles, and the output slides down an exponential curve that cuts across the troughs. This is diagonal clipping.

For a sine message, the envelope is A(1+mcos⁡2πWt)A(1 + m\cos 2\pi W t), with modulation depth mm between 0 and 1. Its steepest fall, compared with the voltage the capacitor holds at that moment, sets the limit:

RC≤1−m22πWmRC \le \frac{\sqrt{1 - m^2}}{2\pi W m}

Deeper modulation and higher message frequencies both tighten it. At m=0.5m = 0.5 the limit is about 0.28/W0.28/W; at m=0.8m = 0.8 it is 0.12/W0.12/W; at 100% modulation it is zero, so some clipping of the deepest troughs is unavoidable. The simulator on this page agrees with the formula. With a 1 MHz carrier, a 5 kHz message and 80% modulation, it measures no clipping at 22 µs, 0.2 mV at 24 µs and 10 mV at 26 µs, against a predicted limit of 23.9 µs.

Worked example: an AM radio detector​

A 1 MHz carrier carries audio up to W=5W = 5 kHz, at up to 80% modulation.

StepCalculationResult
Carrier period1/fc=1/(1 MHz)1/f_c = 1/(1\ \text{MHz})1 µs
Message period1/W=1/(5 kHz)1/W = 1/(5\ \text{kHz})200 µs
Diagonal-clipping limit at m=0.8m = 0.81−0.64 / (2π×5000×0.8)\sqrt{1 - 0.64}\,/\,(2\pi \times 5000 \times 0.8)23.9 µs
Choose standard partsR=10R = 10 kΩ, C=2.2C = 2.2 nFRC=22RC = 22 µs
Ripple between carrier peaks1−e−1/221 - e^{-1/22}4.4% of the level

At 22 µs the time constant is 22 carrier periods long and just inside the clipping limit. With a 1 V carrier, the simulator measures a ripple of 76 mV peak to peak at the top of the envelope (1.8 V) and no clipping. Raise CC to 3.3 nF (RC=33RC = 33 µs) and the output misses the troughs by about 67 mV.

A real diode changes the answer. With a 0.3 V Schottky diode and a 5 V carrier, the output is the envelope minus 0.3 V, so the modulation the capacitor has to follow is deeper: mm becomes 0.8×5/(5−0.3)=0.850.8 \times 5 / (5 - 0.3) = 0.85, and the limit falls to 19.6 µs. The 22 µs design now clips slightly; C=1.8C = 1.8 nF (18 µs) fixes it at the cost of a little more ripple.

In a superheterodyne radio the detector usually works at the intermediate frequency (IF), 455 kHz for AM broadcast receivers, rather than at the station's own frequency. The carrier period is then 2.2 µs, so the same 22 µs leaves about 9% ripple, and the post-detector filter matters more.

Ripple and distortion in a diode detector​

Besides ripple and diagonal clipping, a diode detector has four other faults to design around:

  • Diode drop: a silicon diode needs about 0.6 to 0.7 V before it conducts, a Schottky or germanium diode about 0.2 to 0.3 V. The output is the envelope minus that drop, troughs smaller than the drop vanish, and weak signals are lost entirely. Keep the carrier at the detector several volts high, use a low-drop diode, or use a precision detector.
  • Square-law behaviour at low level: for inputs of a few tens of millivolts, well below the drop, a diode doesn't switch on and off; it bends. The output is then proportional to the input's power (the square of its amplitude), not its amplitude. RF power detectors use this on purpose; an AM detector driven this weakly distorts the audio.
  • Negative-peak clipping: in a radio, the audio usually leaves the detector through a coupling capacitor into the next stage's input resistance RLR_L. At audio frequencies the detector then sees RR in parallel with RLR_L, a lower load than RR alone, and troughs deeper than m=(R∥RL)/Rm = (R \parallel R_L)/R are flattened. With R=10R = 10 kΩ and RL=47R_L = 47 kΩ, that is m=0.82m = 0.82. Make RLR_L much larger than RR.
  • Loading the source: a diode detector draws current only in short pulses at the carrier peaks. Balancing the power it takes from the source, V2/(2Rin)V^2/(2R_\text{in}) for a peak voltage VV, against the power dissipated in RR, V2/RV^2/R, gives an input resistance of about R/2R/2. A 10 kΩ detector loads the IF stage with about 5 kΩ.

The capacitor voltage also has a DC component proportional to the carrier's average strength. Radios separate it with a low-pass filter and use it for automatic gain control (AGC), turning the IF gain down for strong stations.

Precision and full-wave envelope detectors​

A precision envelope detector puts the diode inside an op-amp's feedback loop. The op-amp compares the output with the input and drives the diode until they match, so the diode drop at the output is divided by the op-amp's open-loop gain at the carrier frequency. It follows signals of a few millivolts that a plain diode would ignore, at the cost of an op-amp fast enough for the carrier.

A precision envelope detector: the AM input goes to the non-inverting input of an op-amp, the op-amp output drives a diode D into a capacitor C and resistor R in parallel, and the output node feeds back to the inverting input. Below, two simulated outputs for a weak AM input with a 1 V carrier and 50% modulation: a plain silicon diode with a 0.6 V drop sits well below the envelope and loses the troughs, while the precision detector follows the envelope

A full-wave envelope detector charges the capacitor on both the positive and negative half-cycles, using a diode bridge, a centre-tapped transformer or a precision full-wave rectifier (two op-amps). The capacitor is topped up twice per carrier cycle, so for the same RCRC the ripple roughly halves and moves to 2fc2f_c, further from the message. Equivalently, you can halve RCRC for the same ripple and gain more room below the diagonal-clipping limit.

Many audio and measurement circuits replace the RC discharge with separate charge and discharge time constants, set by two resistors, so the detector can rise quickly and fall slowly. Audio engineers call these the attack and release times.

Envelope detector vs synchronous detector vs Hilbert transform​

MethodHow it worksNeedsHandlesBest for
Diode envelope detectorRectify, hold on C, discharge through RA diode, a resistor and a capacitorAM with m<1m < 1 and a strong carrierAM radio, RF level detection, simple hardware
Precision envelope detectorThe same, with the diode in an op-amp loopAn op-amp fast enough for the carrierWeak signals down to millivoltsInstrumentation, audio level detection
Synchronous (product) detectorMultiply by a local copy of the carrier, then low-passA carrier recovered in frequency and phase, for example with a phase-locked loopOvermodulated AM, DSB-SC, SSB, weak signals in noiseCommunications receivers, lock-in amplifiers
Hilbert transform magnitudex2+H{x}2\sqrt{x^2 + \mathcal{H}\{x\}^2} on sampled dataDigitised samples and an FFT or FIR filterAny narrowband signal, with no carrier ripple and no lagSoftware radio, vibration analysis, ultrasound, offline analysis

The envelope detector's weaknesses are those of following peaks blindly. When AM is overmodulated (m>1m > 1), the true envelope A(1+mcos⁡2πWt)A(1 + m\cos 2\pi W t) goes negative, but a peak follower can only report its size, so the output is the folded shape A∣1+mcos⁡2πWt∣A\lvert 1 + m\cos 2\pi W t\rvert and the audio distorts. In noise, it also has a threshold: below a certain carrier-to-noise ratio the noise, not the carrier, sets the peaks and the message is lost, while a synchronous detector degrades gradually. In software, the Hilbert transform guide compares the rectify-and-low-pass envelope (the digital diode detector) with the Hilbert envelope, with measured delays.

What envelope detectors are used for​

  • AM broadcast and shortwave receivers, from crystal sets, which are a tuned circuit and a diode detector with no amplifier, to superheterodyne radios with a detector at the IF.
  • RF power and level detectors: Schottky diode detectors in their square-law region measure transmitted power and drive the power-control loops of transmitters.
  • On-off keying (OOK) and amplitude-shift keying (ASK) receivers, such as RFID tags, remote key fobs and low-power wake-up radios, where an envelope detector is cheaper and lower power than a full receiver.
  • Audio level detection in compressors, limiters, noise gates and level meters, usually with separate attack and release times.
  • Ultrasound imaging: each echo is a burst of a few megahertz, and a B-mode scanner displays its envelope as brightness (today mostly computed digitally).
  • Radar and sonar, where the envelope of each returned pulse gives its arrival time and strength.

Common envelope detector mistakes​

  • Choosing RC from the carrier alone. A long RC kills the ripple but clips the troughs. Check the upper limit at your deepest modulation and highest message frequency.
  • Ignoring the diode drop. A silicon diode on a 1 V signal loses the troughs and most of the signal. Raise the level, use a Schottky diode, or use a precision detector.
  • Forgetting the drop in the clipping limit. The drop makes the modulation at the capacitor deeper (mA/(A−VD)mA/(A - V_D)), so a design that just passes with an ideal diode can clip with a real one.
  • Loading the detector. A volume control or amplifier input of similar size to RR causes negative-peak clipping. Keep the AC load well above RR.
  • Expecting it to demodulate SSB or DSB-SC. Those signals have no carrier to follow; the envelope detector outputs the wrong waveform. Use a synchronous detector.
  • Testing with a single tone at low modulation. A design that works at 30% modulation and 1 kHz can clip at 80% and 5 kHz. Test at the deepest modulation and the highest message frequency you need.

How to simulate an envelope detector in JavaScript, React or Angular​

SciChart.js draws signals with WebGL and WebGPU, so you can re-run a circuit simulation over tens of thousands of time steps and redraw it every time a control moves. In the simulator below, the top chart shows the AM input (blue), the true envelope (dashed) and the diode detector's output (orange). The bottom chart shows the output minus the true envelope, so ripple appears as a sawtooth below zero and diagonal clipping as humps above it.

Choose the carrier frequency, the message frequency, the modulation depth and the carrier amplitude, then set R and C from standard component values. Diode switches between an ideal diode and a 0.3 V or 0.7 V forward drop, and Noise adds random noise (off by default). The readout gives RC against its two limits, the measured ripple and clipping, and a verdict. Scroll to zoom, drag to pan, double-click to reset, and hover for values.

Things to try:

  • Start from the worked example (1 MHz, 5 kHz, 80%, 10 kΩ, 2.2 nF), then move C up to 3.3 nF and watch the troughs clip.
  • Drop C to 220 pF (RC=2.2RC = 2.2 µs): the output loses about a third of its value between carrier peaks.
  • Set Diode to 0.7 V with a 1 V amplitude: the troughs drop out. Raise the amplitude to 5 V and the troughs return, but the drop now deepens the modulation enough to clip at 22 µs.
  • Set the carrier to 455 kHz with the same R and C, and compare the ripple.

Here is the code for this simulator. The circuit model is plain JavaScript; the charts are ordinary SciChart.js line series.

// Simulate a diode envelope detector (diode, then R and C in parallel) and chart it with SciChart.js
const {
SciChartSurface,
NumericAxis,
NumberRange,
EAutoRange,
FastLineRenderableSeries,
XyDataSeries,
SciChartJsNavyTheme,
CursorModifier,
LegendModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"

// --- Circuit simulation (plain JavaScript, no library needed) ---

// The diode detector, one time step dt at a time. The diode conducts only while the input is more than
// one diode drop above the capacitor voltage; then it charges C up to (input - drop). This model treats the
// diode and the source as having no resistance, so C charges instantly. Otherwise the diode is off and C
// discharges through R: the voltage falls by a factor exp(-dt / RC) each step.
// Returns the output voltage at each step, and whether the diode conducted then.
function diodeDetector(input, dt, rc, diodeDrop) {
const decay = Math.exp(-dt / rc);
const output = new Array(input.length);
const conducting = new Array(input.length);
let v = 0; // capacitor voltage, starting discharged
for (let n = 0; n < input.length; n++) {
const held = v * decay;
const charged = input[n] - diodeDrop;
conducting[n] = charged > held;
v = conducting[n] ? charged : held;
output[n] = v;
}
return { output, conducting };
}

// Measure the result: the carrier ripple (how far C droops between two charging pulses) and the
// diagonal clipping (how far the output stays above the true envelope because C can't discharge fast enough)
function measure(output, conducting, envelope, diodeDrop, amplitude) {
let rippleVolts = 0;
let ripplePercent = 0;
let clipVolts = 0;
let segmentStart = -1;
for (let n = 1; n < output.length; n++) {
// Diagonal clipping: the output sits above the envelope less the diode drop (ignoring the troughs
// that fall below the diode drop, where the output simply drops out)
const target = envelope[n] - diodeDrop;
if (target > 0.05 * amplitude) clipVolts = Math.max(clipVolts, output[n] - target);
// Ripple: each stretch with the diode off, if it lasts no more than about one carrier cycle
if (!conducting[n] && conducting[n - 1]) segmentStart = n - 1;
if (conducting[n] && !conducting[n - 1] && segmentStart >= 0) {
const length = n - 1 - segmentStart;
const peak = output[segmentStart];
if (length <= 1.5 * SAMPLES_PER_CYCLE && peak > 0.05 * amplitude) {
const droop = peak - output[n - 1];
rippleVolts = Math.max(rippleVolts, droop);
ripplePercent = Math.max(ripplePercent, (100 * droop) / peak);
}
segmentStart = -1;
}
}
return { rippleVolts, ripplePercent, clipVolts };
}

// The largest RC that still follows a sine message of depth m at messageHz:
// RC <= sqrt(1 - m^2) / (2 pi f m). Above it, the output cuts across the troughs (diagonal clipping).
// A diode drop lowers the output by the same amount at the peaks and the troughs, which makes the
// modulation the capacitor has to follow deeper: m becomes m A / (A - drop), so the limit gets tighter.
function diagonalClippingLimit(messageHz, depth, amplitude, diodeDrop) {
const m = amplitude > diodeDrop ? Math.min((depth * amplitude) / (amplitude - diodeDrop), 1) : 1;
return m > 0 ? Math.sqrt(1 - m * m) / (2 * Math.PI * messageHz * m) : Infinity;
}

// --- Chart 1: the AM input, the true envelope and the detector output ---
const top = await SciChartSurface.create(ui.signalDiv, { theme: new SciChartJsNavyTheme() });
top.sciChartSurface.xAxes.add(new NumericAxis(top.wasmContext, { axisTitle: "Time (µs)" }));
top.sciChartSurface.yAxes.add(
new NumericAxis(top.wasmContext, {
axisTitle: "Voltage (V)",
autoRange: EAutoRange.Always,
growBy: new NumberRange(0.05, 0.05)
})
);
const inputSeries = new XyDataSeries(top.wasmContext, { dataSeriesName: "AM input", dataIsSortedInX: true });
const envelopeSeries = new XyDataSeries(top.wasmContext, { dataSeriesName: "True envelope", dataIsSortedInX: true });
const outputSeries = new XyDataSeries(top.wasmContext, { dataSeriesName: "Detector output", dataIsSortedInX: true });
top.sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(top.wasmContext, { dataSeries: inputSeries, stroke: "#50C7E0", strokeThickness: 1 }),
new FastLineRenderableSeries(top.wasmContext, {
dataSeries: envelopeSeries,
stroke: "#FFFFFF",
strokeThickness: 1.5,
strokeDashArray: [6, 4]
}),
new FastLineRenderableSeries(top.wasmContext, { dataSeries: outputSeries, stroke: "#F48420", strokeThickness: 2.5 })
);
top.sciChartSurface.chartModifiers.add(
new CursorModifier({ showTooltip: true, showAxisLabels: false }),
new LegendModifier({ showCheckboxes: true }),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier()
);

// --- Chart 2: the output minus the true envelope (the detector's error), in millivolts ---
const lower = await SciChartSurface.create(ui.errorDiv, { theme: new SciChartJsNavyTheme() });
lower.sciChartSurface.xAxes.add(new NumericAxis(lower.wasmContext, { axisTitle: "Time (µs)" }));
lower.sciChartSurface.yAxes.add(
new NumericAxis(lower.wasmContext, {
axisTitle: "Error (mV)",
autoRange: EAutoRange.Always,
labelPrecision: 0,
growBy: new NumberRange(0.1, 0.1)
})
);
const errorSeries = new XyDataSeries(lower.wasmContext, {
dataSeriesName: "Output minus true envelope",
dataIsSortedInX: true
});
lower.sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(lower.wasmContext, { dataSeries: errorSeries, stroke: "#F5E663", strokeThickness: 1.5 })
);
lower.sciChartSurface.chartModifiers.add(
new CursorModifier({ showTooltip: true, showAxisLabels: false }),
new LegendModifier(),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier()
);

// --- The controls ---
const e12Value = (index, decadeStart) => E12[index % 12] * decadeStart * Math.pow(10, Math.floor(index / 12));
const formatUnit = (value, units) => {
for (const [scale, prefix] of units) {
if (value >= scale * 0.9999) {
const scaled = value / scale;
return `${scaled < 10 ? Number(scaled.toPrecision(2)) : Math.round(scaled)} ${prefix}`;
}
}
return `${value}`;
};
const ohms = (value) => formatUnit(value, [[1e3, "kΩ"], [1, "Ω"]]);
const farads = (value) => formatUnit(value, [[1e-6, "µF"], [1e-9, "nF"], [1e-12, "pF"]]);
const seconds = (value) => formatUnit(value, [[1e-3, "ms"], [1e-6, "µs"], [1e-9, "ns"]]);
const hertz = (value) => formatUnit(value, [[1e6, "MHz"], [1e3, "kHz"], [1, "Hz"]]);

function update() {
const carrierHz = Number(ui.carrierSelect.value);
const messageHz = MESSAGE_HZ[Number(ui.message.input.value)];
const depth = Number(ui.depth.input.value) / 100;
const amplitude = Number(ui.amplitudeSelect.value);
const r = e12Value(Number(ui.r.input.value), 1000); // 1 kΩ to 100 kΩ
const c = e12Value(Number(ui.c.input.value), 1e-10); // 100 pF to 100 nF
const rc = r * c;
const diodeDrop = Number(ui.diodeSelect.value);
const noiseLevel = Number(ui.noise.input.value) / 100;
ui.message.output.textContent = hertz(messageHz);
ui.depth.output.textContent = `${Math.round(depth * 100)}%`;
ui.r.output.textContent = ohms(r);
ui.c.output.textContent = farads(c);
ui.noise.output.textContent = noiseLevel > 0 ? `${Math.round(noiseLevel * 100)}%` : "off";

const { t, input, envelope, dt } = makeAmSignal(carrierHz, messageHz, depth, amplitude, noiseLevel);
const { output, conducting } = diodeDetector(input, dt, rc, diodeDrop);
const micros = t.map((time) => time * 1e6);
inputSeries.clear();
inputSeries.appendRange(micros, input);
envelopeSeries.clear();
envelopeSeries.appendRange(micros, envelope);
outputSeries.clear();
outputSeries.appendRange(micros, output);
errorSeries.clear();
errorSeries.appendRange(
micros,
output.map((v, n) => (v - envelope[n]) * 1000)
);
top.sciChartSurface.zoomExtents();
lower.sciChartSurface.zoomExtents();

// The readout: RC against its two limits, what the simulation measured, and a verdict
const limit = diagonalClippingLimit(messageHz, depth, amplitude, diodeDrop);
// Measured on the same signal without noise, so noise peaks don't count as ripple or clipping
const clean = noiseLevel > 0 ? makeAmSignal(carrierHz, messageHz, depth, amplitude, 0) : null;
const sim = clean ? diodeDetector(clean.input, dt, rc, diodeDrop) : { output, conducting };
const { rippleVolts, ripplePercent, clipVolts } = measure(sim.output, sim.conducting, envelope, diodeDrop, amplitude);
let verdict;
if (diodeDrop > 0 && amplitude * (1 - depth) < diodeDrop)
verdict = "Diode drop too large: the troughs fall below it, so the output drops out";
else if (limit === 0) verdict = "100% modulation: the output always clips close to the troughs";
else if (clipVolts > 0.01 * amplitude) verdict = "RC too long: diagonal clipping (the output misses the troughs)";
else if (ripplePercent > 10) verdict = "RC too short: large carrier ripple";
else verdict = "OK: the output follows the envelope";
ui.summary.textContent =
`RC = ${seconds(rc)} · 1/fc = ${seconds(1 / carrierHz)} · ` +
`diagonal-clipping limit ${limit === Infinity ? "none (no modulation)" : limit === 0 ? "0 (any RC clips)" : seconds(limit)} · ` +
`ripple ${(rippleVolts * 1000).toFixed(0)} mV p-p (${ripplePercent.toFixed(1)}%) · ` +
`clipping ${(Math.max(clipVolts, 0) * 1000).toFixed(0)} mV${noiseLevel > 0 ? " (measured without noise)" : ""} · ${verdict}`;
}

ui.carrierSelect.addEventListener("change", update);
ui.amplitudeSelect.addEventListener("change", update);
ui.diodeSelect.addEventListener("change", update);
for (const control of [ui.message, ui.depth, ui.r, ui.c, ui.noise]) control.input.addEventListener("input", update);
update();

Key points:

  • The circuit is the diodeDetector() function: one loop over the samples, with one multiplication and one comparison per step. The time step must be much shorter than a carrier period (the simulator uses 40 steps per cycle) so the charging happens close to each peak.
  • The model treats the diode as a switch with a fixed forward drop and charges the capacitor instantly. A real diode and source have some resistance, so the capacitor charges a little below the peak; add a series resistance to the model if that matters.
  • The input, the envelope and the output are three FastLineRenderableSeries on one chart; the error is a fourth series on a second chart. On every control change the simulator calls clear() then appendRange() on each XyDataSeries and SciChart.js redraws on the next frame.
  • On a 1 MHz carrier, two cycles of a 500 Hz message are 160,000 samples per series, and the whole simulation and redraw still follow the sliders.

See it in the demo app: JavaScript audio waveform chart · React audio waveform chart · Angular audio waveform chart. It shows live audio from your microphone as a waveform, an FFT spectrum and a spectrogram.

Go deeper: SciChart.js line chart documentation, and the Hilbert transform guide for envelope detection in software.

Frequently asked questions​

What is an envelope detector?​

An envelope detector is a circuit that follows the slowly changing peak amplitude of a fast oscillating signal and outputs that outline, the envelope, without the oscillation. The simplest one is a diode followed by a capacitor and a resistor in parallel. It demodulates AM radio and measures the level of RF, audio and ultrasound signals.

How does a diode envelope detector work?​

On each positive peak of the carrier, the diode conducts and charges the capacitor to the peak voltage. Between peaks the diode is off and the capacitor discharges slowly through the resistor. If the RC time constant is long compared with a carrier cycle but short compared with the message, the capacitor voltage follows the peaks, which is the envelope.

How do you choose R and C for an envelope detector?​

Choose the time constant RC between two limits: much longer than one carrier period, 1/fc, so the carrier ripple is small, and short enough that the capacitor can discharge as fast as the envelope falls. For a sine message of frequency W and modulation depth m, that upper limit is RC <= sqrt(1 - m^2) / (2 pi W m). For a 1 MHz carrier, 5 kHz audio and 80% modulation, the limit is about 24 microseconds, and 10 kilohms with 2.2 nanofarads (22 microseconds) works.

What is diagonal clipping in an envelope detector?​

Diagonal clipping happens when the detector's RC time constant is too long: the capacitor cannot discharge as fast as the envelope falls, so the output cuts across the troughs of the envelope in a straight-looking exponential slope instead of following them. It gets worse with deeper modulation and higher message frequencies, and is cured by a smaller RC.

What is the difference between an envelope detector and a synchronous detector?​

An envelope detector only follows the peaks of the signal, so it needs no reference and costs a diode, a resistor and a capacitor. A synchronous (product) detector multiplies the signal by a locally generated copy of the carrier and low-pass filters the result. It needs that carrier to be recovered in frequency and phase, but it also demodulates overmodulated AM, DSB-SC and SSB, and works better in noise.

How do I simulate an envelope detector in JavaScript?​

Step through the input samples with a time step dt. At each step, let the capacitor voltage decay by a factor exp(-dt / RC); if the input minus the diode drop is higher than that, the diode conducts and the capacitor voltage becomes the input minus the drop. The resulting array is the detector output. With SciChart.js, draw the input, the output and the true envelope as FastLineRenderableSeries.

Sources​

  • Haykin, S. and Moher, M. (2009), Communication Systems, 5th edition, Wiley. Amplitude modulation, the envelope detector and its time-constant limits, and coherent (synchronous) detection.
  • Horowitz, P. and Hill, W. (2015), The Art of Electronics, 3rd edition, Cambridge University Press. Precision rectifiers and peak detectors with op-amps.
  • Analog Devices, ADALM2000 Activity: Envelope Detector, StudentZone, Analog Dialogue, September 2024. A bench build of diode envelope detectors.
  • Smith, J. O., Spectral Audio Signal Processing, Center for Computer Research in Music and Acoustics (CCRMA), Stanford University. Analytic signals and envelope estimation in software.