Gallery
Electronics
3 examples. Open any of them in the editor to change it.
Bode plot of an RC filter Open ↗ Code
f = logspace(1, 6, 400); % 10 Hz … 1 MHz
w = 2*pi*f;
R = 1e3; C = 100e-9; % 1 kΩ, 100 nF
H = 1 ./ sqrt(1 + (w*R*C).^2);
phase = -atan(w*R*C) * 180/pi;
fc = 1/(2*pi*R*C);
subplot(2, 1, 1)
semilogx(f, 20*log10(H), 'LineWidth', 2)
xline(fc, 'k--', sprintf('fc = %.0f Hz', fc))
yline(-3, 'k:')
ylabel('gain (dB)'), title('RC low-pass filter')
subplot(2, 1, 2)
semilogx(f, phase, 'LineWidth', 2)
xline(fc, 'k--')
yline(-45, 'k:')
ylabel('phase (°)'), xlabel('frequency (Hz)')
RLC circuit step response Open ↗ Code
% Series RLC driven by a 1 V step: under-, critically and over-damped
L = 1e-3; C = 1e-6; % 1 mH, 1 µF; critical at R = 2√(L/C) ≈ 63 Ω
for R = [10 63.2 200]
f = @(tt, x) [x(2); (1 - x(1) - R*C*x(2)) / (L*C)]; % x = [capacitor voltage; its slope]
[tt, x] = ode45(f, [0 1.5e-3], [0; 0]);
plot(tt*1e3, x(:, 1), 'LineWidth', 2, 'DisplayName', sprintf('R = %g Ω', R))
hold on
end
yline(1, 'k:')
hold off
legend show
xlabel('time (ms)'), ylabel('capacitor voltage (V)')
title('Series RLC step response')
Diode operating point (load line) Open ↗ Code
% A diode in series with 220 Ω on a 5 V supply
Is = 1e-12; nVt = 0.02585; Vs = 5; R = 220; % silicon diode, ideality factor 1
Vd = linspace(0, 0.9, 400);
plot(Vd, 1e3*Is*(exp(Vd/nVt) - 1), 'LineWidth', 2), hold on
plot(Vd, 1e3*(Vs - Vd)/R, '--', 'LineWidth', 2)
Vq = fzero(@(v) Is*(exp(v/nVt) - 1) - (Vs - v)/R, [0.3 0.9]);
Iq = (Vs - Vq)/R;
scatter(Vq, 1e3*Iq, 80, 'k', 'filled'), hold off
ylim([0 30])
legend('diode (Shockley equation)', 'load line')
xlabel('diode voltage (V)'), ylabel('current (mA)')
title(sprintf('Operating point: %.3f V, %.1f mA', Vq, 1e3*Iq))