clearvars
format shortEng
syms s omega
assume(omega > 0)

% i)

Amb = 10 % Considering the amplifier in the fig. 1
wp = 107e3 % From LTSPICE, the pole frequency is near that value
A = (Amb) / ( 1 + s/wp );
A = subs(A, s, j*omega); 
AmbLog = 20*log10(Amb);
HA = 20*log10(abs(A));
figure()
hold on
grid on
grid minor
fplot(HA, [1 1e9])
set(gca, 'XScale','log')
xlabel("\omega (rad/sec), log")
ylabel("|A(s)| (dB)")
title("magnitude Bode plot of the transfer function A(s)")
plot([1 1e9], [AmbLog AmbLog])
plot(wp, AmbLog-3, 'g*', 'MarkerSize', 10)
legend("|A|", "A_{DC}", "\omega_p")
hold off

% ii)

beta = 0.5; % I give it arbitrarily
A_fv = A / (1 + beta*A);
HA_fv = 20*log10(abs(A_fv));
AmbLog2 = subs(HA_fv, omega, 0);
figure()
hold on
grid on
grid minor
fplot(HA_fv, [1 1e9])
set(gca, 'XScale','log')
xlabel("\omega (rad/sec), log")
ylabel("|A_{fv}(s)| (dB)")
title("magnitude Bode plot of the transfer function A_{vf}(s)")
plot([1 1e9], [AmbLog2 AmbLog2])
wp_f = solve(HA_fv == AmbLog2-3);
plot(wp_f, AmbLog2-3, 'g*', 'MarkerSize', 10)
legend("|A_{fv}|", "A_{fv, DC}", "\omega_p")
hold off

% iii)

GBW1 = Amb*wp
Afmb = subs(A_fv, omega, 0);
GBW2 = double(Afmb*wp_f)