% ECE207, Lab 6 -- Power calculations in a generator/line/load system


% Required inputs (Given load P) ------------------------------------------
Vload = 2400;   % Load voltage in RMS; take as phase reference (0 degrees)
Zline = 200 + j*75; % Line impedance
Pload = 3.7e3;  % Load power (watts)
pf = 0.8;       % Load power factor (NOTE: assumed lagging)

% Calculations ------------------------------------------------------------

% Load:
theta = acos(pf);                   % complex power angle
theta_deg = theta / (2 * pi) * 360; % power angle in degrees
Qload = Pload * tan(theta);         % reactive power
Sload = Pload + j*Qload;            % complex power

%  Line:
Iline = conj(Sload / Vload);        % line current
Pline = abs(Iline)^2 * real(Zline); % line power (loss)

% Generator:
Vgen = Vload + Iline * Zline;       % generator voltage

% System performance:
effcy = Pload/(Pload+Pline) * 100;  % efficiency
voltreg = (abs(Vgen)-abs(Vload))/abs(Vload) * 100;  % voltage regulation

% Results -----------------------------------------------------------------
disp(sprintf('\nLoad characteristics:'));
disp(sprintf('  V:  %g Vrms', Vload));
disp(sprintf('  P:  %g W', Pload));
disp(sprintf('  Q:  %g VAR', Qload));
disp(sprintf('  S:  %g /_ %gdeg = %g + j%g VA', abs(Sload), theta_deg,...
    real(Sload), imag(Sload)));
disp(sprintf('  pf: %g lagging', pf));

disp(sprintf('\nLine characteristics:'));
disp(sprintf('  I: %g /_ %gdeg Arms', abs(Iline),angle(Iline)/(2*pi)*360));
disp(sprintf('  P: %g W', Pline));

disp(sprintf('\nSystem performance:'));
disp(sprintf('  efficiency:         %g %', effcy));
disp(sprintf('  voltage regulation: %g %', voltreg));

% All done ----------------------------------------------------------------




  