AC Analysis by MATLAB

Embed Size (px)

Citation preview

  • 8/2/2019 AC Analysis by MATLAB

    1/27

    AC Circuit Analysis

  • 8/2/2019 AC Analysis by MATLAB

    2/27

    Compute Z and for the circuit shown with MATLAB

    Let the given network be represented as shown in Figure below

    where Z1 = j13-j8 = j5 , and Z2 = 10 +j5 and Z3 = 20 j16

  • 8/2/2019 AC Analysis by MATLAB

    3/27

    In the circuit of Figure , and the symbols V and A inside the circles denote an AC voltmeter * and

    ammeter respectively. Assume that the ammeter has negligible internal resistance. The variable capacitor C is adjusted until

    the voltmeter reads 25 V and the ammeter 5 A. Find the value of the capacitor.

    Solution:

    Since the instruments read absolute values, we are only need to be

    concerned the magnitudes of the phasor voltage, phasor current,

    and impedance. Thus,

  • 8/2/2019 AC Analysis by MATLAB

    4/27

    For the circuit of Figure 1, find vc(t) if vs1 = 15 V, vS2 (t) = 20 cos 1000t V , and is(t) = 4cos2000t A.

    Plot vc(t) using MATLAB

    This circuit is excited by a DC (constant) voltage source, an AC (sinusoidal) voltage source, and an AC

    current source of different frequency. Therefore, we will apply the superposition principle. Let V'C be the

    capacitor voltage due to vS1 acting alone, VC the capacitor voltage due to v S2(t) acting alone, and V'Cthe capacitor voltage due to iS(t) acting alone. Then, the capacitor voltage due to all three sources acting

    simultaneously will be V = V + V' + V''.

    With the DC voltage source acting alone, after steady-state conditions have been reached the inductors

    behave like short circuits and the capacitor as an open circuit and thus the circuit is simplified as below.

    Also Voltage source short circuited while current source open circuited.

    By the voltage division expression

    Fig 1

  • 8/2/2019 AC Analysis by MATLAB

    5/27

    Next, with the sinusoidal voltage source vs2(t) acting alone the reactance's are

    By KCL

    With MATLAB

    5

    -j 2

  • 8/2/2019 AC Analysis by MATLAB

    6/27

    Finally with the sinusoidal current source is(t) acting alone the reactance's are

    By KCL

    With MATLAB

    Current source and its parallel resistance have beenreplaced with a voltage source with a series resistor

    V = Is x R = 4 x 5 = 20

  • 8/2/2019 AC Analysis by MATLAB

    7/27

    These waveforms are plotted below using the following MATLAB code:

    wt = linspace(0,2*2*pi);

    Vc1=5;

    Vc2=3.97*cos(wt-62.9*pi/180); % degree converted in radians

    Vc3 = 3.43*cos(2*wt-114.8*pi/180);

    plot(wt,Vc1,'*',wt,Vc2,'+',wt,Vc3,'x',wt,Vc1+Vc2+Vc3,'--')

  • 8/2/2019 AC Analysis by MATLAB

    8/27

    RL Circuit For an RL circuit, the voltage v(t) and i(t) are given as;

    v(t) = 10cos(377t)

    i(t) = 5cos(377t+60o) Sketch v(t) and i(t) for t = 0 to 20 milliseconds

    % RL circuit

    % current i(t) and voltage v(t) are generated; t is time

    t = 0:1E-3:20E-3;

    v = 10*cos(377*t);

    ang = (60*pi/180); % angle in radians (60 is degrees)

    i= 5*cos(377*t+ang);

    plot(t,v,'*',t,i,'o')

    title('voltage and current of an RL circuit')xlabel('sec')

    ylabel('voltage (V) and current(mA)')

    text(0.003,1.5,'v(t)'); % text command place v(t) on x and y axis respectively.

    text(0.009,2,'i(t)')

  • 8/2/2019 AC Analysis by MATLAB

    9/27

    0 0.002 0.004 0.006 0.008 0.01 0.012 0.014 0.016 0.018 0.02-10

    -8

    -6

    -4

    -2

    0

    2

    4

    6

    8

    10voltage and current of an RL circuit

    sec

    voltage(V)and

    current(mA)

    v(t)i(t)

  • 8/2/2019 AC Analysis by MATLAB

    10/27

    Compute and sketch all phasor voltages for the circuit of Figure below. Then, use MATLAB to

    plot these quantities in the t-domain

    We will begin by selecting as our reference as shown on the phasor

    diagram of Fig.

    and

    1

  • 8/2/2019 AC Analysis by MATLAB

    11/27

    below

  • 8/2/2019 AC Analysis by MATLAB

    12/27

    G=[1,0,0;-1/2,1/2-1/5j+1/3j,-1/3j;0,-1/3j,1/3j+1/5];

    % Enter all values of the I matrix

    I=[1 0 0]';

    % Compute node voltages

    V=G\I; % Got the values of V(1), V(2), V(3)

    VR1=V(1)- V(2);

    VL=V(2)- V(3);

    % Compute magnitudes and phase angles of voltages

    magV1=abs(V(1));

    magV2=abs(V(2));

    magV3=abs(V(3));

    phaseV1=angle(V(1))*180/pi;

    phaseV2=angle(V(2))*180/pi; phaseV3=angle(V(3))*180/pi;

    magVR1=abs(VR1);

    phaseVR1=angle(VR1)*180/pi;

    magVL=abs(VL);

    phaseVL=angle(VL)*180/pi;

    % Denote radian frequency as w and plot wt for 0 to2*pi range

    wt=linspace(0,2*pi);

    V1=magV1*cos(wt+phaseV1);

    V2=magV2*cos(wt+phaseV2);

    V3=magV3*cos(wt+phaseV3);

    VR1t=magVR1*cos(wt+phaseVR1);

    VLt=magVL*cos(wt+phaseVL);

    % Convert wt to degrees

    deg=wt*180/pi;

    % Print phasor voltages, magnitudes, and phase angles

    fprintf(' \n');

    % With fprintf only the real part of each parameter is processed

    so we will use disp

    disp('V1 = '); disp(V(1)); disp('V2 = '); disp(V(2));

    disp('V3 = '); disp(V(3));

    disp('VR1 = '); disp(VR1);

    disp('VL = '); disp(VL);

    fprintf('magV1 = %4.2f V \t', magV1);

    fprintf('magV2 = %4.2f V \t', magV2);

    fprintf('magV3 = %4.2f V', magV3);

    fprintf(' \n'); fprintf(' \n'); % To create a gap between mag and phase

    fprintf('phaseV1 = %4.2f deg \t', phaseV1);

    fprintf('phaseV2 = %4.2f deg \t', phaseV2);

    fprintf('phaseV3 = %4.2f deg', phaseV3);

    fprintf(' \n'); fprintf(' \n');

    fprintf('magVR1 = %4.2f V \t', magVR1); fprintf('phaseVR1 = %4.2f deg ', phaseVR1);

    fprintf(' \n'); fprintf(' \n');

    fprintf('magVL = %4.2f V \t', abs(VL));

    fprintf('phaseVL = %4.2f deg ', phaseVL);

    fprintf(' \n');

    plot(deg,V1,deg,V2,deg,V3,deg,VR1t,deg,VLt)

    fprintf(' \n');

    1

  • 8/2/2019 AC Analysis by MATLAB

    13/27

    >> phasorvoltages

    V1 =

    1

    V2 =

    0.7503 - 0.1296i V3 =

    0.4945 - 0.4263i

    VR1 =

    0.2497 + 0.1296i

    VL =

    0.2558 + 0.2967i

    magV1 = 1.00 V magV2 = 0.76 V magV3 = 0.65 V

    phaseV1 = 0.00 deg phaseV2 = -9.80 deg phaseV3 = -40.76 deg

    magVR1 = 0.28 V phaseVR1 = 27.43 deg

    magVL = 0.39 V phaseVL = 49.24 deg

    With these values we have

    vs(t) = v1(t) = coswt

    V2(t) = 0.76cos(wt-9.80)

    V3(t) = 0.65cos(wt-40.80)

    vR1(t) = 0.28cos(wt+27.40)

    VL(t) = 0.39cos(wt+49.20)

    Note: With command legend(V1,V2,V3,VR1,VL) we can put thelegend on plot

    0 50 100 150 200 250 300 350 400

    -1

    -0.8

    -0.6

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    V1

    V2

    V3

    VR1

    VL

  • 8/2/2019 AC Analysis by MATLAB

    14/27

    For the circuit of Figure 1, vs(t) = 100cos1000t V.

    Compute the average power delivered (or absorbed) by each device

    jwL = j103 x 3 x 10-3 = j3 andj/wC= -j /103 x2 x104= -j5

    The phasor equivalent circuit is shown below where

    Fig 1

    Fig 2

    Z3

    2

  • 8/2/2019 AC Analysis by MATLAB

    15/27

    MATLAB codes

  • 8/2/2019 AC Analysis by MATLAB

    16/27

    0

  • 8/2/2019 AC Analysis by MATLAB

    17/27

    Steady state AC power Figure shows an impedance with voltage

    across it given by v(t) and current throughit i(t).The instantaneous powerp(t) = v(t) i(t) ------------(1)

    If v(t) and i(t) are periodic

    with period T, the rms or

    effective values of the

    voltage and current are

    Where Vrmsand Irms is the rms value of v(t) and i(t) respectively.

    The average power dissipated by

    The one port network is

  • 8/2/2019 AC Analysis by MATLAB

    18/27

    The power factorpfis given as

    If both the current i(t) and

    voltage v(t) are both sinusoidal, i.e.

    The rms value of the voltage v(t) and current is

    The average power P is

    The power factor, pf, is

    The reactive power Q is

    The complex power, S, is

  • 8/2/2019 AC Analysis by MATLAB

    19/27

    Integration

    In order to find the integral

    The general forms of quad functions that can be used to find q

    are

    h fi if d i

  • 8/2/2019 AC Analysis by MATLAB

    20/27

    For the fig if and . Determine

    Find the average power, rms value of v(t) and the power factor using (a) analytical

    solution and (b) numerical solution

    Function files

  • 8/2/2019 AC Analysis by MATLAB

    21/27

    Function files

    (Lower codes are for function files)

    function vsq=voltage1(t) % voltage 1 This function is used to define the voltage function

    vsq=(10*cos(120*pi*t+30*pi/180)).^2; %Square of voltage and changing degree into radian also

    (Save the above codes with name voltage1 as function file)

    function isq=current1(t)

    % current1This function is used to define the current function

    isq=(6*cos(120*pi*t+60*pi/180)).^2; %Square of current and changing degree into radian also

    (Save the above codes with name current1 as function file)

    function pt = inst_pr(t)

    %inst_pr This function is used to define % instantaneous power obtained by multiplying sinusoidal voltage and current

    it = 6*cos(120*pi*t + 60*pi/180);

    vt = 10*cos(120*pi*t + 30*pi/180); pt = it.*vt;

    (Save the above codes with name inst_pr as function file)

    T=2*pi/(120*pi); % 2*pi is the period of the sine wave 120 * pi is the time period of v(t) and i(t)

  • 8/2/2019 AC Analysis by MATLAB

    22/27

    T=2 pi/(120 pi); % 2 pi is the period of the sine wave , 120 pi is the time period of v(t) and i(t)

    a = 0; % lower limit of integration

    b = T; % upper limit of integration

    x = 0:0.02:1; % Array

    t=x.*b; %Array x is multiplied to T and get points on time period

    v_int = quad('voltage1',a,b); %integration of instantaneous value

    v_rms = sqrt(v_int/b); % rms of voltage

    i_int = quad('currentl',a,b); % integration of instantaneous value

    i_rms = sqrt(i_int/b); % rms of current

    p_int =quad('inst_pr',a,b); % instantaneous value

    p_ave = p_int/b; % average power

    pf = p_ave/(i_rms*v_rms); % power factor

    % analytical solution

    p_ave_an = (60/2)*cos(30*pi/180); %Average Power is Multiplication of Vrms and Irms with difference of angle , an represent analytical

    v_rms_an = 10.0/sqrt(2);

    pf_an = cos(30*pi/180);

    % results are printed

    fprintf('Average power, analytical %f\n Average power, numerical: %f\n',p_ave_an,p_ave) fprintf('rms voltage, analytical: %f \n rms voltage, numerical: %f \n', v_rms_an, v_rms)

    fprintf('power factor, analytical: %f \n power factor, numerical: %f \n', pf_an, pf)

    Average power, analytical 25.980762

    Average power, numerical: 25.980762

    rms voltage, analytical: 7.071068

    rms voltage, numerical: 7.071068

    power factor, analytical: 0.866025

    power factor, numerical: 0.866025

  • 8/2/2019 AC Analysis by MATLAB

    23/27

    In figure, showing an unbalanced wye-wye system,

    find the phase voltages VAN, VBN and VCN

    Using KVL, we can solve for I1, I2, I3

    - -------(1)

    ---(2)

    ---(3)

    Simplifying Equations 1,2 and 3, we have

    -----(4)

    ------(5)

    -------(6)

    Expressing the above equations in matrix form

    We have

    The phase voltages can be obtained as

    The above matrix can be written as

    Polar form exponential form

  • 8/2/2019 AC Analysis by MATLAB

    24/27

    Matlab Codes

    % This program calculates the phasor voltage of

    % an unbalanced three-phase system

    % Z is impedance matrix, V is voltage vector

    % I is current vectorZ = [6-13*j 0 0;

    0 4+2*j 0;

    0 0 6-12.5*j];

    v2= 110*exp(j*pi*(-120/180)); % volt v2 In Radians

    v3 = 110*exp(j*pi*(120/180)); % In Radians

    V = [110; v2; v3]; % column voltage vector

    I =inv(Z)*V; % solve for loop currents

    %calculate the phase voltages

    Van =(5+12*j)*I(1);

    Vbn = (3+4*j)*I(2);

    Vcn = (5-12*j)*I(3);

    Van _abs = abs(Van);

    Van_ang = angle(Van)*180/pi;

    Vbn _abs = abs(Vbn);

    Vbn_ang = angle(Vbn)*180/pi;

    Vcn_abs = abs(Vcn);

    Vcn_ang = angle(Vcn)*180/pi;

    % print out results

    fprintf('phasor voltage Van,magnitude: %f \n phasor

    voltage Van, angle in degree: %f \n', Van_abs, Van_ang)

    fprintf('phasor voltage Vbn,magnitude: %f \n phasor

    voltage Vbn, angle in degree: %f \n', Vbn_abs,

    Vbn_ang)

    fprintf('phasor voltage Vcn,magnitude: %f \n phasor

    voltage Vcn, angle in degree: %f \n', Vcn_abs, Vcn_ang)

    The following results were obtained:

    phasor voltage Van, magnitude: 99.875532

    phasor voltage Van, angle in degree: 132.604994 phasor voltage Vbn, magnitude: 122.983739 phasor

    voltage Vbn, angle in degree: -93.434949

    phasor voltage Vcn, magnitude: 103.134238 phasor

    voltage Vcn, angle in degree: 116.978859

    110L-120= 110ej(-120)= 110ej(-120 x pi/180)

    Polar form exponential form

    Example of Isolation transformer

  • 8/2/2019 AC Analysis by MATLAB

    25/27

    Example of Isolation transformerFor the circuit below, find the voltage ratio V 2 / V 1

    Solution:

    The dots are given to us as shown. Now, we arbitrarily assign currents I1 &12 and

    we write mesh equations for each mesh

    With this current assignments I 2 leaves the dotted terminal of the right mesh and

    therefore the mutual voltage has a negative sign. Then,

    Mesh 1:

    R1I1+ jwL1I1 jwMI2 = V in

    ( 0.5 + j18.85) I1 j18.85I 2 = 120I_0o --------------------------------------(1)

  • 8/2/2019 AC Analysis by MATLAB

    26/27

    Mesh 2:

    jwMI 1 + jwL2 I 2 + RLOAD I 2 = 0 % w = 377 r/s

    Or

    j18.85I1 + (500 + j37.7)12 = 0 ---------------(2)

    We will find the ratio V 2 / V 1 using the MATLAB code below where

    V 1 = j w LI I1 = j18.85 I1 and V2 = I2 Rload

    MATLAB codes

    Z=[0.5+18.85j -18.85j; -18.85j 500+37.7j];

    V=[120 0]';

    I=Z\V; %It will solve I(1) and I(2)

    fprintf(' \n');

    fprintf('V1 = %7.3f V\t', abs(18.85j*I(1))); %abs of V1

    fprintf('V2 = %7.3f V \t', abs(500*I(2))); %abs of V2

    fprintf('Ratio V2/V1 = %7.3f \t', abs((500*I(2))/(18.85j*I(1))))

    MATLAB Answer

    V1 = 120.093 V V2 = 119.753 V Ratio V2/V1 = 0.997

  • 8/2/2019 AC Analysis by MATLAB

    27/27

    Thus the magnitude of Vload is practically same as the magnitude of Vin.

    However we suspect that Vload will be out of phase with Vin. We can find the

    phase of Vload by adding the following statement to the MATLAB code

    fprintf('Phase V2 = %6.2fdeg',angle(500*I(2))*180/pi)

    Answer

    Phase V2 = -0.64 deg

    This is a very small phase difference from the phase of Vin and thus we see that

    both magnitude and phase of Vload are essentially the same as that of Vin.

    If we increase the load resistance Rload to 1kwe will find that again themagnitude and phase of Vloadare essentially the same as that ofVin. Therefore, the

    transformer of this example is an isolation transformer, that is , it isolates the load

    from the source and the value of Vin appear across the load even though the load

    changes. An isolation transformer is also referred to as a 1:1 transformer.

    If in a transformer the secondary winding voltage is considerably higher than theinput voltage, the transformer is referred to as a step-up transformer. Conversely, if

    the secondary winding voltage is considerably lower than the input voltage, the

    transformer is referred to as a step-down transformer.