analiza circuitelor cu aplicatii fiziologice

Upload: calidor

Post on 19-Oct-2015

9 views

Category:

Documents


0 download

DESCRIPTION

analiza circuitelor cu aplicatii fiziolgice

TRANSCRIPT

  • Harvard UniversityDivision of Engineering and Applied Sciences

    ES 145/215 - INTRODUCTION TO SYSTEMS ANALYSISWITH PHYSIOLOGICAL APPLICATIONS

    Fall 2001

    Lab 2: Signals and Systems with Matlab

    Introduction

    Matlab provides an interactive environment for visualizing the behavior of systems. Using matlab, wecan plot system characteristics such as frequency response and pole-zero locations as well as the responseof the system to arbitrary inputs. Matlab can also aid in the otherwise tedious calculations involved insolving system equations analytically. Matlab makes it easy to tweak parameters of the system and view thecorresponding changes in its behavior in order to better understand it.

    First Order Linear System: RC Circuit

    We will use a simple RC circuit to introduce the basic system analysis tools available in Matlab.

    Figure 1: A Simple RC Circuit

    +

    -

    Vin

    R=10K

    C=1F Vo+

    -

    For the circuit shown in figure 1 the differential equation governing the behavior of Vo for zero initialconditions is:

    1

  • dVodt

    VoRC

    0 (1)

    Using Laplace transforms, we find the transfer function of the system to be:

    H s 1

    sRC 1

    Matlab has a number of tools for analyzing transfer functions. First we must enter the values for theresistor and capacitor.

    >> R = 10e3;>> C = 1e-6;

    Next we enter the numerator and denominator of the transfer function as polynomial coefficients of s.

    >> num = 1;>> den = [R*C 1];

    We know that a general transfer function can be written in terms of its zeros, poles, and gain:

    H s k s z1 s z2 s p1 s p2

    (2)

    Given a transfer function as polynomials in s, matlab will identify the zeros, poles, and gain.

    >> [z,p,k] = tf2zp(num,den)

    For the RC circuit, tf2zp yields the following results:

    z =

    Empty matrix: 0-by-1

    p =

    -100

    k =

    100

    2

  • where z is the list of zeros of the tranfer function, which for this example is empty, p is the list of poles,and k is the gain. The reverse operation can be done with the command [num,den]=zp2tf(z,p,k). Toanalyze the various repsonse characteristics of the system, we combine the numerator and denominator intoone structure that matlab recongnizes as a trasnfer function.>> sys=tf(num,den);

    Now we are ready to analyze the system. First, we may want to plot the frequency response of the sys-tem as a Bode plot. In matlab this is done easily:

    >> [mag,phase]=bode(sys);

    Figure 2: Bode Plot for RC Circuit

    Bode Diagram

    Frequency (rad/sec)

    Phas

    e (de

    g)M

    agnit

    ude

    (dB)

    25

    20

    15

    10

    5

    0

    101 102 10390

    45

    0

    This command stores the magnitude and phase of the transfer function and produces the plots in figure2. The magnitude is stored in standard units, but plotted as decibels. We can easily convert the stored mag-nitude to decibels with the command >> magdb=20*10log(mag);. Note that in general, giving outputarguments to a matlab command will stop it from generating a plot. If you want to plot and save theoutput of a function, you will have to run the command twice.

    Next, we may want the observe the behavior of the system in response to various inputs. This is also doneeasliy in matlab. We can observe the response of the system to an impulse using the command:

    >> impulse(sys);

    Similarly, for a step input, the command step(sys); is used. Beside these common inputs, we can simulate

    3

  • the response to an arbitrary input. Suppose we want to see how the system will respond to a constant inputthat is on for 50 ms, then shuts off. We first create the time vector for which we want our input defined, thenwe create the input as a function of that time vector.

    >> t = 0:.001:.1;>> Vin=t> lsim(num,den,x,t);

    The reponse of the system to the impulse, step, and custom inputs are shown in figure 3.

    Figure 3: Response of RC Circuit to Various Inputs

    Impulse Response

    Time (sec)

    Ampl

    itude

    0 0.01 0.02 0.03 0.04 0.05 0.060

    5000

    10000

    Step Response

    Time (sec)

    Ampl

    itude

    0 0.01 0.02 0.03 0.04 0.05 0.060

    50

    100

    Linear Simulation Results

    Time (sec)

    Ampl

    itude

    0 0.02 0.04 0.06 0.08 0.1 0.120

    50

    100

    Finally, matlab can help us find the time domain solution to the differential equation by aiding in a partialfraction expansion. We know that a transfer function can be rewritten as a partial fraction expansion

    H s k s r1s p1

    r2s p2

    We can use matlab to obtain the values of k, r, and p with the residue command

    >> [r,p,k]=residue(num,den)

    4

  • Since out transfer function is already in partial fraction form, we need to create another one to test thefunction.

    >> num = [2 1];>> den = [1 2 1];>> [r,p,k]=residue(num,den)r =

    2-3

    p =

    -1-1

    k =

    []

    So we can see the partial fraction expansion of our function is:

    H s 2s 1

    s2 2s 1

    2s 1

    3s 1

    5

  • Second Order Linear System: RLC Circuit

    Now you will demonstrate your ability to analyze a more complex system. Figure 4 shows an RLC circuit.Use matlab to analyze the circuit and answer the following quesitons.

    Figure 4: An RLC Circuit

    +

    -

    Vin

    R=1

    C=1mF Vo+

    -

    L=1H

    a. Find the differential equation governing the behavior of Vo for zero initial conditions:

    d2Vodt2

    RL

    dVodt

    1LC

    VoRC

    VinLC

    (3)

    6

  • b. Using Laplace transforms, find the transfer function of the system:

    H s 1 LC

    s2

    R L s 1 LC

    c. Find the poles and zeros of the system and plot them on the provided axes.

    Figure 5: Pole-Zero Plot for RLC Circuit

    Root Locus

    Real Axis

    Imag

    Axis

    8 6 4 2 0 2 4 6 8

    80

    60

    40

    20

    0

    20

    40

    60

    80

    7

  • d. Plot the magnitude and phase of the transfer function and plot them on the provided semilog axes.

    Figure 6: Bode Plot for RLC Circuit

    Bode Diagram

    Frequency (rad/sec)

    Phas

    e (deg)

    Magn

    itude

    (dB)

    40

    20

    0

    20

    40

    100 101 102180

    135

    90

    45

    0

    e. Plot the step response of the system on the provided axes.Is the system under, critically, or overdamped?

    Figure 7: Step Response for RLC Circuit

    Step Response

    Time (sec)

    Amplit

    ude

    0 5 10 15 20 250

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    1.4

    1.6

    1.8

    2

    Underdamped.

    8

  • f. Select parameters such that the system is critcally damped. Plot the resulting step response.

    One possible arrangement is set C=1, R=2;

    Figure 8: Step Response for Critically Damped RLC Circuit

    Step Response

    Time (sec)

    Amplit

    ude

    0 5 10 150

    100

    200

    300

    400

    500

    600

    700

    800

    900

    1000

    g. Select parameters such that the system is overdamped. Plot the resulting Step response.

    One possible arrangement is changing R=20;

    Figure 9: Step Response for Overdamped RLC Circuit

    Step Response

    Time (sec)

    Amplit

    ude

    0 20 40 60 80 100 1200

    100

    200

    300

    400

    500

    600

    700

    800

    900

    1000

    9

  • h. Find the time-domain analytical expression for the step response of the overdamped circuit. Use matlabto do the partial fraction expansion.

    Depending on the parameters, solution should have the form:

    Vo t C1e at C2e bt

    1 (4)

    The Phase Plane

    Another common tool for system analysis is a phase plane plot. We can use matlab to convert our transferfunction to a state space representation of the system with the tf2ss command. The state space equationsare of the form x Ax and describe the behavior of the system from a given set of initial conditions. Fromthe state equations, we can plot the trajectories of the system in the phase plane.

    a. Using the tf2ss command, determine the values of the matrix A for the origninal underdamped RLCcircuit.

    A=[ -.5 -500 ; 1 0]

    10

  • b. We can use the inline command to define a function for matlab to evaluate. For example if want tostore the function y 2x, we would use the inline command as follows:

    >> y=inline(2*x);

    As always you can learn more about the inline command by typing >> help inline. Using inline,store the state space differential equations for the RLC circuit. Write the command you use below. Remem-ber that since the state equations are differential, your function must be of time as well as the statevariable.

    Inline input to ode solvers is not supported by earlier versions of matlab. Instead we must define our differ-ential state equation in a separate file, call it xdot.m. In this file we define the function as follows:

    function yy=xdot(t,x)yy=[-.5 -.500; 1 0]*x;

    c. Now that we have the state space equations stored, we can use one of the matlab differential equationsolvers to solve them. Use ode23 to solve the state equations up to 10 seconds, for an initial condition ofVo = 1. Write the command you used below and plot the values of your state variables vs. time on the axesprovided.

    Figure 10: Solutions to State Equations vs. Time

    0 1 2 3 4 5 6 7 8 9 101

    0.8

    0.6

    0.4

    0.2

    0

    0.2

    0.4

    0.6

    0.8

    1

    Call ode23 as follows: [t,y]=ode23(xdot,[0 10],[1 0]);Argument 1 is the file that stores the state equations. Argument 2 is the vector with the initial and final times.Argument 3 is the vector of initial conditions. The output t is the time vector the equations are evaluatedover and y is the solution vector. We can plot the solutions vs. time by plot(t,y);

    11

  • d. Use matlab to plot the solutions to the state equations in the phase plane. Plot and label the results onthe axes below.

    Figure 11: Phase Plane Plot for RLC Circuit

    1 0.8 0.6 0.4 0.2 0 0.2 0.4 0.6 0.8 10.06

    0.04

    0.02

    0

    0.02

    0.04

    0.06

    plot(y(:,1),y(:,2))

    12