# E12 Assignment 06

Description:

Problems:
1. Circuit Transfer Function and Analog

a) For the circuit shown, find the transfer function Eout(s)/Ein(s).

b) Show it is of the same form as the transfer function (Xout(s)/Xin(s)) of the mechanical system shown.  Take xout(t)=0 at equilibrium (i.e., ignore gravity).  The two transfer functions should have similar polynomials in numerator and denominator, only the constant coefficients will differ.

Solution:

a) Use voltage divider

b) Use FBD

2. e12negFeedback

Which of the following represent positive feedback, and which negative?  Remember with negative feedback, if there is any change, the system acts in a direction that opposes that change; it acts to keep the system output constant.  Positive feedback amplifies any disturbance.

1. An eye for an eye; or Do unto others as you would have them do unto you.
2. One good turn deserves another.
3. The squeaky wheel gets the grease.
4. You learn from your mistakes.
5. The rich get richer – the poor get poorer.
6. Imagine you run a restaurant where drinks are in a cooler and patrons help themselves.  You would like to maintain a good variety.  You implement a system in which you see what drinks are in the cooler and order more in proportion to the ones that are present.
7. Imagine you run a restaurant where drinks are in a cooler and patrons help themselves.  You would like to maintain a good variety.  You implement a system in which you see what drinks are in the cooler and order more in inverse proportion to the ones that are present.
8. When you eat and your blood sugar increases, insulin is released which starts the process of metabolizing the glucose.
9. Come up with your own example of positive feedback.
10. Come up with your own example of negative feedback
Solution:
1. +'ve
2. +'ve
3. -'ve
4. -'ve
5. +'ve
6. +'ve
7. -'ve
8. -'ve
9. +'ve
10. -'ve
3. Lowpass opamp - inner ear analog

This circuit in this problem has an ideal op-amp with negative feedback.  you may make assumptions accordingly.

For the circuit shown uses the standard inverting configuration with an input impedance (Ri and Li in series) and a feedback impedance (Rf and C in parallel).  (What is the transfer function (i.e., gain) of the inverting configuration with feedback impedance Zf and input impedance Zi?)

a) Find the transfer function H(s)=Eout(s)/Ein(s).  Write H(s) in the form of a ratio of polynomials in positive powers of s.   If Ri=10kΩ, Rf=10kΩ, L=100000H, C=0.5μF the resulting system is highly overdamped (two real roots that are very unequal) and equal to

b) Using the results from part "a" find an expression for the impulse response of the system (use any method to do so).

c) What are the two time constants associated with the system?

d) Plot the impulse response for 50 seconds (either use your expression, or MATLAB's "impulse" command).  Use the time vector "t=linspace(0,50,100000);" (i.e, 0.5 mSec resolution) in your plot.  Turn in two plots, one for the first 50 mSec (0.05 Sec), and one for the entire 50 seconds.  (You can easily set the limits of the x-axis of the current graph to 0.05 Sec with "set(gca,'XLim',[0 0.05]);"  (this gets current axis ("gca") and sets the "XLim" (x limits) property).  Explain the shapes of the two plots in light of the two time constants of the system.

Solution:

a)   We will calculate the feedback and input impedance use the fact that the gain (i.e., transfer function) of the inverting configuration is -Zf/Zi.

```>> syms Ri Rf C L s
>> Zf = Rf/(s*C)/(Rf + 1/(s*C))  % Parallel feedback impedance. Rf and C.
Zf = Rf/(C*s*(Rf + 1/(C*s)))

>> Zi=Ri+s*L		% Series input impedance. Ri and L
Zi = Ri + L*s

>> H=simple(-Zf/Zi);
>> pretty(H)
Rf
- -----------------------
(C Rf s + 1) (Ri + L s)

>> [n,d]=numden(H);      % Get numerator and denominator polynomial
>> Rf=10000; Ri=10000;  C=0.5E-6; L=100000;  % Specify component values.

>> n=eval(n)		 % Evaluate numerator
n =  -10000

>> d=sym2poly(eval(d))	 % Eval denominator and convert to MATLAB polynomial
d =   500      100050       10000

>> n=n/d(1)   % Normalize num and den so highest order term in den is one (see last command).
n =   -20

>> d=d/d(1)
d =   1.0000  200.1000   20.0000```

b)    You can do partial fraction expansion, or... look it up in table (double exponential), or... use MATLAB for a numerical solution

```>> [r,p,k]=residue(n,d)
r =
0.1001
-0.1001

p =
-200.0000
-0.1000

k =     []```

