summaryrefslogtreecommitdiff
path: root/OpAmps_And_Linear_Integrated_Circuits_by_Gayakwad/Chapter6.ipynb
blob: e940a81c78861c70240b711569f45dbad9517ffb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Chapter 6: General Linear Applications"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\n",
      " Low-freq cutoff is 10.61 kHz\n",
      "\n",
      " High-freq cutoff is 90.91 kHz\n",
      "\n",
      " Bandwidth is 80.3 kHz\n"
     ]
    }
   ],
   "source": [
    "#Example 6.1\n",
    "#In the circuit of figure 6-3(a) Rin=50 Ohm,Ci=0.1 uF,R1=100 Ohm, Rf=1 KOhm\n",
    "#Rl=10 kOhm and supply voltages +15, -15 V.\n",
    "#Determine the bandwidth of the amplifier.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "R1=100\n",
    "Rf=1*10**3\n",
    "Rin=50\n",
    "Rl=10*10**3\n",
    "Ci=0.1*10**-6    #Capacitance b/w 2 stages being coupled \n",
    "RiF=R1           #ac input resistance of the second stage\n",
    "Ro=Rin           #ac output resistance of the 1st stage\n",
    "UGB=10**6        #Unity gain bandwidth\n",
    "\n",
    "\n",
    "#calculation\n",
    "fl=1/(2*math.pi*Ci*(RiF+Ro)) #Low-freq cutoff\n",
    "K=Rf/(R1+Rf)\n",
    "Af=-Rf/R1                    #closed loop voltage gain\n",
    "fh=UGB*K/abs(Af)             #High-freq cutoff\n",
    "BW=fh-fl                     #Bandwidth\n",
    "\n",
    "#result\n",
    "print \"\\n Low-freq cutoff is\",round(fl/10**3,2),\"kHz\"\n",
    "print \"\\n High-freq cutoff is\",round(fh/10**3,2),\"kHz\"\n",
    "print\"\\n Bandwidth is\",round(BW/10**3,2),\"kHz\" \n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Low-freq cutoff is 31.8 kHz\n",
      "High-freq cutoff is 90.91 kHz\n",
      "Bandwidth is 90.88 kHz\n",
      "The ideal maximum output voltage swing is 15 Volts\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.2\n",
    "#For the noninverting amplifier of figure 6-4(c), Rin=50 Ohm,Ci=C1=0.1 uF\n",
    "#R1=R2=R3=100 kOhm,Rf=1 MOhm,Vcc=15 V.Determine\n",
    "#a)the bandwidth of the amplifier\n",
    "#b)the maximum output voltage swing\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "R1=100*10**3\n",
    "R2=100*10**3\n",
    "R3=100*10**3\n",
    "Rf=1*10**6\n",
    "Rin=50\n",
    "Ci=0.1*10**-6      #Capacitance b/w 2 stages being coupled\n",
    "Ro=Rin             #ac output resistance of the 1st stage\n",
    "Vcc=15\n",
    "UGB=10**6          #Unity gain bandwidth\n",
    "Rif=R2*R3/(R2+R3)  #since Ri*(1+A*B)>>R2 or R3\n",
    "\n",
    "#calculation\n",
    "fl=1/(2*math.pi*Ci*(Rif+Ro)) #Low-freq cutoff\n",
    "K=Rf/(R1+Rf)\n",
    "Af=-Rf/R1                    #closed loop voltage gain\n",
    "fh=UGB*K/abs(Af)             #High-freq cutoff\n",
    "BW=fh-fl                     #Bandwidth\n",
    "\n",
    "#result\n",
    "print \"Low-freq cutoff is\",round(fl,2),\"kHz\"\n",
    "print \"High-freq cutoff is\",round(fh/10**3,2),\"kHz\"\n",
    "print\"Bandwidth is\",round(BW/10**3,2),\"kHz\"\n",
    "print \"The ideal maximum output voltage swing is\",Vcc,\"Volts\""
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Inductance is 9.9 mH\n",
      "Figure of merit of the coil is 33.2\n",
      "Parallel resistance of the tank circuit is 32.98 kHz\n",
      "Feedback resistance is 1.03 kHz\n"
     ]
    }
   ],
   "source": [
    "#Example 6.3\n",
    "#The circuit of figure 6-5(a) is to provide a gain of 10 at a peak frequency of\n",
    "#16 kHz. Determine the value of all its components.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "fp=16*10**3   #Peak frequency\n",
    "Af=10         #Gain at peak frequency\n",
    "C=0.01*10**-6 #Assume\n",
    "R=30          #Assume the value of internal resistance of the inductor\n",
    "R1=100        #Assume the value of internal resisrance of the coil\n",
    "\n",
    "#calculation\n",
    "L=1/(((2*math.pi*fp)**2)*10**-8) #Simplifying fp=1/(2*pi*sqrt(L*C))\n",
    "Xl=2*math.pi*fp*L                #Inductive reactance\n",
    "Qcoil=Xl/R                       #Figure of merit of the coil\n",
    "Rp=((Qcoil)**2)*R                #Parallel resistance of the tank circuit\n",
    "Rf=-Rp/(1-(Rp/(Af*R1)))          #Simplifying Af=(Rf||Rp)/R1\n",
    "\n",
    "\n",
    "#result\n",
    "print \"Inductance is\",round(L*10**3,1),\"mH\"\n",
    "print \"Figure of merit of the coil is\",round(Qcoil,1)\n",
    "print \"Parallel resistance of the tank circuit is\",round(Rp/10**3,2),\"kHz\"\n",
    "print \"Feedback resistance is\",round(Rf/10**3,2),\"kHz\"\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.4"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output voltage is -2.0 Volts\n"
     ]
    }
   ],
   "source": [
    "#Example 6.4\n",
    "#In the circuit of figure 6-6 Va=1V, Vb=2V, Vc=3V, Ra=Rb=Rc=3 kOhm,Rf=1 kOhm\n",
    "#Supply voltages are 15V and -15V. Assuming that the opamp is initially nulled,\n",
    "#determine the output voltage Vo\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Va=1          #Input voltage in Volts\n",
    "Vb=2          #Input voltage in Volts\n",
    "Vc=3          #Input voltage in Volts\n",
    "Ra=3*10**3    #Resistance in ohms\n",
    "Rb=3*10**3    #Resistance in ohms\n",
    "Rc=3*10**3    #Resistance in ohms\n",
    "Rf=1*10**3    #Resistance in ohms\n",
    "\n",
    "\n",
    "#calculation\n",
    "Vo=-((Rf/Ra)*Va+(Rf/Rb)*Vb+(Rf/Rc)*Vc) #Output voltage\n",
    "\n",
    "\n",
    "#result\n",
    "print \"Output voltage is\",Vo,\"Volts\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Voltage at non-inverting terminal is 1.0 Volts\n",
      "Output voltage is 3.0 Volts\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.5\n",
    "#In the circuit of figure 6-7 Va=2V, Vb=-3V, Vc=4V, R=R1=1 kOhm,Rf=2 kOhm\n",
    "#Supply voltages are 15V and -15V. Assuming that the opamp is initially nulled,\n",
    "#determine the output voltage Vo and voltage V1 at the noninverting terminal.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Va=2             #Input voltage in volts\n",
    "Vb=-3            #Input voltage in volts\n",
    "Vc=4             #Input voltage in volts\n",
    "R1=1*10**3       #Resistance in ohms      \n",
    "Rf=2*10**3       #Resistance in ohms\n",
    "\n",
    "\n",
    "#calculation\n",
    "V1=(Va+Vb+Vc)/3  #Voltage at non-inverting terminal\n",
    "Vo=(1+Rf/R1)*V1  #Output voltage\n",
    "\n",
    "#result\n",
    "print \"Voltage at non-inverting terminal is\",V1,\"Volts\"\n",
    "print \"Output voltage is\",Vo,\"Volts\"\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output voltage is 4 Volts\n"
     ]
    }
   ],
   "source": [
    "#Example 6.6\n",
    "#In the circuit of figure 6-9 Va=2V, Vb=3V,Vc=4V,Vc=4V,Vd=5V,R=1 kOhm\n",
    "#Supply voltages are 15V and -15V. Assuming that the opamp is initially nulled,\n",
    "#Determine the output voltage Vo\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Va=2             #Input voltage in volts\n",
    "Vb=3             #Input voltage in volts\n",
    "Vc=4             #Input voltage in volts\n",
    "Vd=5             #Input voltage in volts\n",
    "R=1*10**3        #Resistance in ohms\n",
    "\n",
    "#calculation\n",
    "Vo=-Va-Vb+Vc+Vd  #Output voltage\n",
    "\n",
    "#result\n",
    "print \"Output voltage is\",Vo,\"Volts\"\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Output voltage at 0 degree is 1.47 Volts\n",
      "Output voltage at 100 degree is -4.41 Volts\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.7\n",
    "#In the circuit of figure 6-12 R1=1 kOhm, Rf=4.7 kOhm, Ra=Rb=Rc=100 kOhm.\n",
    "#Vdc=5V and Supply voltages are 15V and -15V.\n",
    "#The transducer is a thermistor with the following specifications.\n",
    "#Rt=100 kOhm at a reference temperature of 25 degree celcius, temperature\n",
    "#coefficient of resistance =-1 kOhm/ degree celcius or 1%/degree celcius.\n",
    "#Determine the output voltage Vo at o degree C and 100 degree C.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "R1=1*10**3         #Resistance in ohms\n",
    "Rf=4.7*10**3       #Resistance in ohms\n",
    "Ra=100*10**3       #Resistance in ohms\n",
    "Rb=100*10**3       #Resistance in ohms\n",
    "Rc=100*10**3       #Resistance in ohms\n",
    "Vdc=5              #dc voltage in Volts\n",
    "Rt=100*10**3       #Resistance of a thermistor\n",
    "temp_coeff=1*10**3\n",
    "R=Ra               #Ra=Rb=Rc=R\n",
    "\n",
    "#calculation\n",
    "delta_R=-temp_coeff*(0-25)      #Change in resistance\n",
    "Vo1=((Rf*delta_R)/(R1*4*R))*Vdc #Output voltage at degrees\n",
    "delta_R=-temp_coeff*(100-25)    #Change in resistance\n",
    "Vo2=((Rf*delta_R)/(R1*4*R))*Vdc #Output voltage at 100 degrees\n",
    "\n",
    "#result\n",
    "print \"Output voltage at 0 degree is\",round(Vo1,2),\"Volts\"\n",
    "print \"Output voltage at 100 degree is\",round(Vo2,2),\"Volts\"\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.8"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Change in resistance is 0.1 ohm\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.8\n",
    "#The circuit of Figure 6-12 is used as an analog weight scale with the following\n",
    "#specifications. The gain of the differential instrumentation amplifier = -100.\n",
    "#Assume that Vdc= +10 V and the opamp supply voltages = +/- 10 V. The unstrained\n",
    "#resistance of each of the four elements of the strain gage is 100 ohm Vo= 1 V.\n",
    "#When a certain weight is placed on the scale platform,the output voltage Vo=1 V.\n",
    "#Assuming that the output is initially 0,determine the change in the resistance\n",
    "#of each strain-gage element.\n",
    "\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "A=-100                      #Gain of the differential instrumentation amplifier\n",
    "Ra=100\n",
    "Rb=100\n",
    "Rc=100\n",
    "Vdc=10\n",
    "Vo=1\n",
    "R=Ra                        #Ra=Rb=Rc=R\n",
    "\n",
    "#calculation\n",
    "delta_R=(Vo*R)/(Vdc*abs(A)) #Change in resistance\n",
    "\n",
    "#result\n",
    "print \"Change in resistance is\",delta_R,\"ohm\"\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.9"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Feedback resisrance is 1.8 kOhm\n",
      "Gain of the differential amplifier is 38.0\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.9\n",
    "#The differential input and output amplifier of figure 6-14(a) is used as a\n",
    "#pre-amplifier and requires a differential output of atleast 3.7 V. Determine\n",
    "#the gain of the circuit if the differential input Vin=100 mV.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Vo=3.7                  #differential output voltage in Volts\n",
    "Vin=100*10**-3          #differential input voltage in Volts\n",
    "R1=100                  #Assume\n",
    "Rf=0.5*((Vo*R1)/Vin-1)  #Feedback resisrance\n",
    "\n",
    "#calculation\n",
    "A=(1+2*Rf/R1)           #Gain of the differential amplifier\n",
    "\n",
    "#result\n",
    "print \"Feedback resisrance is\",round(Rf/10**3,1),\"kOhm\"\n",
    "print \"Gain of the differential amplifier is\",round(A,0)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.10"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum input voltage is 1.1 Volts\n",
      "Maximum input voltage is 7.48 Volts\n"
     ]
    }
   ],
   "source": [
    "#Example 6.10\n",
    "#In the figure 6-17, for the indicated values of resistors, determine the full\n",
    "#scale range for the input voltage.\n",
    "\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "R1min=1*10**3\n",
    "R1max=6.8*10**3\n",
    "io=1*10**-3              #Meter current for full-wave rectification\n",
    "\n",
    "\n",
    "#calculation\n",
    "vin_min=1.1*R1min*io     #Minimum input voltage\n",
    "vin_max=1.1*R1max*io     #Maximum input voltage\n",
    "\n",
    "#result\n",
    "print \"Minimum input voltage is\",vin_min,\"Volts\"\n",
    "print \"Maximum input voltage is\",vin_max,\"Volts\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Current through diode is 5.0 mA\n",
      "Voltage drop across diode is 0.7 Volts\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.11\n",
    "#The circuit of figure 6-18,when the switch is in position 1, Vin=0.5 V and\n",
    "#Vo=1.2 V. Determine the current through the diode and the voltage drop across\n",
    "#it.Assume that the opamp is initially nulled.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Vin=0.5        #Input voltage\n",
    "Vo=1.2         #Output voltage\n",
    "R1=100     \n",
    "\n",
    "\n",
    "#calculation\n",
    "Io=Vin/R1      #Current through diode\n",
    "Vd=Vo-Vin      #Voltage drop across diode\n",
    "\n",
    "#result\n",
    "print \"Current through diode is\",Io*10**3,\"mA\"\n",
    "print \"Voltage drop across diode is\",Vd,\"Volts\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.12"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Load Current is 0.5 mA\n",
      "Output voltage is 2 Volts\n"
     ]
    }
   ],
   "source": [
    "\n",
    "#Example 6.12\n",
    "#The circuit of figure 6-19,Vin=5 V, R=1 Kilo Ohm and V1=1 V. Find\n",
    "#a) the load current.\n",
    "#b) the output voltage Vo.\n",
    "#Assume that the op-amp is initially nulled.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Vin=5          #Input voltage in Volts\n",
    "V1=1           #Voltage in Volts\n",
    "R1=10*10**3    #Resistance in ohms\n",
    "\n",
    "\n",
    "#calculation\n",
    "I1=Vin/R1      #Load current\n",
    "Vo=2*V1        #Output voltage\n",
    "\n",
    "\n",
    "#result\n",
    "print \"Load Current is\",I1*10**3,\"mA\"\n",
    "print \"Output voltage is\",Vo,\"Volts\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.13"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum output voltage is 0.0 Volts\n",
      "Maximum output voltage is 5.38 Volts\n"
     ]
    }
   ],
   "source": [
    "#Example 6.13\n",
    "#The circuit of figure 6-20, Vref=2V, R1=1 kilo Ohm. Rf=2.7 kilo Ohm. Assuming\n",
    "#that the opamp is initially nulled, determine the range for the output voltage\n",
    "#Vo.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "#Variable declaration\n",
    "R1=1*10**3       #Resistance in ohms\n",
    "Rf=2.7*10**3     #Resistance in ohms\n",
    "Vref=2           #Voltage in Volts\n",
    "Io=0             #Since all the binary inputs D0 to D7 are logic zero\n",
    "\n",
    "\n",
    "#calculation\n",
    "Vo_min=Io*Rf                                         #Minimum output voltage\n",
    "Io=(Vref/R1)*(1/2+1/4+1/8+1/16+1/32+1/64+1/128+1/256)\n",
    "Vo_max=Io*Rf                                         #Maximum output voltage\n",
    "\n",
    "#result\n",
    "print \"Minimum output voltage is\",Vo_min,\"Volts\"\n",
    "print \"Maximum output voltage is\",round(Vo_max,2),\"Volts\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.14"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Minimum output voltage at darkness is -0.15 Volts\n",
      "Maximum output voltage at illumination is -10.0 Volts\n"
     ]
    }
   ],
   "source": [
    "#Example 6.14\n",
    "#The circuit of figure 6-21, Vdc=5 V and Rf=3 kilo Ohm. Determine the change in\n",
    "#the output voltage if the photocell is exposed to light of 0.61 lux from a dark\n",
    "#condition.Assume that the opamp is initially nulled.\n",
    "\n",
    "from __future__ import division     #to perform decimal division\n",
    "import math\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Rf=3*10**3\n",
    "Vdc=5\n",
    "Rt1=100*10**3        #Resistance at darkness in ohms\n",
    "Rt2=1.5*10**3        #Resistance at Illumination in ohms\n",
    "\n",
    "#calculation\n",
    "Vomin=-(Vdc/Rt1)*Rf  #Min output voltage at darkness\n",
    "Vomax=-(Vdc/Rt2)*Rf  #Max output voltage at Illumination\n",
    "\n",
    "#result\n",
    "print \"Minimum output voltage at darkness is\",Vomin,\"Volts\"\n",
    "print \"Maximum output voltage at illumination is\",round(Vomax,2),\"Volts\"\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "## Example 6.15"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYQAAAEZCAYAAACXRVJOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAF0BJREFUeJzt3XuYXHV9x/H3QgJeuFrUoFxWEREFFVTY8ihMsJigAqX1\n2j5PC8iKN2yqQDC0TVKkgKL2qX20fZ6IeAO8UBQUqhGZ1SpgWRPdIKhE7jcNNyNYBdn+8TuTPZnM\n7s7Mzpnf75x5v55nnj1n5uyZ7/6Snd9+fr/fnAFJkiRJkiRJkiRJkiRJkiRJUsJuBV4duwipYavY\nBUhNjgMmgEeAe4BPADt28P23Aof3sJ5eny9vMrsBrAA+V9DzSG2xQ1BK3g+ck33dARgB9gRWA/Pb\nPMckMNTDmnp9PknSLHYANgJvaLr/qcCvgOOz/QuAM3OP14A7su3PAX8EHs3OdQowDDwBjAJ3AXcT\nOpyGTs/X7Ebgdbn9ecCvgZdm+0cDNwAPAlcDL8gdewshfSwGfg/8IXueNdnjxwM/BX4DrAfe3vTc\np2U/z53AidnP+dzssW2B84DbgHuBTwJPalG/JCVnMfAYrVPrBcCF2fangX/OPVZj6gUcpl5kG4YJ\nL5RfAJ4M7EfoYBpj952er9k/Ap/P7b+O0AEAPB/4bfZcWwOnAr8gdBrN514OfLbp3K8FnpNtH0oY\nRjsg219MGFLbN/u5Ps/mHcLHgK8COwHbAZcB/zLDzyE5ZKRk7AJsILyoNbsX+JPcfjdDOCuB3wHr\nCJ3AW+d4voYLCSmg8df3XwEXZdtvBr4OXEVIGucRXrwPaXGeoRZ1XEHoNAC+C3wLeFW2/ybgfEJC\n+R2hQ8mfaxR4H/AQoVM6G3hLpz+cBosdglKxgdAptPo/uWv2+Fzk/+q/HXjWHM/XsJ7wonw08BTg\nKKbSzK7ZczVMZnU8u81zHwlcC9xPGHJ6LVMd465s/jPdm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avZxpc+/X78ugtvN8PyKM574E+Djw1UIr6l7stmxH\nSm25HfAV4O8If4E3S6U9Z6ozlfZ8gjC8tRtwKGHopVkK7TlbnSm05+uBXxHmD2ZKK223Zwodwl2E\nhm3YndCLzXTMbvT/+kft1LmRqah5JWGu4WnFl9aRFNqyHam05XzgEuDztP6lT6U9Z6szlfZseBj4\nBmEJel4q7dkwXZ0ptOchhCGhW4CLgMOBzzYdk1p7zmoe4V11w4TxutkmlUeIM9HUTp3PZKo3Pogw\n3xDDMO1NKsdqy4Zhpq8zhbYcIvyCfWyGY1Joz3bqTKE9dyGMYQM8Gfgu4Y2peSm0Zzt1ptCeeYfR\nepVRCu3ZsSMJKyNuZupCdydlt4Z/zx7/MXBgX6ubMlud7yYs+1sL/IDwD9BvFwF3A38gjB2eQJpt\nOVudKbTlKwlDB2uZWl54JOm1Zzt1ptCe+xOGWtYCPyGMfUN67dlOnSm0Z95hTK0ySq09JUmSJEmS\nJEmSJEmSJEmSJKnKdgTemW3vCnw5Yi2SpIiGmfmzJCRJA+JiwjVq1gBfYqpzOI5wjaBvEa4d8x7g\nFMI7Wq8Bds6O24twbZvrCZc82KdPdUuSemxPpjqB/PZxhE+deirhWjcPA2/PHvso4QqjAFcBz8u2\nD872pVKYF7sAKTFD02xDuC7+I9ntIaYuJjYBvJjQWRzC5vMO2xRTptR7dghS+36f234it/8E4Xdp\nK8KnwCX/ubVSKyl8HoKUko3A9h1+TyNJbCTML7whd/+Le1SXVDg7BGlz9wPfJwwDfYipT5eaZPNP\nmmrebuz/NfA2wmWR1xE+wESSJEmSJEmSJEmSJEmSJEmSJEmSJKl6/h8flz155YhO7wAAAABJRU5E\nrkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x7f75432e8a90>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "\n",
    "#Example 6.15\n",
    "#In the figure 6-23, R1Cf=1 second, and the input is a step(dc) voltage, as\n",
    "#shown in figure 6-26(a). Determine the output voltage and sketch it.\n",
    "#Assume that the opamp is initially nulled.\n",
    "\n",
    "%matplotlib inline\n",
    "import math\n",
    "import scipy\n",
    "from matplotlib.pyplot import ylabel, xlabel, title, plot, show\n",
    "import scipy.integrate\n",
    "\n",
    "\n",
    "#Variable declaration\n",
    "Vin=2   #Input voltage in Volts\n",
    "VoO=0   #Output offset voltage\n",
    "\n",
    "\n",
    "#calculation\n",
    "\n",
    "def integrnd(x) :\n",
    " return 2\n",
    "val1, err = scipy.integrate.quad(integrnd, 0, 1)\n",
    "val2, err = scipy.integrate.quad(integrnd, 1, 2)\n",
    "val3, err = scipy.integrate.quad(integrnd, 2, 3)\n",
    "val4, err = scipy.integrate.quad(integrnd, 3, 4)\n",
    "\n",
    "a=-val1\n",
    "b=a+-val2\n",
    "c=b+-val3\n",
    "d=c+-val4\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "x=[0,1,2,3,4]\n",
    "y=[VoO,a,b,c,d]\n",
    "plt.plot(x,y)\n",
    "title('Output voltage')\n",
    "xlabel('time')\n",
    "ylabel('Voutput')\n",
    "plt.show()\n"
   ]
  }
 ],
 "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.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}