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 audio from AM radio and measures RF, audio and ultrasound levels.

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.
- 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: , with the carrier frequency and the highest message frequency.
- Too short an RC leaves carrier ripple; too long an RC gives diagonal clipping, which starts above .
- 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.
- 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).
- 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.
- The resistor discharges it. Between peaks, the capacitor discharges through the resistor, falling by the factor . 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 , 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 , the time constant, sets how fast the capacitor discharges. It has to satisfy two opposing limits:
where is the carrier frequency and the highest frequency in the message (the envelope's bandwidth).
The lower limit: carrier ripple
Between two carrier peaks, a time apart, the output droops by the fraction
An 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 . If 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 , with modulation depth between 0 and 1. Its steepest fall, compared with the voltage the capacitor holds at that moment, sets the limit:
Deeper modulation and higher message frequencies both tighten it. At the limit is about ; at it is ; 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 kHz, at up to 80% modulation.
| Step | Calculation | Result |
|---|---|---|
| Carrier period | 1 µs | |
| Message period | 200 µs | |
| Diagonal-clipping limit at | 23.9 µs | |
| Choose standard parts | kΩ, nF | µs |
| Ripple between carrier peaks | 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 to 3.3 nF ( µ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: becomes , and the limit falls to 19.6 µs. The 22 µs design now clips slightly; 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.5% 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 . At audio frequencies the detector then sees in parallel with , a lower load than alone, and troughs deeper than are flattened. With kΩ and kΩ, that is . Make much larger than .
- Loading the source: a diode detector draws current only in short pulses at the carrier peaks. Balancing the power it takes from the source, for a peak voltage , against the power dissipated in , , gives an input resistance of about . 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 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 the ripple roughly halves and moves to , further from the message. Equivalently, you can halve 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
A diode detector is the simplest way to recover an envelope; a synchronous detector or a Hilbert transform copes with signals a diode can't.
| Method | How it works | Needs | Handles | Best for |
|---|---|---|---|---|
| Diode envelope detector | Rectify, hold on C, discharge through R | A diode, a resistor and a capacitor | AM with and a strong carrier | AM radio, RF level detection, simple hardware |
| Precision envelope detector | The same, with the diode in an op-amp loop | An op-amp fast enough for the carrier | Weak signals down to millivolts | Instrumentation, audio level detection |
| Synchronous (product) detector | Multiply by a local copy of the carrier, then low-pass | A carrier recovered in frequency and phase, for example with a phase-locked loop | Overmodulated AM, DSB-SC, SSB, weak signals in noise | Communications receivers, lock-in amplifiers |
| Hilbert transform magnitude | on sampled data | Digitised samples and an FFT or FIR filter | Any narrowband signal, with no carrier ripple and no lag | Software radio, vibration analysis, ultrasound, offline analysis |
The envelope detector's weaknesses are those of following peaks blindly. When AM is overmodulated (), the true envelope goes negative, but a peak follower can only report its size, so the output is the folded shape 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
Envelope detectors are used wherever the level of a fast oscillation matters more than the oscillation itself.
- 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
Most detector problems come from an RC chosen for only one of its two limits, or from ignoring the diode's forward drop.
- 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 (), 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 causes negative-peak clipping. Keep the AC load well above .
- 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
The simulator steps the diode, capacitor and resistor through two cycles of the message tone, 40 time steps per carrier cycle, and re-runs on every control change. 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 in on individual carrier cycles and see the ripple; 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 ( µ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.
- JavaScript
- React
- Angular
// 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();
import { SciChartReact } from "scichart-react";
import {
SciChartSurface,
NumericAxis,
FastLineRenderableSeries,
XyDataSeries,
SciChartJsNavyTheme,
CursorModifier,
LegendModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} from "scichart";
// A diode envelope detector, one time step at a time: charge to (input - drop) when the diode conducts,
// otherwise discharge through R by exp(-dt / RC)
const diodeDetector = (input: number[], dt: number, rc: number, diodeDrop: number) => {
const decay = Math.exp(-dt / rc);
let v = 0;
return input.map((x) => (v = Math.max(v * decay, x - diodeDrop)));
};
// initChart builds the chart; SciChartReact creates it, sizes it and cleans it up
const initChart = async (rootElement: string | HTMLDivElement) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "Time (µs)" }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: "Voltage (V)" }));
const { xValues, yValues, dt } = getYourAmSignal(); // evenly spaced samples, dt seconds apart
const output = diodeDetector(yValues, dt, 10e3 * 2.2e-9, 0.3); // R = 10 kΩ, C = 2.2 nF, Schottky diode
sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues, dataSeriesName: "AM input" }),
stroke: "#50C7E0",
strokeThickness: 1
}),
new FastLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: output, dataSeriesName: "Detector output" }),
stroke: "#F48420",
strokeThickness: 2.5
})
);
sciChartSurface.chartModifiers.add(
new CursorModifier({ showTooltip: true }),
new LegendModifier(),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier()
);
return { sciChartSurface };
};
export const EnvelopeDetectorChart = () => <SciChartReact initChart={initChart} style={{ width: "100%", height: 400 }} />;
import { Component } from "@angular/core";
import { ScichartAngularComponent } from "scichart-angular";
import {
SciChartSurface,
NumericAxis,
FastLineRenderableSeries,
XyDataSeries,
SciChartJsNavyTheme,
CursorModifier,
LegendModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier
} from "scichart";
// A diode envelope detector, one time step at a time: charge to (input - drop) when the diode conducts,
// otherwise discharge through R by exp(-dt / RC)
const diodeDetector = (input: number[], dt: number, rc: number, diodeDrop: number) => {
const decay = Math.exp(-dt / rc);
let v = 0;
return input.map((x) => (v = Math.max(v * decay, x - diodeDrop)));
};
@Component({
selector: "app-envelope-detector-chart",
standalone: true,
imports: [ScichartAngularComponent],
template: `<scichart-angular [initChart]="initChart" style="display: block; width: 100%; height: 400px"></scichart-angular>`
})
export class EnvelopeDetectorChartComponent {
// initChart builds the chart; scichart-angular creates it, sizes it and cleans it up
initChart = async (rootElement: string | HTMLDivElement) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: new SciChartJsNavyTheme()
});
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { axisTitle: "Time (µs)" }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: "Voltage (V)" }));
const { xValues, yValues, dt } = getYourAmSignal(); // evenly spaced samples, dt seconds apart
const output = diodeDetector(yValues, dt, 10e3 * 2.2e-9, 0.3); // R = 10 kΩ, C = 2.2 nF, Schottky diode
sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues, dataSeriesName: "AM input" }),
stroke: "#50C7E0",
strokeThickness: 1
}),
new FastLineRenderableSeries(wasmContext, {
dataSeries: new XyDataSeries(wasmContext, { xValues, yValues: output, dataSeriesName: "Detector output" }),
stroke: "#F48420",
strokeThickness: 2.5
})
);
sciChartSurface.chartModifiers.add(
new CursorModifier({ showTooltip: true }),
new LegendModifier(),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier()
);
return { sciChartSurface };
};
}
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
FastLineRenderableSerieson one chart; the error is a fourth series on a second chart. On every control change the simulator callsclear()thenappendRange()on eachXyDataSeriesand 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: the demo app has no envelope detector, so the closest is the JavaScript audio spectrum analyzer chart · React audio spectrum analyzer chart · Angular audio spectrum analyzer chart, which charts live microphone audio as a waveform, a spectrum and a spectrogram.
Go deeper: SciChart.js line series 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 Hilbert transform filters.