function result = calib_stiff(iin)

% Solves for the dc voltages and currents in the stiffener model
% and iterates the transistor Vbe and Ie operating points to
% give the correct small-signal ac behavior after linearization.

% physical constant kT/e
  VT = 25.6e-3;

  global sQ0Vbe0 sQ0Ie0 sB0 sQ0;
  global sQ1Vbe0 sQ1Ie0 sB1 sQ1;
  %if isempty(Q0Vbe0)
    sQ0Vbe0 = 0.66;
    sQ0Ie0 = 2.1e-3;
    sQ1Vbe0 = 0.74;
    sQ1Ie0 = 2.1e-3;
    sB0 = 100;
    sB1 = 100;
    sQ0 = sQ0Ie0/VT;
    sQ1 = sQ1Ie0/VT;
  %end

% NPN transistor: BFR92P (Infineon) ------------------
  BFR92P.IS = 121.3e-18;
  BFR92P.BF = 30; % 94.733;
  BFR92P.NF = 1.0947;
  BFR92P.VAF = 30;
  BFR92P.IKF = 0.46227;
  BFR92P.ISE = 129.55e-15;
  BFR92P.NE = 1.9052;
  BFR92P.BR = 10.729;
  BFR92P.NR = 0.8983;
  BFR92P.VAR = 14.599;
  BFR92P.IKR = 0.01;
  BFR92P.ISC = 0.75557e-15;
  BFR92P.NC = 1.371;
  BFR92P.RB = 14.998;
  BFR92P.IRB = 0.01652e-3;
  BFR92P.RBM = 7.8145;
  BFR92P.RE = 0.29088;
  BFR92P.RC = 0.13793;
  BFR92P.XTB = 0;
  BFR92P.EG = 1.11;
  BFR92P.XTI = 3;
  BFR92P.CJE = 10.416e-15;
  BFR92P.VJE = 0.70618;
  BFR92P.MJE = 0.34686;
  BFR92P.TF = 26.796-12;
  BFR92P.XTF = 0.3817;
  BFR92P.VTF = 0.32861;
  BFR92P.ITF = 4.4601e-3;
  BFR92P.PTF = 0;
  BFR92P.CJC = 946.47e-15;
  BFR92P.VJC = 0.84079;
  BFR92P.MJC = 0.4085;
  BFR92P.XCJC = 0.13464;
  BFR92P.TR = 1.2744e-9;
  BFR92P.CJS = 0e-15;
  BFR92P.VJS = 0.75;
  BFR92P.MJS = 0;
  BFR92P.FC = 0.99545;

% PNP transistor: BFT92W (NXP) -----------------------
  BFT92W.IS = 437.5e-18;
  BFT92W.BF = 20; % 33.58;
  BFT92W.NF = 1.009;
  BFT92W.VAF = 23.39;
  BFT92W.IKF = 99.53e-3;
  BFT92W.ISE = 87.05e-15;
  BFT92W.NE = 1.943;
  BFT92W.BR = 4.947;
  BFT92W.NR = 1.002;
  BFT92W.VAR = 3.903;
  BFT92W.IKR = 5.281e-3;
  BFT92W.ISC = 35.88e-15;
  BFT92W.NC = 1.393;
  BFT92W.RB = 5.000;
  BFT92W.IRB = 1.000;
  BFT92W.RBM = 5.000;
  BFT92W.RE = 1.000;
  BFT92W.RC = 10.00;
  BFT92W.XTB = 0.000;
  BFT92W.EG = 1.110;
  BFT92W.XTI = 3.000;
  BFT92W.CJE = 746.6e-15;
  BFT92W.VJE = 600.0e-3;
  BFT92W.MJE = 0.357;
  BFT92W.TF = 17.49e-12;
  BFT92W.XTF = 1.354;
  BFT92W.VTF = 155.6e-3;
  BFT92W.ITF = 1.000e-3;
  BFT92W.PTF = 45.00;
  BFT92W.CJC = 937.1e-3;
  BFT92W.VJC = 396.4e-3;
  BFT92W.MJC = 0.200;
  BFT92W.XCJC = 0.106;
  BFT92W.TR = 8.422e-9;
  BFT92W.CJS = 0.000e-15;
  BFT92W.VJS = 750.0e-3;
  BFT92W.MJS = 0.000;
  BFT92W.FC = 0.768;

% solve for the dc operating point
% 0.1 Hz is close enough to dc
  Q0Vbec.Base = stiffener('VQ0b','constant',0.1,iin);
  Q0Vbec.Emitter = stiffener('VQ0e','constant',0.1,iin);
  Q0Vbec.Collector = stiffener('VQ0c','constant',0.1,iin);
  Q1Vbec.Base = stiffener('VQ1b','constant',0.1,iin);
  Q1Vbec.Emitter = stiffener('VQ1e','constant',0.1,iin);
  Q1Vbec.Collector = stiffener('VQ1c','constant',0.1,iin);
  newQ0Vbe0 = Q0Vbec.Emitter - Q0Vbec.Base;
  newQ1Vbe0 = Q1Vbec.Emitter - Q1Vbec.Base;

  resolution = 1e-6;
  while abs(newQ0Vbe0-sQ0Vbe0)>resolution || ...
        abs(newQ1Vbe0-sQ1Vbe0)>resolution || ...
        abs(newQ0Ie0-sQ0Ie0)>resolution || ...
        abs(newQ1Ie0-sQ1Ie0)>resolution
    sQ0Vbe0 = (sQ0Vbe0+newQ0Vbe0)/2;
    currents = transistor_model(Q0Vbec,BFT92W);
    sQ0Ie0 = currents.Emitter;
    sB0 = currents.Collector/(currents.Base+1e-30);
    sQ0 = sQ0Ie0/VT;
    sQ1Vbe0 = (sQ1Vbe0+newQ1Vbe0)/2;
    currents = transistor_model(Q1Vbec,BFT92W);
    sQ1Ie0 = currents.Emitter;
    sB1 = currents.Collector/(currents.Base+1e-30);
    sQ1 = sQ1Ie0/VT;

    Q0Vbec.Base = stiffener('VQ0b','constant',0.1,iin);
    Q0Vbec.Emitter = stiffener('VQ0e','constant',0.1,iin);
    Q0Vbec.Collector = stiffener('VQ0c','constant',0.1,iin);
    Q1Vbec.Base = stiffener('VQ1b','constant',0.1,iin);
    Q1Vbec.Emitter = stiffener('VQ1e','constant',0.1,iin);
    Q1Vbec.Collector = stiffener('VQ1c','constant',0.1,iin);
    newQ0Vbe0 = Q0Vbec.Emitter - Q0Vbec.Base;
    newQ1Vbe0 = Q1Vbec.Emitter - Q1Vbec.Base;
    newQ0Ie0 = stiffener('Je0','constant',0.1,iin);
    newQ1Ie0 = stiffener('Je1','constant',0.1,iin);
  end