or... use MATLAB for a symbolic solution

```>> h=simple(ilaplace(eval(H)))
h =
(200*exp(-200*t))/1999 - (200*exp(-t/10))/1999

>> vpa(h,4)
ans =
0.1001*exp(-200.0*t) - 0.1001*exp(-0.1*t)```

c) From equations in either part a (from Xfer function) or part b (from impulse response) time constants are 5 mSec (0.005=1/200) and 10 Sec (10=1/0.1).   This uses the fact that s e-αt=e-t/τ.

d)

```>> t=linspace(0,50,100000);
>> plot(t,eval(vectorize(h)));```

The first graph (0.05 second axis) shows fast time constant (5 mSec=0.005 Sec; it takes 5mSec to go through 67% (1-e-1) of decay).First graph (50 second axis) shows long time constant (it takes 10 seconds to go through 67% of decay).

4. Op Amp with Positive Feedback

This problem explores the difficulties that ensue if an op-amp circuit has finite gain.  Therefore do not assume that the two input terminals of the op-amp are at the same voltage though you may still assume no current into the inputs.  The last part of the problem explore difficulties that ensue if the circuit does not have negative feedback.

A real op-amp not only has negative feedback, it is also not infinitely fast.  We represent this finite speed by giving it a transfer function of the form

where A0 is a large positive quantity (typically 105 or more) and τ0 is a positive number (typically on the order of 0.1 seconds).  The output is defined to be

where E+ and E- are the voltages at the inverting and non-inverting terminals.

a) For the circuit shown, find an expression for the transfer function H(s)=Eout(s)/Ein(s).  It should be expressed in terms of a ratio of polynomials in positive powers of s.

b) What is the time constant of the circuit (i.e., H(s)) if  Zi=Zf, A0=106 and τ0=0.1?  Remember, you can get the time constant of a system by looking at the denominator of the transfer function.  Note that, with feedback, the circuit is much faster (smaller time constant) than the op-amp alone.

c) Find H(s) if the circuit is built as shown below (with the op-amp terminals switched).  What fundamental problem does this create?  This is a circuit with positive feedback.   Hint: you can re-use your previous work if you just make A0 negative.

Solution:

a)

b)    τ ≈ 2e-7  (i.e., 200 nSec - much faster than the op amp alone).

c) We can use the same equation as before but change the sign in front of A0.  The value of τ becomes negative, so the homogenous solution grows exponentially with time (this is a behavior that is not seen in circuits with only capacitors, inductors and resistors).  In this case we have positive feedback instead of negative feedback.

5. MATLAB for TF and Symbolic

Copy the code below into MATLAB and complete the various sections (add code in the specified locations).  Note: when you are done you can go to the "Publish" tab at the top of the MATLAB window and hit "Pulblish".  In about a minute a browser should pop up with all the results as a web page that you can print and turn in.

Note for part d, you can make this easier if you note that:

further note that

so the step does not have to be handled as a special case.

```%% Working with Transfer Functions and symbolic

%% Define a transfer function
H = tf(8,conv([1 2],[1 4]))
t = linspace(0, 4, 401);
syms s

%% a) Use the "step" command to display the step function. Add the title
% 'MATLAB step command' (using the "title" command).
%xxx delete this line and add code here
title('MATLAB step command');

%%  b) Get numerator and denominator polynomials with "tfdata" command
% Call the variables "n" and "d"
%xxx delete this line and add code here

%% c) Find the "r" and "p" values of the step response using "residue".  Note
% you'll want to multiply the denominator by "s" since Y(s)=H(s)F(s) and
% F(s)=1/s.  The "conv" command is useful for this.
%xxx delete this line and add code here

%% d) Calculate the step response using the "t" vector defined above, along
% with the calculated "r" and "p" values.  Your code should reference the
% "r" and "p" vectors; don't just type the values into your MATLAB script. See
% statement of problem for some hints.  Put this in the variable "y"
%xxx delete this line and add code here

%% e) Plot the step response calculated above with the titie 'Numeric'
%xxx delete this line and add code here

%% e) Define two symbolic variables "ns" and "ds" as the numerators and
% denominators of the transfer function H.  The polynomial variable
% shoudl be 's'.  Use the "poly2sym" command.
%xxx delete this line and add code here

%% f) Define a symbolic transfer function "Hs" and get the step response
% symbolically using the "ilaplace" command.  Assign the result to the
% variable "ys"  (for "y symbolic")
%xxx delete this line and add code here

%% g) Use the "eval" function to plot this response.  Add the title
% 'Symbolic'
%xxx delete this line and add code here```
Solution:
```%% Working with Transfer Functions and symbolic

%% Define a transfer function
H = tf(8,conv([1 2],[1 4]))
t = linspace(0, 4, 401);
syms s

%% a) Use the "step" command to display the step function. Add the title
% 'MATLAB step command' (using the "title" command).
step(H,t)
title('MATLAB step command');

%%  b) Get numerator and denominator polynomials with "tfdata" command
% Call the variables "n" and "d"
[n,d] = tfdata(H,'v')

%% c) Find the "r" and "p" values of the step response using "residue".  Note
% you'll want to multiply the denominator by "s" since Y(s)=H(s)F(s) and
% F(s)=1/s.  The "conv" command is useful for this.
dnew = conv([1  0],d);
[r, p, k] = residue (n,dnew)

%% d) Calculate the step response using the "t" vector defined above, along
% with the calculated "r" and "p" values.  Your code should reference the
% "r" and "p" vectors; don't just type the values into your MATLAB script. See
% statement of problem for some hints.  Put this in the variable "y"

% Note this code is generic, it will work for any roots (with the exception
% of repeated roots.
y=r'*exp(diag(p)*[1 1 1]'*t);  % Do it in one line
if k, y = y+k; end

% Or in a loop
yslow = zeros(size(t)); % Predefine output and initialize to zero
for i=1:3,
yslow = yslow + r(i)*exp(p(i)*t);  % Add in each exponential term.
end
if k, yslow = yslow + k; end

%% e) Plot the step response calculated above with the titie 'Numeric'
plot(t,y)
title('Numeric');

%% e) Define two symbolic variables "ns" and "ds" as the numerators and
% denominators of the transfer function H.  The polynomial variable
% shoudl be 's'.  Use the "poly2sym" command.
ns = poly2sym(n,s)
ds = poly2sym(d,s)

%% f) Define a symbolic transfer function "Hs" and get the step response
% symbolically using the "ilaplace" command.  Assign the result to the
% variable "ys"  (for "y symbolic")
Hs = ns/ds;
ys = ilaplace(Hs/s)

%% g) Use the "eval" function to plot this response.  Add the title
% 'Symbolic'
plot(t,eval(ys));
title('Symbolic');```
6. Spring, Mass, Dashpot, Sawtooth input, Simulation

Consider the system:

a) If the input is a force, fa(t), that acts on the mass (positive to the right) and the output is the position of the mass is x(t) (positive to the right), find the transfer function.  Use m=2kg, k=1N/m and b=0.1N-s/m.

b) The system is underdamped, what are the frequency and period of oscillation of the system's impulse resopnse?  You can find the frequency by completing the square of the denominator of the transfer function.

c) The input to the system is a sawtooth function that rises from 0 to 9 Newtons linearly and then drops immediately to zero, and repeats this with a 9 second period (this is near the systems natural frequency of oscillation).  Click here for link to animation to see input (and output). Use MATLAB to plot the response of the system over 90 seconds (using the "lsim" command).  You can generate the sawtooth with the following code (that also plots it):

```>> t=linspace(0,90);
>> fa=mod(t,9);
>> plot(t,fa);```

Solution:

a)

b)

c)

```>> H=tf(1,[2 0.1 1]);
>> t=linspace(0,90);    fa=mod(t,9);
>> plot(t,fa,t,lsim(H,fa,t));    legend('Input','Output');```

7. Dual Circuit (2nd order)

The circuit below acts as a low-pass circuit (i.e., rapid variations of the input voltage will tend not to show up on the output because the inductor resists rapid changes in current, and the capacitor blocks rapid changes in voltage).

a) Write an equation summing the currents at the node in the top right of the circuit (in terms of R, C, L and ei and eo (and their derivatives)).

b) Write the transfer function H(s)=Eo(s)/Ei(s).

c) Take the result from part a and substitute dual variables.

d) Draw the dual of the circuit and identify ii and io (the input and output current).

e) Show that the equation from part c represents a voltage loop equation for the dual circuit.

Solution:

a)

b)

c)  Draw over original (with dual quantities) then redraw for neatness

d)

e) Sum voltages around the loop then differentiate and gather terms to get equation from part c.

8. Two Flywheels, FBD

Consider the system shown below with two flywheels joined by a flexible shaft, K.  The flywheel on the left (J1) has a friction, B, to ground.  The flywheel on the right (J2) has no friction.

a) Draw free body diagrams

b) Write equations of motion.

Animation

Solution: