function ee340lab9(WRIM1, WRIM2)
V  = WRIM1(:,1)';      % Line-to-line voltage 
I1 = WRIM1(:,2)';      %  Stator line current
P1 = WRIM1(:,3)';      %  Wattmeter reading W1  
P2 = WRIM1(:,4)';      %  Wattmeter reading W2 
n =  WRIM1(:,5)';      %  Speed in RPM
Pull=WRIM1(:,6)';      % Pull in Kg
% With rotor resistance
Vb  = WRIM2(:,1)';      % Line-to-line voltage 
I1b = WRIM2(:,2)';      %  Stator line current
P1b = WRIM2(:,3)';      %  Wattmeter reading W1  
P2b = WRIM2(:,4)';      %  Wattmeter reading W2 
nb =  WRIM2(:,5)';      %  Speed in RPM
Pullb=WRIM2(:,6)';      % Pull in Kg

% Calculated data          
Pi = P1+P2;              % Motor input power
T=Pull*9.81*0.305;       % Torque Eq. (7.11)
w = 2*pi*n/60;           % Speed in Rad/sec.
Po=(w.*T);               % Motor output power Eq. (8.17)
Eff = (Po./Pi*100);      % Motor efficiency 
th=atan(sqrt(3)*(P1-P2)./(P1+P2));
pf=cos(th);
ns=input('Enter the synchronous speed in RPM, ns = ');
S=((ns-n)/ns);							% Slip

Pib = P1b+P2b;              % Motor input power
Tb=Pullb*9.81*0.305;       % Torque Eq. (7.11)
wb = 2*pi*nb/60;           % Speed in Rad/sec.
Pob=(wb.*Tb);               % Motor output power Eq. (8.17)
Effb = (Pob./Pib*100);      % Motor efficiency 
thb=atan(sqrt(3)*(P1b-P2b)./(P1b+P2b));
pfb=cos(thb);
nsb=ns;
Sb=((nsb-nb)/nsb);							% Slip

fprintf('\n\n     Table I:  Measured Data, no external rotor resistance \n')

fprintf(['\n     V(V)    I_1(A)   P_1(W)      P_2(W)    n(RPM)    Pull, kg\n'])   
fprintf('%10.2f %8.2f %11.2f %10.2f %11.2f %9.2f\n', [V; I1; P1; P2; n; Pull]);  

fprintf('\n\n     Table II:  Measured Data with resistance added in the rotor circuit \n')

fprintf(['\n     V(V)    I_1(A)   P_1(W)      P_2(W)    n(RPM)    Pull, kg\n'])   
fprintf('%10.2f %8.2f %11.2f %10.2f %11.2f %9.2f\n', [Vb; I1b; P1b; P2b; nb; Pullb]);  


fprintf('\n\n  Results for the WRIM, no exteral rotor resistance \n')

fprintf(['\n   P_i(W)   T(N-m)    P_0(W)    Slip          pf          Eff\n'])
fprintf('%9.2f %9.2f %11.2f %10.3f %10.3f %10.2f\n',[Pi; T; Po; S; pf; Eff]);
% added rotor resistance
fprintf('\n\nResults for the WRIM with resistance added in the rotor circuit \n')

fprintf(['\n   P_i(W)   T(N-m)    P_0(W)    Slip          pf          Eff\n'])
fprintf('%9.2f %9.2f %11.2f %10.3f %10.3f %10.2f\n',[Pib; Tb; Pob; Sb; pfb; Effb]);


% Current and Torque Vs. Speed plots
nI= 2; nT=3;							% Poly. order for curve fitting
													% if necessary change the order  
CI=polyfit(n, I1,nI);  	% Returns polynomial coefficients for I1/n curve   
Ifit=polyval(CI, n);    % Evaluates the polynomial values for I1/n curve

nIb= 2; nTb=3;							% Poly. order for curve fitting
CIb=polyfit(nb, I1b,nIb);  	% Returns polynomial coefficients for I1/n curve   
Ifitb=polyval(CIb, nb);    % Evaluates the polynomial values for I1/n curve


figure(1), plot(n, I1, 'xr', n, Ifit, 'r', nb, I1b, 'or', nb, Ifitb, 'r')

CT=polyfit(n, T,nT);  	 	% Returns polynomial coefficients for T/n curve   
Tfit=polyval(CT, n);   	% Evaluates the polynomial values for T/n curve
CTb=polyfit(nb, Tb,nTb);  	 	% Returns polynomial coefficients for T/n curve   
Tfitb=polyval(CTb, nb);   	% Evaluates the polynomial values for T/n curve



hold on
figure(1), plot(n, T, 'xb', n, Tfit, 'b', nb, Tb, 'ob', nb, Tfitb, 'b'  )
figure(1), Legend('I_1(a)', ' ', 'I_1(b)', ' ','T(a)', ' ','T(b)', ' ',  3)
figure(1),title('Stator current and Developed Torque Vs. Speed')
figure(1), xlabel('n, RPM'), 
figure(1), ylabel('I_1 (A) & T (Nm)')
hold off
Eff=Eff/100; Effb=Effb/100;
% Pf and efficiency Vs. Speed plots
npf= 2; nE=2;							% Poly. order for curve fitting
													  % if necessary change the order  
Cpf=polyfit(n, pf,npf);  	% Returns polynomial coefficients for pf/n curve   
pffit=polyval(Cpf, n);    % Evaluates the polynomial values for pf/n curve
npfb= 2; nEb=2;							% Poly. order for curve fitting
Cpfb=polyfit(nb, pfb,npfb);  	% Returns polynomial coefficients for pf/n curve   
pffitb=polyval(Cpfb, nb);    % Evaluates the polynomial values for pf/n curve
figure(2), plot(n, pf, 'xr', n, pffit, 'r',nb, pfb, 'or', nb, pffitb, 'r')


CE=polyfit(n, Eff,nE);  	% Returns polynomial coefficients for Eff/n curve   
Efit=polyval(CE, n);     	% Evaluates the polynomial values for Eff/n curve
CEb=polyfit(nb, Effb,nEb);  	% Returns polynomial coefficients for Eff/n curve   
Efitb=polyval(CEb, nb);     	% Evaluates the polynomial values for Eff/n curve



hold on
figure(2), plot(n, Eff, 'xb', n, Efit, 'b', nb, Effb, 'ob', nb, Efitb, 'b' )
figure(2), Legend('pf(a)', ' ', 'pf(b)', ' ', 'P.U. \eta(a)',' ','P.U. \eta(b)',' ' , 3)
figure(2),title('Power factor and Per-unit Efficiency Vs. Speed')
figure(2), xlabel('n, RPM'), 
figure(2), ylabel('pf & P.U. \eta')
hold off







