Skip to content

Instantly share code, notes, and snippets.

@raytroop
Created May 24, 2026 02:17
Show Gist options
  • Select an option

  • Save raytroop/69a093a3569bc12226d91b5a2022bbe9 to your computer and use it in GitHub Desktop.

Select an option

Save raytroop/69a093a3569bc12226d91b5a2022bbe9 to your computer and use it in GitHub Desktop.
clear; clc; close all;
% Parameters
wp = 1; % rad/s
% Frequency axis
w = logspace(-2, 2, 1000);
s = 1j*w;
% Transfer functions
H1 = wp ./ s; % lossless integrator
H2 = wp ./ (s + wp); % lossy integrator
% Magnitude (dB)
mag1 = 20*log10(abs(H1));
mag2 = 20*log10(abs(H2));
% Phase (deg)
ph1 = angle(H1)*180/pi;
ph2 = angle(H2)*180/pi;
% Plot
figure;
% ---------------- Magnitude ----------------
subplot(2,1,1);
semilogx(w, mag1, 'LineWidth', 2); hold on;
semilogx(w, mag2, 'LineWidth', 2);
% Vertical line at wp
xline(wp, '--k', '\omega_p', ...
'LineWidth', 1.5, ...
'LabelVerticalAlignment', 'middle');
grid on;
xlabel('\omega (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response');
legend('\omega_p/s', '\omega_p/(s+\omega_p)', ...
'Location', 'southwest');
% ---------------- Phase ----------------
subplot(2,1,2);
semilogx(w, ph1, 'LineWidth', 2); hold on;
semilogx(w, ph2, 'LineWidth', 2);
% Vertical line at wp
xline(wp, '--k', '\omega_p', ...
'LineWidth', 1.5, ...
'LabelVerticalAlignment', 'middle');
grid on;
xlabel('\omega (rad/s)');
ylabel('Phase (deg)');
title('Phase Response');
legend('\omega_p/s', '\omega_p/(s+\omega_p)', ...
'Location', 'southwest');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment