Bode Plot
What is a Bode plot?
A Bode plot (pronounced "boh-dee") is a pair of charts that shows a system's frequency response: its gain in decibels on top and its phase shift in degrees below, both against frequency on a logarithmic axis. Engineers use it to read a filter's cutoff, an amplifier's bandwidth and how close a control loop is to oscillating.

The Bode plot of a second-order low-pass system: exact curves and the straight-line asymptotes you would draw by hand. Try the interactive Bode plot generator.
- A Bode plot is two charts on one log frequency axis: magnitude in dB (top) and phase in degrees (bottom).
- Each pole bends the magnitude down by 20 dB per decade and the phase by up to −90°; each zero does the opposite.
- At a single pole's corner frequency, the gain is −3 dB and the phase is −45°.
- You can sketch one by hand from straight lines, then correct by 3 dB at each corner (more near a resonance).
- In a feedback loop, the Bode plot gives the gain margin and phase margin: how far the loop is from oscillating.
What is frequency response?
Feed a sine wave into a linear, time-invariant system (a filter, an amplifier, a mass on a spring) and, once any start-up transient has died away, a sine wave comes out at the same frequency. Only two things can change: its size and its timing. The ratio of output amplitude to input amplitude is the gain (or magnitude), and the shift in timing, measured as a fraction of a cycle, is the phase.
The frequency response is that pair of numbers for every frequency. Mathematically it is one complex number per frequency, , where is the angular frequency in radians per second:
The magnitude is the gain and the angle is the phase. If you know a system's transfer function (its output-to-input ratio written with the Laplace variable ), you get the frequency response by putting . For a resistor-capacitor (RC) low-pass filter, becomes .
In mechanical testing the same idea is called a frequency response function (FRF): the ratio of a structure's measured vibration to the force applied, frequency by frequency. In audio, a "frequency response" is often just the magnitude half, shown as a curve of level against frequency for a loudspeaker, microphone or pair of headphones.
Describing a signal or system by what it does to each frequency is working in the frequency domain, as opposed to the time domain of waveforms and samples. The Fourier transform moves between the two.
How to read a Bode plot
A pole is a factor such as in the transfer function's denominator: above its corner frequency it bends the magnitude down by 20 dB per decade and moves the phase by up to −90°. A zero is the same kind of factor in the numerator, and does the opposite. The Bode plot below is for a system with a gain of 100 and two poles, at 100 Hz and 10 kHz. The solid line is the exact response; the dashed lines are the straight-line approximation explained in the next section.
- The frequency axis is logarithmic. Each major gridline is ten times the one before (a decade), so 1 Hz to 1 MHz fits in six equal steps. A doubling of frequency is an octave. The axis never reaches zero.
- The top panel is magnitude in decibels: . 0 dB means the amplitude passes unchanged, positive values mean amplification and negative values attenuation.
- The bottom panel is phase in degrees. Negative phase means the output lags the input; positive means it leads.
- Look for the corners. A corner (or break) frequency is where the slope changes. Here, the magnitude is flat up to 100 Hz, then falls at 20 dB per decade, then at 40 dB per decade above 10 kHz.
- Read the slope as a count. Every pole adds −20 dB per decade of slope and every zero adds +20, so a 40 dB per decade fall means two more poles than zeros are acting.
- Read the bandwidth at −3 dB. The frequency where the gain is 3 dB below its passband level is the usual definition of a filter's cutoff and an amplifier's bandwidth.
Decibels turn multiplication into addition, which is why the two panels can be built up piece by piece. Common values to know:
| Gain in dB | Amplitude ratio | Power ratio |
|---|---|---|
| +20 dB | 10 | 100 |
| +6 dB | about 2 | about 4 |
| 0 dB | 1 | 1 |
| −3 dB | 0.707 | 0.5 (half power) |
| −6 dB | about 0.5 | about 0.25 |
| −20 dB | 0.1 | 0.01 |
| −40 dB | 0.01 | 0.0001 |
How to draw a Bode plot by hand
Hendrik Bode's insight, set out in his 1945 book on feedback amplifiers, is that a transfer function written as a product of simple factors becomes a sum on a Bode plot, and each factor has an easy straight-line shape. To draw one:
- Factor the transfer function into a constant gain, powers of , and terms of the form for real poles and zeros, or a quadratic for complex pairs.
- Find each corner frequency (or ) and mark it on the log axis.
- Start at the low-frequency end with the constant gain in dB, , plus the slope of any or terms.
- Walk to the right, changing the slope at each corner by the amount in the table below.
- Draw the phase the same way, then correct the magnitude near each corner using the exact values.
| Factor | Magnitude asymptote | Phase asymptote | Exact value at the corner |
|---|---|---|---|
| Constant | Flat at | 0° (or ±180° if is negative) | n/a |
| Zero at the origin, | +20 dB/decade, through 0 dB at | +90° | n/a |
| Pole at the origin, (integrator) | −20 dB/decade | −90° | n/a |
| Real pole, | 0 dB, then −20 dB/decade above | 0° to −90°, a straight ramp from to | −3 dB, −45° |
| Real zero, | 0 dB, then +20 dB/decade above | 0° to +90° over the same two decades | +3 dB, +45° |
| Complex pole pair, damping ratio | 0 dB, then −40 dB/decade above | 0° to −180°, steeper as falls | dB above the asymptote, −90° |
Worked example: two real poles
Take the system plotted above:
- Low frequencies: the gain of 100 is dB, and the phase is 0°.
- First corner, 100 Hz: the line bends to −20 dB per decade. Over the two decades to 10 kHz it falls by 40 dB, reaching 0 dB.
- Second corner, 10 kHz: a second pole joins in, so the slope becomes −40 dB per decade. At 100 kHz the line is at −40 dB.
- Phase: each pole ramps by −90° over the two decades around its corner. The first ramp runs from 10 Hz to 1 kHz, the second from 1 kHz to 100 kHz, so the phase is −45° at 100 Hz, −90° at 1 kHz, −135° at 10 kHz and −180° from 100 kHz on.
Exact values from the formula:
| Frequency | Asymptote | Exact magnitude | Asymptote phase | Exact phase |
|---|---|---|---|---|
| 10 Hz | 40 dB | 39.96 dB | 0° | −5.8° |
| 100 Hz | 40 dB | 36.99 dB | −45° | −45.6° |
| 1 kHz | 20 dB | 19.91 dB | −90° | −90.0° |
| 10 kHz | 0 dB | −3.01 dB | −135° | −134.4° |
| 100 kHz | −40 dB | −40.04 dB | −180° | −174.2° |
The straight lines are within about 3 dB everywhere, and 3 dB out at the corners, so the rule "subtract 3 dB at each real pole's corner" turns a quick sketch into a good one. When two corners are close together, their corrections add up.
Second-order systems: resonance, Q and the damping ratio
A pair of complex poles, as in a mass on a spring, an RLC circuit or a second-order active filter, has the standard form
where is the natural frequency and (zeta) is the damping ratio. Filter designers often use the quality factor instead, . Its straight-line magnitude is flat, then falls at 40 dB per decade from . The exact curve depends strongly on :
- At the gain is exactly , or dB, and the phase is −90° whatever the damping.
- Below the response peaks before falling. With the peak is about +14 dB, five times the input amplitude. This peak is a resonance.
- () is the 2nd-order Butterworth response: the flattest response with no peak, and −3 dB exactly at .
- At and above the pair becomes two real poles, and the straight-line rules for real poles apply.
The phase of a complex pair turns faster when the damping is low. A common straight-line approximation ramps it from 0° to −180° between and , which becomes a vertical step as approaches 0.
Gain margin and phase margin
Control engineers use the Bode plot to check a feedback loop before building it. Plot the open-loop response , the gain all the way round the loop with the loop broken, and read two numbers:
- Gain margin: at the phase crossover frequency, where the phase reaches −180°, how far the gain is below 0 dB. It is how much more gain the loop could take before it oscillates.
- Phase margin: at the gain crossover frequency, where the gain crosses 0 dB, how far the phase is above −180°. It is how much extra lag the loop could take.
Both should be positive for a stable closed loop (for loops that are stable when opened, which covers most practical designs). A common rule of thumb in control engineering is a phase margin of 30° to 60° and a gain margin of at least 6 dB (a factor of 2). Small margins give a closed loop that rings and overshoots.
For example, take a loop of three identical poles with a gain of 4, :
- each pole contributes −60° at , so that is the phase crossover. There the gain is , so the gain margin is dB;
- the gain falls to 1 (0 dB) at , where the phase is −152.9°, so the phase margin is 27.1°: stable, but likely to ring.
Raise the gain from 4 to 8 and both margins reach zero; beyond that the closed loop is unstable.
Impulse response vs frequency response
A system's impulse response, , is its output when the input is a single very short, very tall pulse (an impulse). For a linear system it tells you everything: the output for any input is the input convolved with .
The impulse response and the frequency response are two views of the same thing. The Fourier transform of the impulse response is the frequency response:
| Impulse response | Frequency response | |
|---|---|---|
| Domain | Time | Frequency |
| Answers | How does the system ring, settle and delay after a kick? | How much does it pass, and shift, each frequency? |
| Usual chart | Amplitude against time | A Bode plot (or a Nyquist plot) |
| RC low-pass example | A decaying exponential, | −3 dB and −45° at |
| Digital filter | The FIR filter's coefficients, or the IIR filter's output for a single 1 | The Fourier transform of those samples |
Narrow in one domain means wide in the other: a short, sharp impulse response belongs to a system with a wide bandwidth, and a long, ringing one to a narrow, resonant response. In audio, an "impulse response" is a recording of a room or a guitar cabinet's , which a plug-in convolves with a dry signal to make it sound as if it were played there.
How to measure frequency response
When there is no formula, measure it. The common methods:
- Swept or stepped sine: play one sine wave at a time, measure the output's amplitude and phase against the input, and step through the frequencies. Slow, but precise and robust against noise. Frequency response analysers, and many oscilloscopes with a signal generator, draw a Bode plot this way.
- Impulse or step test and an FFT: record the response to a short pulse (or a hammer tap on a structure), then take its FFT. Quick, but a single pulse carries little energy, so the result can be noisy.
- Broadband noise or a chirp: drive the system with random noise or a fast frequency sweep, record input and output, and estimate as the cross-spectrum of input and output divided by the input's power spectrum, averaged over many blocks. The coherence function shows at which frequencies the estimate can be trusted. This is the usual method for FRFs in vibration testing.
- From a model or a digital filter: if you have the transfer function or the filter's coefficients, calculate directly.
Whichever you use, plot the result on log frequency axes. The log scale graph guide explains why a linear axis hides most of a response.
Bode plot vs Nyquist plot vs Nichols chart
All three charts show the same complex frequency response; they differ in what they make easy to read. A Nichols chart plots the gain in dB against the phase in degrees as a single curve, with frequency marked along it.
| Bode plot | Nyquist plot | Nichols chart | |
|---|---|---|---|
| Axes | Two charts: dB and degrees, each against log frequency | Real part against imaginary part, one curve | dB against phase, one curve |
| Where frequency is | On the x axis | Hidden along the curve | Hidden along the curve |
| Good for | Reading bandwidth and slopes, sketching by hand, combining stages by adding | Stability of feedback loops, including open-loop unstable systems | Designing a loop's gain and phase together, with closed-loop contours |
| Stability check | Gain and phase margins | Encirclements of the point −1 (the Nyquist criterion) | Distance from the point (0 dB, −180°) |
| Hard to read | Stability of unusual loops | Exact frequencies; very large and very small gains | Frequencies; unfamiliar to most readers |
What is a Nyquist plot?
A Nyquist plot draws as a path in the complex plane as runs from zero to infinity, usually with its mirror image for negative frequencies. Harry Nyquist's 1932 stability criterion counts how many times the open-loop path circles the point : for a loop that is stable when opened, the closed loop is stable if the path doesn't circle at all. To read one, find where the curve crosses the negative real axis (that gives the gain margin) and where it crosses the unit circle (that gives the phase margin). This is a different use of Nyquist's name from the Nyquist frequency, half the sample rate in sampled data.
Common Bode plot mistakes
- Using a linear frequency axis. Everything below a tenth of the top frequency gets squashed into the left edge, and the straight-line slopes turn into curves. Always use a log axis.
- Plotting wrapped phase. Taking the angle of the complex product with
atan2gives values between −180° and +180°, so a smooth −200° shows as a jump to +160°. Add up the phase of each factor, or unwrap the phase (add or subtract 360° at each jump), before you read margins from it. - Mixing hertz and radians per second. , so a corner at 1,000 rad/s is at 159 Hz. Many textbooks and simulation tools use rad/s; many instruments use Hz. Label the axis.
- Using 10 log for amplitude. Amplitude ratios (voltage, current, pressure, displacement) use ; power ratios use . Applying to an amplitude ratio halves every value: an amplitude ratio of 0.1 is −20 dB, not −10 dB.
- Forgetting the correction near a resonance. A lightly damped pole pair can sit 10 dB or more above its straight-line asymptote. Check the exact value at .
- Reading margins from the closed-loop response. Gain and phase margins come from the open-loop Bode plot. The closed-loop plot shows bandwidth and peaking instead.
- Trusting a measurement where the coherence is low. In noise-driven measurements, frequencies where the output barely relates to the input give a meaningless gain and phase.
How to make a Bode plot in JavaScript, React or Angular
SciChart.js draws both panels with WebGL and WebGPU on true logarithmic axes, so the plot redraws as fast as you move a slider. This Bode plot generator computes the response of the system you choose and draws the exact curves, the straight-line asymptotes and the key points. Pick a system, then drag the corner frequency and the damping (or the loop gain, for the control loop). Lower the damping and watch the error at the corner grow; choose Control loop and raise the loop gain to 8, where both margins reach zero. Hover to read values on both charts at once, scroll to zoom the frequency axis, drag to pan, and double-click to reset.
Here is the code for this example. The JavaScript tab includes the pole and zero helpers; the React and Angular tabs show the chart setup (two charts with a shared logarithmic frequency axis) for your own magnitude and phase data:
- JavaScript
- React
- Angular
// An interactive Bode plot generator: magnitude and phase of a system on a shared log frequency axis
const {
SciChartSurface,
SciChartVerticalGroup,
NumericAxis,
LogarithmicAxis,
NumberRange,
XyDataSeries,
FastLineRenderableSeries,
XyScatterRenderableSeries,
EllipsePointMarker,
VerticalLineAnnotation,
HorizontalLineAnnotation,
ELabelPlacement,
ENumericFormat,
EXyDirection,
LegendModifier,
ELegendPlacement,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier,
SciChartJsNavyTheme
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"
// --- 1. A system is a product of standard factors, H(f) = factor1 × factor2 × ... ---
// Each factor works on x = f / (its corner frequency), with s = j x:
// gain k a constant
// s^n (j x)^n: a differentiator (n = 1) or integrator (n = -1), 0 dB at its corner
// zero1, pole1 (1 + j x) and 1 / (1 + j x): a real zero or pole
// zero2, pole2 (1 - x² + j 2ζ x) and its inverse: a pair of complex zeros or poles with damping ratio ζ
// On a Bode plot, multiplying factors means adding their dB and their degrees. Adding the phases of the
// factors (rather than taking the angle of the product) also gives a phase that never wraps at ±180°.
const toDegrees = (radians) => (radians * 180) / Math.PI;
// The exact gain (dB) and phase (degrees) of one factor at frequency f
function factorExact(factor, f) {
const x = f / factor.f;
switch (factor.type) {
case "gain":
return { db: 20 * Math.log10(factor.k), deg: 0 };
case "s":
return { db: 20 * factor.n * Math.log10(x), deg: 90 * factor.n };
case "zero1":
return { db: 10 * Math.log10(1 + x * x), deg: toDegrees(Math.atan(x)) };
case "pole1":
return { db: -10 * Math.log10(1 + x * x), deg: -toDegrees(Math.atan(x)) };
default: {
// zero2 or pole2: the complex number 1 - x² + j 2ζx
const re = 1 - x * x;
const im = 2 * factor.zeta * x;
const sign = factor.type === "zero2" ? 1 : -1;
return {
db: sign * 10 * Math.log10(Math.max(re * re + im * im, 1e-12)), // floor where a notch reaches zero
deg: sign * toDegrees(Math.atan2(im, re))
};
}
}
}
// The straight-line (asymptotic) approximation of the same factor, the one you draw by hand:
// flat up to the corner then ±20 dB per decade for a real pole or zero, ±40 dB per decade for a pair.
// Phase: a real pole or zero ramps by ±90° from a decade below the corner to a decade above it;
// a pair ramps by ±180° over 10^-ζ to 10^+ζ times the corner (a sudden step when ζ = 0).
function factorAsymptote(factor, f) {
const decades = Math.log10(f / factor.f); // how many decades above the corner
const ramp = (from, to) => (from === to ? (decades < 0 ? 0 : 1) : Math.min(1, Math.max(0, (decades - from) / (to - from))));
switch (factor.type) {
case "gain":
return { db: 20 * Math.log10(factor.k), deg: 0 };
case "s":
return { db: 20 * factor.n * decades, deg: 90 * factor.n };
case "zero1":
return { db: Math.max(0, 20 * decades), deg: 90 * ramp(-1, 1) };
case "pole1":
return { db: Math.min(0, -20 * decades), deg: -90 * ramp(-1, 1) };
case "zero2":
return { db: Math.max(0, 40 * decades), deg: 180 * ramp(-factor.zeta, factor.zeta) };
default: // pole2
return { db: Math.min(0, -40 * decades), deg: -180 * ramp(-factor.zeta, factor.zeta) };
}
}
// Add up the factors at every frequency
function bode(factors, frequencies, factorFunction) {
const db = [];
const deg = [];
for (const f of frequencies) {
let sumDb = 0;
let sumDeg = 0;
for (const factor of factors) {
const r = factorFunction(factor, f);
sumDb += r.db;
sumDeg += r.deg;
}
db.push(sumDb);
deg.push(sumDeg);
}
return { db, deg };
}
// The frequencies where values cross a target level, interpolated on the log frequency scale
function crossings(frequencies, values, target) {
const found = [];
for (let i = 1; i < values.length; i++) {
const a = values[i - 1] - target;
const b = values[i] - target;
if (a === 0 || a * b < 0) {
const t = a === 0 ? 0 : a / (a - b);
found.push(frequencies[i - 1] * Math.pow(frequencies[i] / frequencies[i - 1], t));
}
}
return found;
}
const valueAt = (factors, f) => bode(factors, [f], factorExact);
// The systems in the menu. fc is the corner (or natural) frequency in Hz; shape is ζ, or K for the loop.
const systems = {
"low-pass-1": { shape: null, factors: (fc) => [{ type: "pole1", f: fc }] },
"high-pass-1": {
shape: null,
factors: (fc) => [
{ type: "s", n: 1, f: fc },
{ type: "pole1", f: fc }
]
},
"low-pass-2": { shape: "zeta", factors: (fc, zeta) => [{ type: "pole2", f: fc, zeta }] },
"band-pass": {
shape: "zeta",
factors: (fc, zeta) => [
{ type: "gain", k: 2 * zeta }, // scales the peak to exactly 0 dB at fc
{ type: "s", n: 1, f: fc },
{ type: "pole2", f: fc, zeta }
]
},
notch: {
shape: "zeta",
factors: (fc, zeta) => [
{ type: "zero2", f: fc, zeta: 0 },
{ type: "pole2", f: fc, zeta }
]
},
lead: {
shape: null,
factors: (fc) => [
{ type: "zero1", f: fc },
{ type: "pole1", f: 10 * fc }
]
},
loop: {
shape: "gain",
factors: (fc, k) => [
{ type: "gain", k },
{ type: "pole1", f: fc },
{ type: "pole1", f: fc },
{ type: "pole1", f: fc }
]
}
};
// 1,000 frequencies from 1 Hz to 1 MHz, evenly spaced on a log scale (six decades)
const frequencies = Array.from({ length: 1000 }, (_, i) => Math.pow(10, (6 * i) / 999));
// --- 2. Two charts, magnitude above phase, with the same logarithmic frequency axis ---
const theme = new SciChartJsNavyTheme();
const magnitudeChart = await SciChartSurface.create(ui.magnitudeDiv, { theme });
const phaseChart = await SciChartSurface.create(ui.phaseDiv, { theme });
const frequencyAxisOptions = {
logBase: 10,
labelFormat: ENumericFormat.Engineering, // 1, 10, 100, 1K, 10K ...
autoTicks: false, // a labelled gridline every decade, and minor gridlines between
majorDelta: 1,
minorDelta: 1,
visibleRange: new NumberRange(1, 1e6),
cursorLabelFormat: ENumericFormat.Engineering,
cursorLabelPrecision: 3
};
const magnitudeXAxis = new LogarithmicAxis(magnitudeChart.wasmContext, { ...frequencyAxisOptions, drawLabels: false });
const phaseXAxis = new LogarithmicAxis(phaseChart.wasmContext, { ...frequencyAxisOptions, axisTitle: "Frequency (Hz)" });
magnitudeChart.sciChartSurface.xAxes.add(magnitudeXAxis);
phaseChart.sciChartSurface.xAxes.add(phaseXAxis);
magnitudeChart.sciChartSurface.yAxes.add(
new NumericAxis(magnitudeChart.wasmContext, {
axisTitle: "Magnitude (dB)",
visibleRange: new NumberRange(-80, 40),
labelPrecision: 0,
cursorLabelPrecision: 1 // tooltips show one decimal place
})
);
const phaseYAxis = new NumericAxis(phaseChart.wasmContext, {
axisTitle: "Phase (°)",
labelPrecision: 0,
cursorLabelPrecision: 1,
autoTicks: false,
majorDelta: 45,
minorDelta: 15
});
phaseChart.sciChartSurface.yAxes.add(phaseYAxis);
// Keep the two frequency axes in step when either chart is zoomed or panned,
// and give both charts the same y axis width, so their frequencies line up
magnitudeXAxis.visibleRangeChanged.subscribe((args) => (phaseXAxis.visibleRange = args.visibleRange));
phaseXAxis.visibleRangeChanged.subscribe((args) => (magnitudeXAxis.visibleRange = args.visibleRange));
const verticalGroup = new SciChartVerticalGroup();
verticalGroup.addSurfaceToGroup(magnitudeChart.sciChartSurface);
verticalGroup.addSurfaceToGroup(phaseChart.sciChartSurface);
// On each chart: the exact response, the straight-line asymptotes, and markers for the key points
function addSeries(chart, name) {
const exact = new XyDataSeries(chart.wasmContext, { dataSeriesName: name });
const asymptote = new XyDataSeries(chart.wasmContext, { dataSeriesName: "Straight-line asymptotes" });
const points = new XyDataSeries(chart.wasmContext, { dataSeriesName: "Key points" });
chart.sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(chart.wasmContext, { dataSeries: exact, stroke: "#50C7E0", strokeThickness: 3 }),
new FastLineRenderableSeries(chart.wasmContext, {
dataSeries: asymptote,
stroke: "#F48420",
strokeThickness: 2,
strokeDashArray: [8, 5]
}),
new XyScatterRenderableSeries(chart.wasmContext, {
dataSeries: points,
pointMarker: new EllipsePointMarker(chart.wasmContext, {
width: 11,
height: 11,
fill: "#FFFFFF",
stroke: "#F48420",
strokeThickness: 2
})
})
);
return { exact, asymptote, points };
}
const magnitude = addSeries(magnitudeChart, "Exact magnitude");
const phase = addSeries(phaseChart, "Exact phase");
// Mark the corner frequency on both charts, -3 dB and 0 dB on the magnitude chart, and -180° on the phase chart
const cornerLines = [magnitudeChart, phaseChart].map((chart) => {
const line = new VerticalLineAnnotation({
x1: 1000,
stroke: "#FFFFFF88",
strokeDashArray: [2, 4],
showLabel: chart === magnitudeChart,
labelPlacement: ELabelPlacement.TopRight
});
chart.sciChartSurface.annotations.add(line);
return line;
});
const minus3dB = new HorizontalLineAnnotation({
y1: -3,
stroke: "#FFFFFF66",
strokeDashArray: [2, 4],
showLabel: true,
labelValue: "-3 dB",
labelPlacement: ELabelPlacement.BottomRight
});
const zeroDb = new HorizontalLineAnnotation({ y1: 0, stroke: "#FFFFFF66", strokeDashArray: [2, 4] });
const minus180 = new HorizontalLineAnnotation({
y1: -180,
stroke: "#FFFFFF66",
strokeDashArray: [2, 4],
showLabel: true,
labelValue: "-180°",
labelPlacement: ELabelPlacement.TopLeft
});
magnitudeChart.sciChartSurface.annotations.add(minus3dB, zeroDb);
phaseChart.sciChartSurface.annotations.add(minus180);
// Hover for values on both charts at once, scroll to zoom the frequency axis, drag to pan, double-click to reset
for (const chart of [magnitudeChart, phaseChart]) {
chart.sciChartSurface.chartModifiers.add(
new CursorModifier({ modifierGroup: "bode", showTooltip: true, showAxisLabels: false }),
new MouseWheelZoomModifier({ xyDirection: EXyDirection.XDirection }),
new ZoomPanModifier({ xyDirection: EXyDirection.XDirection }),
new ZoomExtentsModifier({ xyDirection: EXyDirection.XDirection })
);
}
magnitudeChart.sciChartSurface.chartModifiers.add(
new LegendModifier({ showCheckboxes: true, placement: ELegendPlacement.TopLeft })
);
// --- 3. Recalculate and redraw whenever a control changes ---
// The corner slider runs from 10 Hz to 10 kHz on a log scale; ζ from 0.05 to 1.5; K from 1 to 20
const sliderToCorner = (value) => 10 * Math.pow(1000, value / 100);
const shapes = {
zeta: { name: "Damping ζ", from: 0.05, to: 1.5, start: 0.2 },
gain: { name: "Loop gain K", from: 1, to: 20, start: 4 }
};
const sliderToShape = (shape, value) => shape.from * Math.pow(shape.to / shape.from, value / 100);
const shapeToSlider = (shape, x) => (100 * Math.log(x / shape.from)) / Math.log(shape.to / shape.from);
const hz = (f) => (f >= 1000 ? `${(f / 1000).toPrecision(3)} kHz` : `${f.toPrecision(3)} Hz`);
function setUpShapeSlider() {
const shape = shapes[systems[ui.systemSelect.value].shape];
ui.shapeInput.disabled = !shape;
ui.shapeInput.parentElement.style.opacity = shape ? "1" : "0.4";
ui.shapeName.textContent = shape ? shape.name : "Damping ζ";
if (shape) ui.shapeInput.value = shapeToSlider(shape, shape.start).toFixed(1);
}
function update() {
const name = ui.systemSelect.value;
const system = systems[name];
const fc = sliderToCorner(Number(ui.cornerInput.value));
const shape = shapes[system.shape];
const shapeValue = shape ? sliderToShape(shape, Number(ui.shapeInput.value)) : 0;
const factors = system.factors(fc, shapeValue);
// Add the corner itself, so the curve passes exactly through it (and a notch reaches its true depth)
const fs = frequencies.filter((f) => f !== fc).concat(fc).sort((a, b) => a - b);
const exact = bode(factors, fs, factorExact);
const asymptote = bode(factors, fs, factorAsymptote);
magnitude.exact.clear();
magnitude.exact.appendRange(fs, exact.db);
magnitude.asymptote.clear();
magnitude.asymptote.appendRange(fs, asymptote.db);
phase.exact.clear();
phase.exact.appendRange(fs, exact.deg);
phase.asymptote.clear();
phase.asymptote.appendRange(fs, asymptote.deg);
// Fit the phase axis to the curves, in steps of 45°
const allPhases = exact.deg.concat(asymptote.deg);
const low = Math.floor(Math.min(...allPhases) / 45) * 45 - 15;
const high = Math.ceil(Math.max(...allPhases) / 45) * 45 + 15;
phaseYAxis.visibleRange = new NumberRange(low, high);
// The key points and the summary line
let points = [];
let text = "";
if (name === "loop") {
// Gain margin: how far below 0 dB the gain is where the phase reaches -180°.
// Phase margin: how far above -180° the phase is where the gain crosses 0 dB.
const gainCrossover = crossings(fs, exact.db, 0)[0];
const phaseCrossover = crossings(fs, exact.deg, -180)[0];
points = [gainCrossover, phaseCrossover].filter((f) => f !== undefined);
const gainMargin = phaseCrossover === undefined ? Infinity : -valueAt(factors, phaseCrossover).db[0];
const phaseMargin = gainCrossover === undefined ? Infinity : 180 + valueAt(factors, gainCrossover).deg[0];
text =
`gain margin ${gainMargin.toFixed(1)} dB · phase margin ${phaseMargin.toFixed(1)}°` +
(gainMargin > 0 && phaseMargin > 0 ? " · stable when the loop is closed" : " · unstable when the loop is closed");
} else if (name === "lead") {
const fMax = Math.sqrt(10) * fc; // the most phase lead is midway between the zero and the pole
points = [fMax];
text = `zero at ${hz(fc)}, pole at ${hz(10 * fc)} · most phase lead ${valueAt(factors, fMax).deg[0].toFixed(1)}° at ${hz(fMax)}`;
} else {
points = crossings(fs, exact.db, -3.0103); // the -3 dB (half-power) points
const at = points.map((f) => `${hz(f)} (${valueAt(factors, f).deg[0].toFixed(1)}°)`);
text = `-3 dB at ${at.join(" and ")}`;
if (points.length === 2) text += ` · bandwidth ${hz(points[1] - points[0])}`;
if (name === "low-pass-2") {
const peak = Math.max(...exact.db);
text += ` · Q = ${(1 / (2 * shapeValue)).toFixed(2)}` + (peak > 0.05 ? ` · peak +${peak.toFixed(1)} dB` : "");
}
}
const pointValues = bode(factors, points, factorExact);
magnitude.points.clear();
magnitude.points.appendRange(points, pointValues.db);
phase.points.clear();
phase.points.appendRange(points, pointValues.deg);
ui.summary.textContent = text;
// Annotations for this system
for (const line of cornerLines) {
line.x1 = fc;
line.labelValue = `corner ${hz(fc)}`;
}
minus3dB.isHidden = name === "loop" || name === "lead";
zeroDb.isHidden = name !== "loop";
minus180.isHidden = name !== "loop";
ui.cornerOutput.textContent = hz(fc);
ui.cornerInput.setAttribute("aria-valuetext", hz(fc).replace("Hz", "hertz"));
ui.shapeOutput.textContent = !shape ? "-" : system.shape === "zeta" ? `${shapeValue.toFixed(2)} (Q = ${(1 / (2 * shapeValue)).toFixed(2)})` : shapeValue.toFixed(1);
}
ui.systemSelect.addEventListener("change", () => {
setUpShapeSlider();
update();
});
ui.cornerInput.addEventListener("input", update);
ui.shapeInput.addEventListener("input", update);
setUpShapeSlider();
update();
import { SciChartReact } from "scichart-react";
import {
SciChartSurface,
SciChartVerticalGroup,
NumericAxis,
LogarithmicAxis,
NumberRange,
ENumericFormat,
EXyDirection,
XyDataSeries,
FastLineRenderableSeries,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier,
SciChartJsNavyTheme
} from "scichart";
// One chart of the pair: a log frequency axis and a y axis
const createPanel = async (div: HTMLDivElement, yTitle: string, showFrequencyLabels: boolean) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(div, { theme: new SciChartJsNavyTheme() });
const xAxis = new LogarithmicAxis(wasmContext, {
logBase: 10,
labelFormat: ENumericFormat.Engineering,
axisTitle: showFrequencyLabels ? "Frequency (Hz)" : undefined,
drawLabels: showFrequencyLabels
});
sciChartSurface.xAxes.add(xAxis);
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: yTitle, growBy: new NumberRange(0.1, 0.1) }));
sciChartSurface.chartModifiers.add(
new CursorModifier({ modifierGroup: "bode", showTooltip: true }),
new MouseWheelZoomModifier({ xyDirection: EXyDirection.XDirection }),
new ZoomPanModifier({ xyDirection: EXyDirection.XDirection }),
new ZoomExtentsModifier({ xyDirection: EXyDirection.XDirection })
);
return { wasmContext, sciChartSurface, xAxis };
};
// initChart builds both charts inside one element; SciChartReact sizes it and cleans it up
const initChart = async (rootElement: string | HTMLDivElement) => {
const root = rootElement as HTMLDivElement;
const [magnitudeDiv, phaseDiv] = [document.createElement("div"), document.createElement("div")];
root.style.display = "flex";
root.style.flexDirection = "column";
magnitudeDiv.style.flex = phaseDiv.style.flex = "1";
root.append(magnitudeDiv, phaseDiv);
const magnitude = await createPanel(magnitudeDiv, "Magnitude (dB)", false);
const phase = await createPanel(phaseDiv, "Phase (°)", true);
// Your frequencies (Hz, all above 0) with the gain in dB and phase in degrees at each
const { frequencies, gainDb, phaseDeg } = getYourFrequencyResponse();
for (const [panel, values] of [[magnitude, gainDb], [phase, phaseDeg]] as const) {
panel.sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(panel.wasmContext, {
dataSeries: new XyDataSeries(panel.wasmContext, { xValues: frequencies, yValues: values }),
stroke: "#50C7E0",
strokeThickness: 3
})
);
}
// Zoom and pan the two frequency axes together, and line the charts up
magnitude.xAxis.visibleRangeChanged.subscribe((args) => (phase.xAxis.visibleRange = args.visibleRange));
phase.xAxis.visibleRangeChanged.subscribe((args) => (magnitude.xAxis.visibleRange = args.visibleRange));
const group = new SciChartVerticalGroup();
group.addSurfaceToGroup(magnitude.sciChartSurface);
group.addSurfaceToGroup(phase.sciChartSurface);
magnitude.sciChartSurface.addDeletable(phase.sciChartSurface); // delete both charts together
return { sciChartSurface: magnitude.sciChartSurface };
};
export const BodePlot = () => <SciChartReact initChart={initChart} style={{ width: "100%", height: 600 }} />;
import { Component } from "@angular/core";
import { ScichartAngularComponent } from "scichart-angular";
import {
SciChartSurface,
SciChartVerticalGroup,
NumericAxis,
LogarithmicAxis,
NumberRange,
ENumericFormat,
EXyDirection,
XyDataSeries,
FastLineRenderableSeries,
CursorModifier,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier,
SciChartJsNavyTheme
} from "scichart";
// One chart of the pair: a log frequency axis and a y axis
const createPanel = async (div: HTMLDivElement, yTitle: string, showFrequencyLabels: boolean) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(div, { theme: new SciChartJsNavyTheme() });
const xAxis = new LogarithmicAxis(wasmContext, {
logBase: 10,
labelFormat: ENumericFormat.Engineering,
axisTitle: showFrequencyLabels ? "Frequency (Hz)" : undefined,
drawLabels: showFrequencyLabels
});
sciChartSurface.xAxes.add(xAxis);
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { axisTitle: yTitle, growBy: new NumberRange(0.1, 0.1) }));
sciChartSurface.chartModifiers.add(
new CursorModifier({ modifierGroup: "bode", showTooltip: true }),
new MouseWheelZoomModifier({ xyDirection: EXyDirection.XDirection }),
new ZoomPanModifier({ xyDirection: EXyDirection.XDirection }),
new ZoomExtentsModifier({ xyDirection: EXyDirection.XDirection })
);
return { wasmContext, sciChartSurface, xAxis };
};
@Component({
selector: "app-bode-plot",
standalone: true,
imports: [ScichartAngularComponent],
template: `<scichart-angular [initChart]="initChart" style="display: block; width: 100%; height: 600px"></scichart-angular>`
})
export class BodePlotComponent {
// initChart builds both charts inside one element; scichart-angular sizes it and cleans it up
initChart = async (rootElement: string | HTMLDivElement) => {
const root = rootElement as HTMLDivElement;
const [magnitudeDiv, phaseDiv] = [document.createElement("div"), document.createElement("div")];
root.style.display = "flex";
root.style.flexDirection = "column";
magnitudeDiv.style.flex = phaseDiv.style.flex = "1";
root.append(magnitudeDiv, phaseDiv);
const magnitude = await createPanel(magnitudeDiv, "Magnitude (dB)", false);
const phase = await createPanel(phaseDiv, "Phase (°)", true);
// Your frequencies (Hz, all above 0) with the gain in dB and phase in degrees at each
const { frequencies, gainDb, phaseDeg } = getYourFrequencyResponse();
for (const [panel, values] of [[magnitude, gainDb], [phase, phaseDeg]] as const) {
panel.sciChartSurface.renderableSeries.add(
new FastLineRenderableSeries(panel.wasmContext, {
dataSeries: new XyDataSeries(panel.wasmContext, { xValues: frequencies, yValues: values }),
stroke: "#50C7E0",
strokeThickness: 3
})
);
}
// Zoom and pan the two frequency axes together, and line the charts up
magnitude.xAxis.visibleRangeChanged.subscribe((args) => (phase.xAxis.visibleRange = args.visibleRange));
phase.xAxis.visibleRangeChanged.subscribe((args) => (magnitude.xAxis.visibleRange = args.visibleRange));
const group = new SciChartVerticalGroup();
group.addSurfaceToGroup(magnitude.sciChartSurface);
group.addSurfaceToGroup(phase.sciChartSurface);
magnitude.sciChartSurface.addDeletable(phase.sciChartSurface); // delete both charts together
return { sciChartSurface: magnitude.sciChartSurface };
};
}
Key points:
- Logarithmic frequency axis: a LogarithmicAxis with
logBase: 10spaces decades equally.ENumericFormat.Engineeringlabels them 1, 10, 100, 1K, 10K;autoTicks: falsewithmajorDelta: 1puts one labelled gridline on each decade. All x values must be above zero. - Two synchronised charts: each chart's x axis
visibleRangeChangedevent sets the other'svisibleRange, so zooming either one zooms both, and a SciChartVerticalGroup gives both charts the same y axis width so their frequencies line up. A sharedmodifierGroupon theCursorModifiershows the crosshair and tooltip on both charts at once. - The maths is plain JavaScript: each factor (gain, pole, zero, complex pair) returns its dB and degrees, and the totals are sums. Adding the phases of the factors gives a continuous phase with no ±180° wrapping.
- Live updates: the demo keeps each
XyDataSeriesand callsclear()andappendRange()when a control changes. The asymptotes are a secondFastLineRenderableSerieswith astrokeDashArray, and the −3 dB points and crossovers are anXyScatterRenderableSeries.
See it in the demo app: JavaScript chart with a logarithmic axis · React chart with a logarithmic axis · Angular chart with a logarithmic axis. For a live spectrum, see the JavaScript audio analyzer.
Go deeper: SciChart.js logarithmic axis documentation, synchronizing multiple charts, the log scale graph guide, and the filter guides in this section: low-pass filter and high-pass filter, whose live demos each draw a filter's frequency response.
Frequently asked questions
What is a Bode plot used for?
A Bode plot shows how a system treats each frequency: how much it amplifies or attenuates it, and how far it shifts it in time (the phase). Engineers use it to see a filter's cutoff and roll-off, an amplifier's bandwidth, a loudspeaker's or sensor's useful range, and how close a feedback control loop is to instability (its gain and phase margins).
How do you read a Bode plot?
Read across the log frequency axis, where each gridline is ten times the last. The top panel gives the gain in decibels: 0 dB means unchanged, −20 dB means one tenth of the amplitude. The bottom panel gives the phase in degrees: negative means the output lags the input. Corners are where the slope changes; the slope tells you how many poles or zeros are acting, at 20 dB per decade each.
What does −20 dB per decade mean?
It means the gain falls by 20 dB, a factor of ten in amplitude, every time the frequency rises tenfold. It is the slope of one pole, such as a first-order RC low-pass filter above its cutoff. It is the same as about −6 dB per octave (each doubling of frequency). Two poles give −40 dB per decade, three give −60, and so on.
What is the difference between a Bode plot and a Nyquist plot?
Both show the same frequency response. A Bode plot uses two charts, gain in dB and phase in degrees, each against log frequency, so frequency is easy to read and the shape can be sketched by hand. A Nyquist plot draws the response as one curve in the complex plane, real part against imaginary part, with frequency hidden along the curve. Its loops around the point −1 tell you whether a feedback loop is stable.
What is the difference between impulse response and frequency response?
They describe the same linear system in two domains. The impulse response is the output over time when the input is a single, very short pulse. The frequency response is the gain and phase the system applies to a sine wave at each frequency. The Fourier transform of the impulse response is the frequency response, and the inverse transform takes you back.
How do I make a Bode plot in JavaScript?
Compute the magnitude in dB and the phase in degrees of your transfer function at a few hundred frequencies spaced evenly on a log scale, then plot them on two charts that share a logarithmic frequency axis. In SciChart.js, use a LogarithmicAxis for frequency on both charts, keep their visible ranges in step with visibleRangeChanged, and line them up with a SciChartVerticalGroup.
Sources
- Bode, H. W. (1945), Network Analysis and Feedback Amplifier Design, Van Nostrand. The origin of the gain-phase plot, the straight-line approximations and the gain and phase margins.
- Nyquist, H. (1932), "Regeneration Theory", Bell System Technical Journal, 11(1), pp. 126–147. The Nyquist stability criterion.
- Ogata, K. (2010), Modern Control Engineering, 5th edition, Prentice Hall. Bode, Nyquist and Nichols plots; gain and phase margins.
- Oppenheim, A. V. and Willsky, A. S. (1997), Signals and Systems, 2nd edition, Prentice Hall; lectures on MIT OpenCourseWare, RES.6-007. Frequency response, impulse response and Bode plots of first- and second-order systems.
- Bendat, J. S. and Piersol, A. G. (2010), Random Data: Analysis and Measurement Procedures, 4th edition, Wiley. Measuring frequency response functions from noise, and the coherence function.
- Smith, S. W. (1997), The Scientist and Engineer's Guide to Digital Signal Processing, California Technical Publishing. Chapters 5 (linear systems), 6 (convolution) and 14 (introduction to digital filters, including the frequency response).