Skip to content

Instantly share code, notes, and snippets.

@haxelion
Created January 8, 2015 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxelion/04781a22911e587131d4 to your computer and use it in GitHub Desktop.
Save haxelion/04781a22911e587131d4 to your computer and use it in GitHub Desktop.
% f : frequency array
% a : amplitude array
% p : phase array
% pm : phase margin
% fp : phase margin frequency
% str : title of the plot
function phasegainplot(f, a, p, Pm, Fp, str)
figure;
subplot(2, 1, 1);
semilogx(f, a);
hold on;
plot([1, Fp], [0, 0], 'r-');
plot([Fp, Fp], [0, -60], 'r:');
title(str);
ylabel('Amplitude (dB)');
xlabel('Frequency (Hz)');
subplot(2, 1, 2);
semilogx(f, p);
hold on;
plot([Fp, Fp], [0, -180], 'r:');
plot([Fp, Fp], [Pm-180, -180], 'r-');
ylabel('Phase (deg)');
xlabel('Frequency (Hz)');
hold off;
end
data = readtable('resultats\Results\Avd_db.csv');
f = table2array(data(:, 'freq_Hz_'));
amp = table2array(data(:, 'Avd_dB_dB_'));
data = readtable('resultats\Results\Avd_phase.csv');
phase = table2array(data(:, 'Avd_phase_deg_'));
i = closest(0, amp); % function that find the index of the elemend of amp closest to 0, had to write it.
phasegainplot(f, amp, phase, phase(i)+180, f(i), 'Spectre Simulation Bode Plot');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment