Skip to main content

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.

A Bode plot in a dark navy theme: the magnitude in dB of a second-order low-pass system on top, with a resonant peak just before the corner and a dashed straight-line approximation, and its phase falling from 0 to -180 degrees below, both on a logarithmic frequency axis from 1 Hz to 1 MHz

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.

Key takeaways
  • 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, H(jω)H(j\omega), where ω=2πf\omega = 2\pi f is the angular frequency in radians per second:

H(jω)=∣H(jω)∣ e jφ(ω)H(j\omega) = |H(j\omega)| \, e^{\,j \varphi(\omega)}

The magnitude ∣H∣|H| is the gain and the angle φ\varphi is the phase. If you know a system's transfer function H(s)H(s) (its output-to-input ratio written with the Laplace variable ss), you get the frequency response by putting s=jωs = j\omega. For a resistor-capacitor (RC) low-pass filter, H(s)=1/(1+sRC)H(s) = 1/(1 + sRC) becomes H(jω)=1/(1+jωRC)H(j\omega) = 1/(1 + j\omega RC).

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 1/(1+s/ωc)1/(1 + s/\omega_c) in the transfer function's denominator: above its corner frequency ωc\omega_c 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.

A worked example Bode plot. Top: the magnitude is flat at 40 dB, 3 dB down at the 100 Hz corner, falls at 20 dB per decade to 0 dB at 10 kHz, then falls at 40 dB per decade. Bottom: the phase passes -45 degrees at 100 Hz, -90 degrees between the corners and -135 degrees at 10 kHz, heading for -180 degrees

  • 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: 20log⁡10∣H∣20 \log_{10} |H|. 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 dBAmplitude ratioPower ratio
+20 dB10100
+6 dBabout 2about 4
0 dB11
−3 dB0.7070.5 (half power)
−6 dBabout 0.5about 0.25
−20 dB0.10.01
−40 dB0.010.0001

How to draw a Bode plot by hand​

Hendrik Bode's insight, first published in a 1940 paper and set out in full 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:

  1. Factor the transfer function into a constant gain, powers of ss, and terms of the form (1+s/ωc)(1 + s/\omega_c) for real poles and zeros, or a quadratic for complex pairs.
  2. Find each corner frequency ωc\omega_c (or fc=ωc/2πf_c = \omega_c / 2\pi) and mark it on the log axis.
  3. Start at the low-frequency end with the constant gain in dB, 20log⁡10K20 \log_{10} K, plus the slope of any ss or 1/s1/s terms.
  4. Walk to the right, changing the slope at each corner by the amount in the table below.
  5. Draw the phase the same way, then correct the magnitude near each corner using the exact values.
FactorMagnitude asymptotePhase asymptoteExact value at the corner
Constant KKFlat at 20log⁡10K20 \log_{10} K0° (or ±180° if KK is negative)n/a
Zero at the origin, ss+20 dB/decade, through 0 dB at ω=1\omega = 1+90°n/a
Pole at the origin, 1/s1/s (integrator)−20 dB/decade−90°n/a
Real pole, 1/(1+s/ωc)1/(1 + s/\omega_c)0 dB, then −20 dB/decade above ωc\omega_c0° to −90°, a straight ramp from 0.1 ωc0.1\,\omega_c to 10 ωc10\,\omega_c−3 dB, −45°
Real zero, (1+s/ωc)(1 + s/\omega_c)0 dB, then +20 dB/decade above ωc\omega_c0° to +90° over the same two decades+3 dB, +45°
Complex pole pair, damping ratio ζ\zeta0 dB, then −40 dB/decade above ωn\omega_n0° to −180°, steeper as ζ\zeta falls−20log⁡10(2ζ)-20 \log_{10}(2\zeta) dB above the asymptote, −90°

Worked example: two real poles​

Take the system plotted above:

H(f)=100(1+jf100 Hz)(1+jf10 kHz)H(f) = \frac{100}{\left(1 + j\dfrac{f}{100\ \text{Hz}}\right)\left(1 + j\dfrac{f}{10\ \text{kHz}}\right)}
  • Low frequencies: the gain of 100 is 20log⁡10100=4020 \log_{10} 100 = 40 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:

FrequencyAsymptoteExact magnitudeAsymptote phaseExact phase
10 Hz40 dB39.96 dB0°−5.8°
100 Hz40 dB36.99 dB−45°−45.6°
1 kHz20 dB19.91 dB−90°−90.0°
10 kHz0 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

H(s)=ωn2s2+2ζωns+ωn2H(s) = \frac{\omega_n^2}{s^2 + 2\zeta\omega_n s + \omega_n^2}

where ωn\omega_n is the natural frequency and ζ\zeta (zeta) is the damping ratio. Filter designers often use the quality factor instead, Q=1/(2ζ)Q = 1/(2\zeta). Its straight-line magnitude is flat, then falls at 40 dB per decade from ωn\omega_n. The exact curve depends strongly on ζ\zeta:

