Codes
Codes
% Transfer functions
G1 = 1/(s+7);
G2 = 1/(s^2 + 2*s + 3);
G3 = 1/(s+4);
G4 = 1/s;
G5 = 1/(s+7);
G6 = 1/(s^2 + 5*s + 10);
G7 = 3/(s+2);
H1 = 1/(s+6);
H2 = 1/s;
H3 = 1/(s+5);
% Forward paths
P1 = G1 * G2 * G6 * G7;
P2 = G1 * G3 * G5 * G7;
P3 = G1 * G3 * G4 * G6 * G7;
t
% Loop gains
L1 = G2 * G6 * H1;
L2 = G4 * H2;
L3 = G5 * H3;
L4 = G2 * G5 * H3;
L5 = G3 * G6 * H1;
L6 = G4 * G6 * H1 * H2;
%'G(s)';
%'T(s)';
ceoffLength = length(coeffVector);
rhTableColumn = ceil(ceoffLength / 2); % Correct column calculation
if rem(ceoffLength, 2) ~= 0
rhTable(2, 1:rhTableColumn - 1) = coeffVector(2:2:ceoffLength);
else
rhTable(2, :) = coeffVector(2:2:ceoffLength);
end
% Determine stability
if unstablePoles == 0
fprintf('~~~~~> It is a stable system! <~~~~~\n')
else
fprintf('~~~~~> It is an unstable system! <~~~~~\n')
end
sysRoots = roots(coeffVector);
fprintf('\nGiven polynomial coefficients roots:\n')
disp(sysRoots)
format compact
syms es e2 Rs i1 e3 R2 e1 i2 i3 k R5 R1 ed R3 R4 is e0
% STEP 1 - Use circuit analysis to write equations for the circuit.
% The circuit has 4 inputs includes es, is, ed, and ke1.
% The output is eo.
% The unknown variables are i1, i2, i3, e1, e2, and e3.
% Use KCL to write an equation for i1.
% Assume the ground is at the bottom of the circuit and use KCL to write
an equation for i3.
% Use KVL to write an equation for e1. You should use KVL because you are
relating voltages in a loop.
% Use Ohm's Law to write an equation for e2. You should use Ohm's law to
relate node voltages and loop currents.
% Use KVL to write an equation for e3. You should use KVL with Ohm's law
to related the voltages around the loop in terms of current and
resistance and voltage.
% Use Ohm's Law to write an equation for eo. Use Ohm's law to relate
voltages and currents with resistance.
% STEP 3 - Find eo/ed and set it equal to zero and then solve for k.
% Redraw the signal flow graph showing only the input ed, the gains and
the output, eo.
% Write the 2 forward paths from ed to eo.
% Use the Gain Formula for SFG to write the transfer function.
% Set the transfer function equal to zero and solve for k to minimize the
effect of the disturbance voltage.
eq3 = i3==(e3-k*e1)/R5;
eq3 = i3==(e3-k*(e2-e3))/R5;
% Use KVL to write an equation for e1. You should use KVL because you are
relating voltages in a loop.
eq4 = e1==e2-e3;
% Use Ohm's Law to write an equation for e2. You should use Ohm's law to
relate node voltages and loop currents.
eq5 = e2==R1*(i1-i2)'
% Use KVL to write an equation for e3. You should use KVL with Ohm's law
to related the voltages around the loop in terms of current and
resistance and voltage.
eq5 = e0==R5*i3
P1 = 1*(1/R5)*R5;
P2 = k
L1 = -(R2+R4)*(1/R5)
L2 = -(R3+R4)*(1/R5)
% Use the Gain Formula for SFG to write the transfer function.
eq7 = e0/ed==(P1+P2)/(1-L1)