{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "adm= -1482\n",
      "acm= -1\n",
      "cmrr= 76.4838188131 db\n"
     ]
    }
   ],
   "source": [
    "#problem 1 page 1.81\n",
    "#given\n",
    "rc=50000;\n",
    "re=100000;\n",
    "rs=10000;\n",
    "rp=50000;\n",
    "beta0=2000;\n",
    "r0=400000;\n",
    "#determine adm,acm,cmrr\n",
    "rc1=(rc*r0)/(rc+r0);\n",
    "print 'adm=',(-(beta0*rc1)/(rs+rp))\n",
    "print 'acm=',(-(beta0*rc1)/(rs+rp+2*re*(beta0+1)))\n",
    "import math\n",
    "print 'cmrr=',20*(math.log10((1+((2*re*(beta0+1))/(rs+rp))))),'db'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "maximum peak amplitude at 100khz 3.1847133758 V\n"
     ]
    }
   ],
   "source": [
    "#problem 2 page 1.83\n",
    "#given\n",
    "sr=0.000001;#volt/sec\n",
    "freq=100000;\n",
    "vsat=12;\n",
    "baw=100000;\n",
    "#determine vx\n",
    "print 'maximum peak amplitude at 100khz',2*(1/(sr*2*3.14*freq)),'V'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "slew rate= 5 volt/μsec\n"
     ]
    }
   ],
   "source": [
    "#problem 3 page 1.84\n",
    "#given\n",
    "V=20;\n",
    "t=4;\n",
    "#determine slew rate\n",
    "print'slew rate=',V/t,'volt/μsec'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "max frequency of input is  79617.8343949 hz\n"
     ]
    }
   ],
   "source": [
    "#problem 4 page 1.84\n",
    "#given\n",
    "a=50;\n",
    "vi=20e-3;\n",
    "sr=0.5e6;\n",
    "#determine max frequency\n",
    "vm=a*vi;\n",
    "print 'max frequency of input is ',sr/(2*3.14*vm),'hz'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "max peak to peak input signal  0.398089171975 V\n"
     ]
    }
   ],
   "source": [
    "#problem 5 page 1.84\n",
    "#given\n",
    "sr=0.5e6;\n",
    "freq=40e3;\n",
    "a=10;\n",
    "#determine max peak to peak input signal\n",
    "vm=sr/(2*3.14*freq);\n",
    "vm=2*vm;\n",
    "print'max peak to peak input signal ',vm/a,'V'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "noise  0.0063247 V\n"
     ]
    }
   ],
   "source": [
    "#problem 6  page 1.85\n",
    "#given\n",
    "adm=400;\n",
    "cmrr=50;\n",
    "vin1=50e-3;\n",
    "vin2=60e-3;\n",
    "vnoise=5e-3;\n",
    "v0=(vin2-vin1)*adm;\n",
    "acm=adm/316.22;\n",
    "print'noise ',round(vnoise*acm,7),'V'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " time to change from 0 t0 15  4e-07 sec\n",
      "slew rate 1.5 volt/μsec\n"
     ]
    }
   ],
   "source": [
    "#problem 7 page 1.86\n",
    "#given\n",
    "sr=35e6;#volt/sec\n",
    "vsat=15;#volt\n",
    "#determine time to change from 0 to 15V\n",
    "print 'time to change from 0 t0 15 ',round(vsat/sr,7),'sec'\n",
    "c=100e-12;#farad\n",
    "i=150e-6;#A\n",
    "print'slew rate',(i/c)/1000000,'volt/μsec'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bandwidth  21231.4225053 hz\n"
     ]
    }
   ],
   "source": [
    "#problem 8 page 1.86\n",
    "#given\n",
    "sr=2e6;#v/sec\n",
    "vsat=15;#volt\n",
    "#determine bandwidth \n",
    "print'bandwidth ',sr/(2*3.14*vsat),'hz'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output offset  3.0 V\n"
     ]
    }
   ],
   "source": [
    "#problem 9 page 1.87\n",
    "#given\n",
    "iin=30e-9;#A\n",
    "a=1e5;\n",
    "rin=1000;#ohm\n",
    "#determine output offset voltage\n",
    "vid=iin*rin;\n",
    "print'output offset ',a*vid,'V'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input offset current  4e-06 A\n",
      "input base current  2.4e-05 A\n"
     ]
    }
   ],
   "source": [
    "#problem 10 page 1.86\n",
    "#given\n",
    "inb1=22e-6;#A\n",
    "inb2=26e-6;#A\n",
    "#determine input offset current input base current\n",
    "print'input offset current ',inb2-inb1,'A'\n",
    "print'input base current ',(inb2+inb1)/2,'A'\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input base current  8e-08 A\n",
      "input offset current  2e-08 A\n",
      "input offset   2.0 V\n"
     ]
    }
   ],
   "source": [
    "#problem 11 page 1.86\n",
    "#given\n",
    "inb2=90e-9;#A\n",
    "inb1=70e-9;#A\n",
    "a=1e5;\n",
    "#determine input offset current\n",
    "print'input base current ',(inb2+inb1)/2,'A'\n",
    "print'input offset current ',inb2-inb1,'A'\n",
    "print'input offset  ',((inb2-inb1)*1000)*a,'V'\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output voltage cmrr  100      0.05125 V\n",
      "output voltage cmrr  200      0.050625 V\n",
      "output voltage cmrr  450      0.0502777777778 V\n",
      "output voltage cmrr  105      0.0511904761905 V\n"
     ]
    }
   ],
   "source": [
    "#problem 12 page 1.88\n",
    "#given\n",
    "vin1=150e-6;#volt\n",
    "vin2=100e-6;#volt\n",
    "a=1000;\n",
    "from array import *\n",
    "cmrr=array('i',[100,200,450,105])\n",
    "#determine output voltage\n",
    "vc=(vin1+vin2)/2;\n",
    "vd=(vin1-vin2);\n",
    "j=0;\n",
    "while j<=3 : print 'output voltage cmrr ',cmrr[j],'    ',(a*vd*(1+(vc/(cmrr[j]*vd)))),'V';j=j+1;\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "output voltage  0.00316455696203 V\n"
     ]
    }
   ],
   "source": [
    "#problem 13 page 1.87\n",
    "#given\n",
    "rin=100e3;#ohm\n",
    "rf1=900e3;#ohm\n",
    "vc=1;#volt\n",
    "cmrr=70;\n",
    "#determine the output voltage\n",
    "print 'output voltage ',(1+(rf1/rin))*vc/3160,'V'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "input voltage  0.0796178343949 V\n"
     ]
    }
   ],
   "source": [
    "#problem 14 page 1.89\n",
    "#given\n",
    "sr=0.5e6;#volt/sec\n",
    "a=50;\n",
    "freq=20e3;#hz\n",
    "#determine max peak to peak voltage\n",
    "print'input voltage ',sr/(2*3.14*freq*a),'V'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "max frequency  265392.781316 hz\n"
     ]
    }
   ],
   "source": [
    "#problem 15 page 1.90\n",
    "#given\n",
    "sr=50e6;#volt/sec\n",
    "rin=2;\n",
    "vimax=10;\n",
    "#determine max frequency\n",
    "vm=vimax*(1+rin);\n",
    "print 'max frequency ',sr/(2*3.14*vm),'hz'\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}