Second-order low-pass magnitude and phase for damping ratios 0.1, 0.3, 0.707 and 1. Lower damping gives a taller peak and a sharper phase drop; the gain at the natural frequency is +14 dB for 0.1 and +4.4 dB for 0.3; every curve passes -90 degrees at the natural frequency

  • At ωn\omega_n the gain is exactly 1/(2ζ)=Q1/(2\zeta) = Q, or −20log⁡10(2ζ)-20 \log_{10}(2\zeta) dB, and the phase is −90° whatever the damping.
  • Below ζ≈0.707\zeta \approx 0.707 the response peaks before falling. With ζ=0.1\zeta = 0.1 the peak is about +14 dB, five times the input amplitude. This peak is a resonance.
  • ζ=1/2≈0.707\zeta = 1/\sqrt{2} \approx 0.707 (Q≈0.707Q \approx 0.707) is the 2nd-order Butterworth response: the flattest response with no peak, and −3 dB exactly at ωn\omega_n.
  • At ζ=1\zeta = 1 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 ωn/10ζ\omega_n / 10^{\zeta} and ωn×10ζ\omega_n \times 10^{\zeta}, which becomes a vertical step as ζ\zeta 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 L(jω)L(j\omega), 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 and cross 0 dB and −180° only once each, 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, L=4/(1+jf/fc)3L = 4/(1 + j f/f_c)^3:

  • each pole contributes −60° at f=3 fcf = \sqrt{3}\,f_c, so that is the phase crossover. There the gain is 4/84/8, so the gain margin is 20log⁡102≈6.020 \log_{10} 2 \approx 6.0 dB;
  • the gain falls to 1 (0 dB) at f≈1.23 fcf \approx 1.23\,f_c, 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, h(t)h(t), 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 h(t)h(t).

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:

H(jω)=∫−∞∞h(t) e−jωt dtH(j\omega) = \int_{-\infty}^{\infty} h(t) \, e^{-j\omega t} \, dt
Impulse response h(t)h(t)Frequency response H(jω)H(j\omega)
DomainTimeFrequency
AnswersHow does the system ring, settle and delay after a kick?How much does it pass, and shift, each frequency?
Usual chartAmplitude against timeA Bode plot (or a Nyquist plot)
RC low-pass exampleA decaying exponential, 1RCe−t/RC\frac{1}{RC} e^{-t/RC}−3 dB and −45° at fc=1/(2πRC)f_c = 1/(2\pi RC)
Digital filterThe FIR filter's coefficients, or the IIR filter's output for a single 1The 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 h(t)h(t), 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 H(f)H(f) 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 HH 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 plotNyquist plotNichols chart
AxesTwo charts: dB and degrees, each against log frequencyReal part against imaginary part, one curvedB against phase, one curve
Where frequency isOn the x axisHidden along the curveHidden along the curve
Good forReading bandwidth and slopes, sketching by hand, combining stages by addingStability of feedback loops, including open-loop unstable systemsDesigning a loop's gain and phase together, with closed-loop contours
Stability checkGain and phase marginsEncirclements of the point −1 (the Nyquist criterion)Distance from the point (0 dB, −180°)
Hard to readStability of unusual loopsExact frequencies; very large and very small gainsFrequencies; unfamiliar to most readers

What is a Nyquist plot?​

A Nyquist plot draws H(jω)H(j\omega) as a path in the complex plane as ω\omega 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 −1-1: for a loop that is stable when opened, the closed loop is stable if the path doesn't circle −1-1 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​

Most Bode plot mistakes come from the axes and units, or from reading margins off the wrong curve.

  • 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 atan2 gives 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. ω=2πf\omega = 2\pi f, 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 20log⁡1020 \log_{10}; power ratios use 10log⁡1010 \log_{10}. Applying 10log⁡1010 \log_{10} 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 ωn\omega_n.
  • 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​

This Bode plot generator computes the exact magnitude and phase of the system you choose, adds the straight-line asymptotes and key points, and redraws both panels on true logarithmic frequency axes whenever you drag a control. 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 KK 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:

// 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();

Key points:

  • Logarithmic frequency axis: a LogarithmicAxis with logBase: 10 spaces decades equally. ENumericFormat.Engineering labels them 1, 10, 100, 1K, 10K; autoTicks: false with majorDelta: 1 puts one labelled gridline on each decade. All x values must be above zero.
  • Two synchronised charts: each chart's x axis visibleRangeChanged event sets the other's visibleRange, so zooming either one zooms both, and a SciChartVerticalGroup gives both charts the same y axis width so their frequencies line up. A shared modifierGroup on the CursorModifier shows 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 XyDataSeries and calls clear() and appendRange() when a control changes. The asymptotes are a second FastLineRenderableSeries with a strokeDashArray, and the −3 dB points and crossovers are an XyScatterRenderableSeries.

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. To tune the controller in a feedback loop, see PID control.

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.
  • Bode, H. W. (1940), Relations between attenuation and phase in feedback amplifier design. Bell System Technical Journal, 19(3), pp. 421–454. The first publication of the gain-phase relations and the straight-line method.
  • 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).