summaryrefslogtreecommitdiff
path: root/Linear_Integrated_Circuit_by_M._S._Sivakumar/Ch6.ipynb
blob: c71607094d9b2640618a4582ac2c2d47ad19c838 (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
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 6 Applications of Operational Amplifier"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.1 Pg 140"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 116,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the input resistance is = 20.00 kohm\n",
      "The resistance R2 is = 100.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design an inverting amplifier\n",
    "Av = -5 #\n",
    "#V1 = 0.1 sin wt #\n",
    "V1 = 0.1   # # *sin wt #\n",
    "i = 5*10**-6 #\n",
    "\n",
    "# the input resistance \n",
    "R1 = V1/i / 1000 # kohm\n",
    "print 'the input resistance is = %0.2f'%R1,'kohm'#\n",
    "\n",
    "# The resistance R2\n",
    "#Av = -(R2/R1)#\n",
    "R2 = -(Av*R1)#\n",
    "print 'The resistance R2 is = %0.2f'%R2,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.2 Pg 141"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 117,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the input resistance is = 20.00 kohm\n",
      "The resistance R2 is = 80.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design an non inverting amplifier\n",
    "Av = 5 #\n",
    "#V1 = 0.1 sin wt #\n",
    "V1 = 0.1 #\n",
    "i = -5*10**-6 #\n",
    "\n",
    "# the input resistance \n",
    "R1 = -V1/i/1000 # kohm\n",
    "print 'the input resistance is = %0.2f'%R1,'kohm'#\n",
    "\n",
    "# The resistance R2\n",
    "#Av = 1+(R2/R1)#\n",
    "R2 = (Av-1)*R1#\n",
    "print 'The resistance R2 is = %0.2f'%R2,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.3 Pg 146"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 118,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the cut off frequency of phase shifter is = 723.43 Hz\n",
      "The phase shift is = -15.75\n"
     ]
    }
   ],
   "source": [
    "# To calculate phase shift between two extremes \n",
    "C = 0.22*10**-6 #\n",
    "R = 1*10**3 #\n",
    "f = 1*10**3 #\n",
    "\n",
    "# the cut off frequency of phase shifter \n",
    "fc = 1/(2*pi*R*C) #\n",
    "print 'the cut off frequency of phase shifter is = %0.2f'%fc,'Hz'#\n",
    "f\n",
    "# the phase shift\n",
    "f = 1 # # KHz\n",
    "fc = 7.23 #  # KHz \n",
    "from math import atan ,degrees\n",
    "PS = -2*degrees(atan(f/fc))\n",
    "print 'The phase shift is = %0.2f'%PS"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.4 Pg 146"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 119,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of resistance is = 1.92 kohm\n"
     ]
    }
   ],
   "source": [
    "# To design a phase shifter\n",
    "f = 2*10**3 #\n",
    "PS = -135 #\n",
    "# the phase shift\n",
    "# PS = -2*atand(2*pi*R*C)#\n",
    "#RC = 192.1*10**-6 #\n",
    "C = 0.1*10**-6 #\n",
    "R = (192.1*10**-6)/C/1000 # kohm\n",
    "print 'The value of resistance is = %0.2f'%R,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.5 Pg 153"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of resistance R1 is = 25.00 kohm\n",
      "The value of resistance R3 is = 25.00 kohm\n",
      "The value of resistance R2 is = 750.00 kohm\n",
      "The value of resistance R4 is = 750.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design a difference amplifier\n",
    "Ri = 50 # kohm\n",
    "Ad = 30 \n",
    "\n",
    "R1 = Ri/2 #\n",
    "print 'The value of resistance R1 is = %0.2f'%R1,'kohm'#\n",
    "R3 = R1 #\n",
    "print 'The value of resistance R3 is = %0.2f'%R3,'kohm'#\n",
    "\n",
    "# the differential gain\n",
    "#Ad = R2/R1 #\n",
    "R2 = 30*R1 #\n",
    "print 'The value of resistance R2 is = %0.2f'%R2,'kohm'#\n",
    "\n",
    "R4 = R2 #\n",
    "print 'The value of resistance R4 is = %0.2f'%R4,'kohm'# "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.6 Pg 154"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 121,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The common mode rejection ratio is = 26.58  dB\n"
     ]
    }
   ],
   "source": [
    "# Calculate CMRR ratio\n",
    "Ad = 10.24 #\n",
    "Acm = 0.48 #\n",
    "\n",
    "# the common mode rejection ratio CMRR is defined as\n",
    "CMRRdB = 20*log10(Ad/Acm)#\n",
    "print 'The common mode rejection ratio is = %0.2f'%CMRRdB,' dB'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.7 Pg 156"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 122,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " The feedback resistance is = 100.00 kohm\n",
      " The value of resistance R1 is = 100.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design current to voltage converter\n",
    "Vo =-10 #\n",
    "Is = 100*10**-6 #\n",
    "\n",
    "# the output voltage of current to voltage converter is defined as\n",
    "#Vo =-1s*R2 \n",
    "R2 = -Vo/Is/1000 #kohm\n",
    "print ' The feedback resistance is = %0.2f'%R2,'kohm'#\n",
    "\n",
    "R1 = R2 #\n",
    "print ' The value of resistance R1 is = %0.2f'%R1,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.8 Pg 157"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 123,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of resistance R2 is = 44.78 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design high sensitivity current to voltage converter\n",
    "R1 = 5 # kohm\n",
    "Is = 1 #\n",
    "KR = 0.01/10**9 #  #    V / nA\n",
    "\n",
    "# the output voltage of high sensitivity current to voltage converter\n",
    "Vo =-KR*Is #\n",
    "KR = 10*10**6 #\n",
    "R = 1*10**6 #   #we assume   then\n",
    "K = 10 #\n",
    "#1 + (R2/R1)+(R2/R) = 10 #\n",
    "# solving above equation we get\n",
    "\n",
    "R2 = 9*((5*10**6)/(10**3+5))/1000 # kohm\n",
    "print 'The value of resistance R2 is = %0.2f'%R2,'kohm'# "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.9 Pg 160"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 124,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The load current iL is = 5.00 mA\n",
      "The current i3 is = 0.50 mA\n",
      "The current iA is = 5.50 mA\n",
      "The output voltage is = 6.00  V\n",
      "The current i1 is = 49.40  A\n",
      "The current i2 is = 49.40  A\n"
     ]
    }
   ],
   "source": [
    "# Determine a load current in a V to I converter\n",
    "R1 = 10 # kohm\n",
    "R2 = 10  # koohm\n",
    "R3 = 1 # kohm\n",
    "R4 = 1 # kohm\n",
    "VI = -5 #\n",
    "\n",
    "# The Load Current\n",
    "iL = -VI/R3 #\n",
    "print 'The load current iL is = %0.2f'%iL,'mA'#\n",
    "\n",
    "VL = 0.5 #\n",
    "# The  Current i3 and iA\n",
    "i3 = VL/R3 #\n",
    "print 'The current i3 is = %0.2f'%i3,'mA'#\n",
    "\n",
    "iA = i3+iL #\n",
    "print 'The current iA is = %0.2f'%iA,'mA'#\n",
    "\n",
    "# the output voltage \n",
    "Vo = (iA*R3)+VL #\n",
    "print 'The output voltage is = %0.2f'%Vo,' V'#\n",
    "\n",
    "ZL =100 #\n",
    "# The current i1 and i2 \n",
    "#i1 = (VI-iL*ZL)/R1 #\n",
    "i1 = (iL*ZL-Vo)/R2 #\n",
    "print 'The current i1 is = %0.2f'%i1,' A'#\n",
    "\n",
    "i2 = i1 #\n",
    "print 'The current i2 is = %0.2f'%i2,' A'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.10 Pg 163"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 125,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of resistance R1f is = 0.0606 K ohm \n",
      "The value of resistance R2 is = 75.5 K ohm \n"
     ]
    }
   ],
   "source": [
    "# Design an instrumentation amplifier\n",
    "#A = 5 to 500 #  adjustable gain\n",
    "VR = 100*10**3 #\n",
    "\n",
    "# the maximum differential gain of instrumentation amplifier is 500 \n",
    "#Amax = (R4/R3)*(1+(2R2/R1))#\n",
    "#by solving above equation we get following equation\n",
    "# 2R2 -249R1f = 0                                                  equation 1\n",
    "\n",
    "# the minimum differential gain of instrumentation amplifier is 5\n",
    "# Amin = (R4/R3)*(1+(2R2/R1)) #\n",
    "#by solving above equation we get following equation\n",
    "# 2R2 -1.5R1f = 150*10**3                                           equation 2\n",
    "\n",
    "#by solving equation 1 and 2 we get\n",
    "print 'The value of resistance R1f is = 0.0606 K ohm '#\n",
    "\n",
    "print 'The value of resistance R2 is = 75.5 K ohm '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.11 Pg 164"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of resistane R1 is = 9.09 kohm\n"
     ]
    }
   ],
   "source": [
    " # To find the value of resistance R1 for instrumentation amplifier\n",
    "A =100 #\n",
    "R2 = 450*10**3 #\n",
    "R3 = 1*10**3 #\n",
    "R4 = 1*10**3 #\n",
    "\n",
    "# The gain of differential amplifier \n",
    "# A = (R4/R3)*(1+(2R2/R1)) #\n",
    "#but  R3 = R4  then\n",
    "# A = 1+(2R2/R1) #\n",
    "R1 = 2*R2/(A-1)/1000 # kohm\n",
    "print 'The value of resistane R1 is = %0.2f'%R1,'kohm'# "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.12 Pg 167"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 130,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " At t = 1 msec the time constant RC is = 0.10  m sec\n",
      " if C = 0.01 uF then R of RC time constant is = 10 K ohm \n",
      " if C = 0.001 uF then R of RC time constant is = 100 K ohm \n"
     ]
    }
   ],
   "source": [
    "# determine the time constant of an integrator\n",
    "Vo = 10 #  # at t= 1 m sec\n",
    "t = 1 # # m sec\n",
    "\n",
    "# the output of integrator \n",
    "#Vo = t/RC # when t is from 0 to 1\n",
    "RC = t/Vo #\n",
    "print ' At t = 1 msec the time constant RC is = %0.2f'%RC,' m sec'#\n",
    "\n",
    "print ' if C = 0.01 uF then R of RC time constant is = 10 K ohm '#\n",
    "\n",
    "print ' if C = 0.001 uF then R of RC time constant is = 100 K ohm '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.13 Pg 168"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 131,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " The feedback resistance Rf is = 100.00 kohm\n",
      " The frequency fa is = 2.00 kHz\n",
      " The value of capacitor C is = 0.8 nF \n"
     ]
    }
   ],
   "source": [
    "# Design an integrator circuit\n",
    "A = 10 #\n",
    "f =20*10**3 #\n",
    "R = 10*10**3 #  # we assume \n",
    "Rf =10*R #\n",
    "\n",
    "print ' The feedback resistance Rf is = %0.2f'%(Rf/1000),'kohm'#\n",
    "\n",
    "# for proper integration f>= 10fa \n",
    "fa = f/10/1000 #\n",
    "print ' The frequency fa is = %0.2f'%fa,'kHz'#\n",
    "\n",
    "# in practical integrator\n",
    "#fa = 1/(2*pi*Rf*C)#\n",
    "\n",
    "C = 1/(2*pi*Rf*fa)*1e6# nF\n",
    "print ' The value of capacitor C is = %0.1f'%C,'nF '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.1 Pg 185"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance R1 is = 0.199 Mohm\n",
      "the value of resistance R2 is  = 1 Mohm\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# design an inverting amplifier with a closed loop voltage gain of Av = -5\n",
    "Av = -5 #\n",
    "Is = 5*10**-6 # # A\n",
    "Rs = 1*10**3 # # ohm\n",
    "# input voltage source Vs = sinwt volts\n",
    "\n",
    "# in an inverting amplifier frequency effect is neglected then i/p volt Vin = 1 V and total resistance equal to Rs+R1\n",
    "\n",
    "# the input current can be written as Iin=Is\n",
    "# Is = (Vin/Rs+R1)#\n",
    "Iin = Is#\n",
    "Vin = 1 # # V\n",
    "R1 = (1-(Iin*Rs))/Iin  #\n",
    "print 'the value of resistance R1 is = %0.3f'%(R1/1e6),'Mohm'#\n",
    "\n",
    "# closed loop voltage gain of an inverting amplifier\n",
    "#Av = -(R2/Rs+R1)\n",
    "R2 = -(Av*(Rs+R1))#\n",
    "print 'the value of resistance R2 is  = %0.f'%(R2/1e6),'Mohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.2 Pg 186"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance R1 is = 8 kohm\n",
      "the value of resistance R2 is  = 72 kohm\n"
     ]
    }
   ],
   "source": [
    " # design an inverting amplifier with a closed loop voltage gain of Av = 10\n",
    "Av = 10 #\n",
    "Vin = 0.8 #  #V\n",
    "Iin = 100*10**-6 # # A\n",
    "# in an non- inverting amplifier the input voltage Vin=V1=V2 because of vortual short effect then the i/p current In = Vin/R1\n",
    "R1 = Vin/Iin/1e3\n",
    "print 'the value of resistance R1 is = %0.f'%R1,'kohm'#\n",
    "\n",
    "# closed loop voltage gain of an non-inverting amplifier\n",
    "#Av = Vo/Vin =  (1+R2/R1)\n",
    "R2 = (Av-1)*R1 # kohm\n",
    "print 'the value of resistance R2 is  = %0.f'%R2,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.3 Pg 187"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance R1 is  = 20.00 kohm\n",
      "the value of resistance R2 is  = 80.00 kohm\n",
      "the output current I2 is  = 50 uA\n"
     ]
    }
   ],
   "source": [
    "# design an non-inverting amplifier with colsed loop gain of 5 limited voltage of -5 V <= Vo <= 5 V  and maximum i/p c/n 50 uA\n",
    "R1 = 8*10**3 # # ohm\n",
    "R2 = 72*10**3 # # ohm\n",
    "Iin = 50*10**-6 # # A\n",
    "Vo = 5 # # V \n",
    "\n",
    "# closed loop gain\n",
    "#Av = Vo/Vin = (1+R2/R1)\n",
    "Av = 1+(R2/R1)#\n",
    "# but  \n",
    "Av = 5 #\n",
    "# then\n",
    "# (R2/R1) = 4 #\n",
    "\n",
    "# the output voltage of the amplifier is Vo = 5 V \n",
    "#i.e\n",
    "Vin = 1 # # V\n",
    "# Iin = Vin/R1 #\n",
    "R1 = Vin/Iin/1e3\n",
    "print 'the value of resistance R1 is  = %0.2f'%R1,'kohm'#\n",
    "\n",
    "R2 = 4*R1 #\n",
    "print 'the value of resistance R2 is  = %0.2f'%R2,'kohm'#\n",
    "\n",
    "# the output current I2 is given as\n",
    "I2 = (Vo-Vin)/R2*1e3 # uA\n",
    "print 'the output current I2 is  = %0.f'%I2,'uA'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.4 Pg 188"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance Ria is  = 20.00 kohm\n",
      "the value of resistance Rib is  = 15.00 kohm\n",
      "the value of resistance Ric is  = 30.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design a op-amp circuit to provide the output voltage Vo = -2(3 V1 +4 V2 +2 V3)\n",
    "# Vo = -2(3 V1 + 4 V2+ 2 V3)#      equation 1\n",
    "# the output of the summer circuit is given as\n",
    "# Vo = -R2((Via/Ria)+(Vib/Rib)+(Vic/Ric))    equation 2\n",
    "\n",
    "# compare equation 1 and 2  of Vo we get \n",
    "\n",
    "#  (R2/Ria)= 6 #\n",
    "#  (R2/Rbi=8 #\n",
    "#  (R2/Ric)=4 #\n",
    "\n",
    "R2 = 120*10**3/1e3 #   # we choose then \n",
    "\n",
    "Ria = R2/6 #\n",
    "print 'the value of resistance Ria is  = %0.2f'%Ria,'kohm'#\n",
    "\n",
    "Rib = R2/8 #\n",
    "print 'the value of resistance Rib is  = %0.2f'%Rib,'kohm'#\n",
    "\n",
    "Ric = R2/4 #\n",
    "print 'the value of resistance Ric is  = %0.2f'%Ric,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.5 Pg 188"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance Ria is  = 90.00  kohm\n",
      "the value of resistance Rib is  = 42.00  kohm\n",
      "the value of resistance Ric is  = 63.00  kohm\n",
      "the value of resistance Rid is  = 210.00 kohm\n"
     ]
    }
   ],
   "source": [
    " # Design a summing amplifier circuit to provide the output voltage Vo = -(7 V11 + 15 V12 + 10 V13 + 3 V14)\n",
    "R2 = 630# kohm # Assume feedback resistance\n",
    "# Vo = -(7 V11 + 15 V12 + 10 V13 + 3 V14)#                    equation 1\n",
    "# the output of the summer circuit is given as\n",
    "# Vo = -R2((Via/Ria)+(Vib/Rib)+(Vic/Ric)+(Vid/Rid))           equation 2\n",
    "\n",
    "# compare equation 1 and 2  of Vo we get \n",
    "\n",
    "#  (R2/Ria)= 7 #\n",
    "#  (R2/Rbi= 15 #\n",
    "#  (R2/Ric)= 10 #\n",
    "#  (R2/Rid)= 3 #\n",
    "\n",
    "Ria = R2/7 #\n",
    "print 'the value of resistance Ria is  = %0.2f'%Ria,' kohm'#\n",
    "\n",
    "Rib = R2/15 #\n",
    "print 'the value of resistance Rib is  = %0.2f'%Rib,' kohm'#\n",
    "\n",
    "Ric = R2/10 #\n",
    "print 'the value of resistance Ric is  = %0.2f'%Ric,' kohm'#\n",
    "\n",
    "Rid = R2/3 #\n",
    "print 'the value of resistance Rid is  = %0.2f'%Rid,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.6 Pg 190"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance R2 is  = 300.00 kohm\n",
      "the value of resistance R4 is  = 33333.33 kohm\n"
     ]
    }
   ],
   "source": [
    "# Design a op-amp circuit to provide the output voltage Vo = V2 - 3 V1 with Ri1 =Ri2 = 100*10**3\n",
    "Ri1 = 100 # # kohm\n",
    "Ri2 = 100  # # kohm\n",
    "# the i/p resistance \n",
    "R1 = Ri1 #\n",
    "R3 = Ri2 #\n",
    "\n",
    "# Vo = V2 - 3 V1#                                    equation 1\n",
    "# the output of the summer circuit is given as\n",
    "# Vo = [(R4/(R3+R4)*(1+(R2/R1))*Vi2-(R2/R1)*Vi1]        equation 2\n",
    "\n",
    "# compare equation 1 and 2  of Vo we get \n",
    "# (R4/(R3+R4)*(1+(R2/R1)) = 1 #                           equation  3\n",
    "# R2/R1 = 3 #                                           equation 4\n",
    "\n",
    "# by subsituting the value of R1 and R3 in equation 3 and 4\n",
    "\n",
    "# from equation  4\n",
    "R2 = 3*R1 #\n",
    "print 'the value of resistance R2 is  = %0.2f'%R2,'kohm'#\n",
    "\n",
    "# from equation  3\n",
    "R4 = (100*10**3)/3 #\n",
    "print 'the value of resistance R4 is  = %0.2f'%R4,'kohm'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.7 Pg 191"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The load current iL is  = 5 mA\n",
      "The voltage across load VL is  = 1.00  V\n",
      "The non-inverting current across i3 is = 1.00 mA\n",
      "The non-inverting current across i4 is  = 6.00 mA\n",
      "The output voltage of given voltage to current converter is  = 6.00  V\n"
     ]
    }
   ],
   "source": [
    " # determine the load current and output voltage\n",
    "Vin = -5 #  # V\n",
    "ZL = 200 # # ohm\n",
    "R1 = 10*10**3 # # ohm\n",
    "R2 = 10*10**3 # # ohm\n",
    "R3 = 1*10**3 # # ohm\n",
    "R4 = 1*10**3 # # ohm\n",
    "\n",
    "# the load c/n of the given voltage to c/n converter circuit is given by\n",
    "iL =-Vin/(R1*R4)*R2*1e3 # m\n",
    "print 'The load current iL is  = %0.f'%iL,'mA'#\n",
    "\n",
    "# the voltage across the load \n",
    "VL = iL/1e3*ZL#\n",
    "print 'The voltage across load VL is  = %0.2f'%VL,' V'#\n",
    "\n",
    "# the non-inverting current across i3 and i4 are\n",
    "i3 = VL/R3*1000 #mA\n",
    "print 'The non-inverting current across i3 is = %0.2f'%i3,'mA'#\n",
    "\n",
    "i4 = iL+i3 # mA\n",
    "print 'The non-inverting current across i4 is  = %0.2f'%i4,'mA'#\n",
    "\n",
    "# the output voltage of given voltage to current converter is given by\n",
    "Vo = (iL/1e3*R3)+VL #\n",
    "print 'The output voltage of given voltage to current converter is  = %0.2f'%Vo,' V'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.8 Pg 192"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The common mode rejection ratio CMRR is  = 120.50  \n",
      "The common mode rejection ratio CMRR in decibel is  = 41.62  dB \n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "# determine the common mode rejection ratio CMRR\n",
    "# R2/R1 = 10 #\n",
    "# R4/R3 = 11 #\n",
    "\n",
    "# the output of the difference amplifier is given by\n",
    "# Vo = (((R4)/(R3+R4))*(((1+(R2/R1))*VI2))-((R2/R1)*VI1))#\n",
    "\n",
    "# putting R1 R2 R3 R4 value in above equation we get Vo as\n",
    "\n",
    "# Vo =(121/12)*VI2-10VI1 #                                 equation 1\n",
    "\n",
    "# the differential mode input of difference amplifier is given by\n",
    "# Vd = VI2-VI1 #                                               eqution 2\n",
    "\n",
    "# the common mode input of difference amplifier is given by\n",
    "# VCM = (VI2+VI1)/2 #                                         equation 3\n",
    "\n",
    "# from equation 2 and 3 \n",
    "\n",
    "# VI1 = VCM-Vd/2 #                                          equation 4\n",
    "\n",
    "# VI2 = VCM+Vd/2 #                                          equation 5\n",
    "\n",
    "# substitute equation 4 and 5 in 1  we get \n",
    "# Vo = (VCM/12)+(241Vd/24)#                               equation6\n",
    "\n",
    "# Vd = Ad*Vd+ACM*VCM #                                  equation 7\n",
    "\n",
    "#equation from equation 6 and 7 we get\n",
    "\n",
    "Ad = 241/24 #\n",
    "ACM = 1/12 #\n",
    "\n",
    "# the common mode rejection ratio CMRR is \n",
    "CMRR = abs(Ad/ACM)#\n",
    "print 'The common mode rejection ratio CMRR is  = %0.2f'%CMRR,' '#\n",
    "\n",
    "# in decibal it can be expressed as\n",
    "\n",
    "CMRR = 20*log10(CMRR)#\n",
    "print 'The common mode rejection ratio CMRR in decibel is  = %0.2f'%CMRR,' dB '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.9 Pg 194"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output of the difference amplifier is  = -8.12  V \n",
      "The output of the difference amplifier is  = 0.12  V \n",
      "the common mode input of difference amplifier is = 2.00  \n",
      "the common mode gain ACM of difference amplifier is = 0.06  \n",
      "the differential gain of the difference amplifier is = 2.00  \n",
      "The common mode rejection ratio CMRR is  = 32.00  \n",
      "The common mode rejection ratio CMRR in decibel is  = 30.10  dB \n"
     ]
    }
   ],
   "source": [
    "# determine Vo when 1) VI1 = 2 V VI2 = -2 V and 2) VI1 = 2 V VI2 = 2 V\n",
    "#                                      and common mode rejection ratio CMRR\n",
    "R1 = 10*10**3 # # ohm\n",
    "R2 = 20*10**3 # # ohm\n",
    "R3 = 10*10**3 # # ohm\n",
    "R4 = 22*10**3 # # ohm\n",
    "\n",
    "\n",
    "# the output of the difference amplifier is given by\n",
    "# Vo = (((R4)/(R3+R4))*(((1+(R2/R1))*VI2))-((R2/R1)*VI1))#\n",
    "\n",
    "# Case 1 when VI1 = 2 V VI2 = -2 V\n",
    "VI1 = 2 #\n",
    "VI2 = -2 #\n",
    "\n",
    "Vo = (((R4)/(R3+R4))*(((1+(R2/R1))*VI2))-((R2/R1)*VI1))#\n",
    "print 'The output of the difference amplifier is  = %0.2f'%Vo,' V '#\n",
    "\n",
    "# case 2 when VI1 = 2 V VI2 = 2 V\n",
    "VI1 = 2 #\n",
    "VI2 = 2 #\n",
    "\n",
    "Vo = (((R4)/(R3+R4))*(((1+(R2/R1))*VI2))-((R2/R1)*VI1))#\n",
    "print 'The output of the difference amplifier is  = %0.2f'%Vo,' V '#\n",
    "\n",
    "# the common mode input of difference amplifier is given by\n",
    "VCM = (VI2+VI1)/2 #\n",
    "print 'the common mode input of difference amplifier is = %0.2f'%VCM,' '#\n",
    "\n",
    "# the common mode gain ACM of difference amplifier is given by\n",
    "ACM = Vo/VCM\n",
    "print 'the common mode gain ACM of difference amplifier is = %0.2f'%ACM,' '#\n",
    "\n",
    "# the differential gain of the difference amplifier is given \n",
    "Ad = R2/R1 # \n",
    "print 'the differential gain of the difference amplifier is = %0.2f'%Ad,' '#\n",
    "\n",
    "# the common mode rejection ratio CMRR is \n",
    "CMRR = abs(Ad/ACM)#\n",
    "print 'The common mode rejection ratio CMRR is  = %0.2f'%CMRR,' '#\n",
    "\n",
    "# in decibal it can be expressed as\n",
    "CMRR = 20*log10(CMRR)#\n",
    "print 'The common mode rejection ratio CMRR in decibel is  = %0.2f'%CMRR,' dB '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.10 Pg 195"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the maximum differential voltage gain of the instrumentation amplifier is = 101.00  \n",
      "the minimum differential voltage gain of the instrumentation amplifier is = 5.00  \n",
      " the range of the differential voltage gain of the instrumentation amplifier is \n",
      "                    5 <= Av <= 101 \n"
     ]
    }
   ],
   "source": [
    "# To determine the range of the differential voltage gain\n",
    "#R1 = 1 K ohm to 25 K ohm #\n",
    "R2 = 50 # # K ohm\n",
    "R3 = 10 #  # K ohm\n",
    "R4 = 10 # # K ohm\n",
    "\n",
    "# the output of instrumentation amplifier is given by\n",
    "#Vo = (R4/R3)*(1+(2*R2/R1))*(VI@-VI1)#\n",
    "\n",
    "# the differential voltage gain of the instrumentation amplifier can be written as\n",
    "#Av = (Vo/(VI2-VI1)) = (R4/R3)*(1+(2R2/R1))#\n",
    "\n",
    "# For R1 = 1 K ohm   the maximum differential voltage gain of the instrumentation amplifier is\n",
    "R1 = 1 # # K ohm\n",
    "Av = (R4/R3)*(1+(2*R2/R1))#\n",
    "print 'the maximum differential voltage gain of the instrumentation amplifier is = %0.2f'%Av,' '#\n",
    "\n",
    "# For R1 = 25 K ohm   the mminimum differential voltage gain of the instrumentation amplifier is\n",
    "R1 = 25 # # K ohm\n",
    "Av = (R4/R3)*(1+(2*R2/R1))#\n",
    "print 'the minimum differential voltage gain of the instrumentation amplifier is = %0.2f'%Av,' '#\n",
    "\n",
    "print ' the range of the differential voltage gain of the instrumentation amplifier is '#\n",
    "print '                    5 <= Av <= 101 '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.11 Pg 196"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The variable resistance R1 varies is  401 ohm <= R1 <= 100.2 K-ohm \n"
     ]
    }
   ],
   "source": [
    "# To design an instrumentation amplifier\n",
    "# 4 <= Av <= 1000 #  gain\n",
    "Ad = 2 #\n",
    "Res = 100 #  # K ohm\n",
    "\n",
    "# we cosider the variable resistance is R1 , the maximum and the minimum range of variable resistance \n",
    "# R1min = R1 #             \n",
    "# R1max = R1+100 #\n",
    "\n",
    "# the gain of difference amplifier \n",
    "#A3 = Ad = Vo/(Vo2-Vo1) = (R4/R3)\n",
    "\n",
    "# the maximum range of differential voltage gain Avmax = 1000 when R1min = R1\n",
    "#Avmax = R4/R3*(1+(2*R2/R1min))#\n",
    "\n",
    "# by solvin we get following equation\n",
    "#  499*R1-2*R2=0                       equation 1\n",
    "\n",
    "# the maximum range of differential voltage gain Avmin =4 when R1max = R1+100 K ohm\n",
    "# Avmin = (R4/R3)*(1+(2R2/R1max))#\n",
    "\n",
    "# by solving above equation we get\n",
    "# R1 -2 R2 = -200 K ohm                equation 2\n",
    "\n",
    "#by solving equation 1 and 2 we get\n",
    "R1 = 401 # #  ohm\n",
    "R2 = 100.2 # # ohm\n",
    "print 'The variable resistance R1 varies is  401 ohm <= R1 <= 100.2 K-ohm ' #"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.12 Pg 198"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " The time constant of the given filter is RC = 0.20 msec \n"
     ]
    }
   ],
   "source": [
    " # Determine the time constant of the integrator\n",
    "Vo = 10 #\n",
    "t = 2*10**-3 #\n",
    "VI = -1 #  # at t =0 #\n",
    "\n",
    "# The output voltage of an integrator is define as\n",
    "RC = t/10*1e3 # ms\n",
    "print ' The time constant of the given filter is RC = %0.2f'%RC,'msec '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.13 Pg 198"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      " The time constant of the given filter is RC = 0.1 msec \n",
      "The capacitor value is = 0.1 F\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Determine the time constant of the integrator\n",
    "Vo = 20 #\n",
    "t = 1*10**-3 #\n",
    "VI = -1 #  # at t =0 #\n",
    "\n",
    "# The output voltage of an integrator is define as\n",
    "RC = t/10 #\n",
    "print ' The time constant of the given filter is RC = %0.1f'%(RC*1000),'msec '#\n",
    "\n",
    "R = 1*10**3 #  # we assume \n",
    "C = RC/R*10**6 #\n",
    "print 'The capacitor value is = %0.1f'%C,'F'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.14 Pg 199"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of resistance RIa is = 90.00  K ohm \n",
      "The value of resistance RIb is = 22.50  K ohm \n",
      "The value of resistance RIc is = 18.00  K ohm \n",
      "The value of resistance RId is = 15.00  K ohm \n"
     ]
    }
   ],
   "source": [
    " # to design a summing amplifier\n",
    "\n",
    "# the output of the summing amplifier is given by\n",
    "#Vo = -R2*((VIa/RIa)+(VIb/RIb)+(VIc/RIc)+(VId/RId))#    equation 1\n",
    "\n",
    "# the equation given is\n",
    "#Vo = -(3*VIa+12*VIb+15*VIc+18*VId)#               equation 2\n",
    "\n",
    "# comparing equation 1 and 2\n",
    "#R2/RIa = 3 #\n",
    "#R2/RIb = 12 #\n",
    "#R2/RIc = 15 #\n",
    "#R2/RId = 18 # \n",
    "\n",
    "# the feedback resistance R2= 270 K ohm \n",
    "R2 = 270 #  # K ohm\n",
    "RIa = R2/3 #\n",
    "print 'The value of resistance RIa is = %0.2f'%RIa,' K ohm '#\n",
    "\n",
    "RIb = R2/12 #\n",
    "print 'The value of resistance RIb is = %0.2f'%RIb,' K ohm '#\n",
    "\n",
    "RIc = R2/15 #\n",
    "print 'The value of resistance RIc is = %0.2f'%RIc,' K ohm '#\n",
    "\n",
    "RId = R2/18 #\n",
    "print 'The value of resistance RId is = %0.2f'%RId,' K ohm '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.15 Pg 200"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output of first op-amp A1 is = -275*sin wt mV \n",
      "The output of second op-amp A2 is = 275*sin wt mV \n",
      "The output of third op-amp A3 is = 825*sin wt mV \n",
      "current through the resistor R1 and R2 is = 5 sin wt uA \n",
      "current through the non-inverting terminal resistor R3 and R4 = 5.5 sin wt uA \n",
      "current through the inverting terminal resistor R3 and R4 = 22 sin wt uA \n"
     ]
    }
   ],
   "source": [
    "# for the instrumentation amplifier find Vo1 , Vo2 , Vo \n",
    "# Vi1 = -25 sin wt  #  # mV\n",
    "# Vi2 = 25 sin wt # # mV\n",
    "R1 = 10*10**3 #\n",
    "R2 = 20*10**3 #\n",
    "R3 = 20*10**3 #\n",
    "R4 = 10*10**3 #\n",
    "\n",
    "# the output of first op-amp A1 is given by\n",
    "# Vo1 = (1+(R2/R1))*Vi1-(R2/R1)*Vi2 #\n",
    "#by solving above equation we get\n",
    "print 'The output of first op-amp A1 is = -275*sin wt mV '#\n",
    "\n",
    "# the output of second op-amp A2 is given by\n",
    "# Vo2 = (1+(R2/R1))*Vi2-(R2/R1)*Vi1 #\n",
    "#by solving above equation we get\n",
    "print 'The output of second op-amp A2 is = 275*sin wt mV '#\n",
    "\n",
    "# the output of third op-amp A3 is given by\n",
    "# Vo = (R4/R3)-(1+(2R2/R1)*(Vi2-Vi1) #\n",
    "#by solving above equation we get\n",
    "print 'The output of third op-amp A3 is = 825*sin wt mV '#\n",
    "\n",
    "# current through the resistor R1 and R2 is\n",
    "#i = (Vi1-Vi2)/R1 #\n",
    "print 'current through the resistor R1 and R2 is = 5 sin wt uA '#\n",
    "\n",
    "# current through the non-inverting terminal resistor R3 and R4 \n",
    "#i3 = Vo2/(R3+R4)#\n",
    "print 'current through the non-inverting terminal resistor R3 and R4 = 5.5 sin wt uA '#\n",
    "\n",
    "# current through the inverting terminal resistor R3 and R4 \n",
    "#i2 = Vo1-(R3/(R3+R4))*Vo2/R3 #\n",
    "print 'current through the inverting terminal resistor R3 and R4 = 22 sin wt uA '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.16 Pg 202"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The input resistance Rin is = 0.00999  ohm \n",
      "The value of Resistance Rs is = 1.0990  K ohm \n"
     ]
    }
   ],
   "source": [
    " # for the a current to voltage converter show a) Rin = (Rf/1+Aop)  b) Rf = 10 K ohm Aop = 1000 \n",
    "\n",
    "#a) The input resistance given as\n",
    "#Rin = (Rf)/(1+Aop) #\n",
    "\n",
    "# The input resistance of the circuit can be written as\n",
    "#Rin = (V1/i!)#\n",
    "\n",
    "#  the feedback current of the given circuit is defined as\n",
    "#i1 =(V1-Vo)/RF #\n",
    "\n",
    "# the feedback resistance RF is \n",
    "#RF =(V1-Vo)/i1 #\n",
    "\n",
    "# The output voltage Vo is\n",
    "#Vo = -Aop*V1 #\n",
    "\n",
    "#by using this output feedback currenty i1 can be reformed as\n",
    "#i1 = (V1-(-Aop*V1))/RF #\n",
    "\n",
    "#i1 = V1*(1+Aop)/RF #\n",
    "\n",
    "# Then Rin Becomes \n",
    "#Rin =Rf/(1+Aop)#\n",
    "\n",
    "Rf =10*10**3 #\n",
    "Aop = 1000 #\n",
    "\n",
    "# the input current and output voltage of the circuit are defined as\n",
    "#i1 =(Rs)/(Rs+Rin) #\n",
    "# Vo = -(Aop*(RF/1+Aop))*i1 #\n",
    "\n",
    "#the input resistance Rin is \n",
    "Rin =(Rf/(1+Aop)) #\n",
    "\n",
    "# subsituting the value of RF Aop Rin and Vo we get \n",
    "RF = 10 #\n",
    "Rin = RF/(1+Aop)\n",
    "print 'The input resistance Rin is = %0.5f'%Rin,' ohm '#\n",
    "\n",
    "Aop = 1000 #\n",
    "#(1000/1001)*(Rs/(Rs*0.00999))> 0.99 #\n",
    "# by solving above equation we get \n",
    "Rs = 1.099  #  # K ohm \n",
    "print 'The value of Resistance Rs is = %0.4f'%Rs,' K ohm '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.17 Pg 204"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for Aop = 10**4 closed loop gain is = 0.9999  \n",
      "for Aop = 10**3 closed loop gain is = 0.9990  \n",
      "for Aop = 10**2 closed loop gain is = 0.9901  \n",
      "for Aop = 10**1 closed loop gain is = 0.9091  \n"
     ]
    }
   ],
   "source": [
    " # determine the closed loop gain\n",
    "\n",
    "# the output of the voltage follower is given as\n",
    "#Vo = Aop(V1-Vo)#\n",
    "\n",
    "# the closed loop gain of the voltage follower \n",
    "#A = 1/(1+(1/Aop))#\n",
    " \n",
    "# for Aop = 10**4 closed loop gain\n",
    "Aop = 10**4 #\n",
    "A = 1/(1+(1/Aop))#\n",
    "print 'for Aop = 10**4 closed loop gain is = %0.4f'%A,' '#\n",
    "\n",
    "# for Aop = 10**3 closed loop gain\n",
    "Aop = 10**3 #\n",
    "A = 1/(1+(1/Aop))#\n",
    "print 'for Aop = 10**3 closed loop gain is = %0.4f'%A,' '#\n",
    "\n",
    "# for Aop = 10**2 closed loop gain\n",
    "Aop = 10**2 #\n",
    "A = 1/(1+(1/Aop))#\n",
    "print 'for Aop = 10**2 closed loop gain is = %0.4f'%A,' '#\n",
    "\n",
    "# for Aop = 10**1 closed loop gain\n",
    "Aop = 10**1 #\n",
    "A = 1/(1+(1/Aop))#\n",
    "print 'for Aop = 10**1 closed loop gain is = %0.4f'%A,' '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.18 Pg 205"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "for the frequency f = 10 Hz  the output is = 106.10  V \n",
      "for the frequency f = 1000 Hz  the output is = 1.06  V \n",
      "for the frequency f = 10000 Hz  the output is = 0.106  V \n"
     ]
    }
   ],
   "source": [
    "from math import pi\n",
    "# To determine the output voltage of integrator\n",
    "Vin = 1 #\n",
    "R = 150*10**3 ##  ohm\n",
    "C = 1*10**-9 # # F\n",
    "\n",
    "# the output voltage of an integrator is given as\n",
    "#Vo = (fc/f)*Vin #\n",
    "\n",
    "#fc = 1/(2*pi*R*C)#\n",
    "\n",
    "#Vo = (1/(2*pi*R*C*f))*Vin#\n",
    "\n",
    "#for the frequency f = 10 Hz  the output is\n",
    "f = 10 # # Hz\n",
    "Vo = (1/(2*pi*R*C*f))*Vin#\n",
    "print 'for the frequency f = 10 Hz  the output is = %0.2f'%Vo,' V '#\n",
    "\n",
    "#for the frequency f = 1000 Hz  the output is\n",
    "f = 1000 # # Hz\n",
    "Vo = (1/(2*pi*R*C*f))*Vin#\n",
    "print 'for the frequency f = 1000 Hz  the output is = %0.2f'%Vo,' V '#\n",
    "\n",
    "#for the frequency f = 10000 Hz  the output is\n",
    "f = 10000 # # Hz\n",
    "Vo = (1/(2*pi*R*C*f))*Vin#\n",
    "print 'for the frequency f = 10000 Hz  the output is = %0.3f'%Vo,' V '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.19 Pg 206"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The cutoff frequency of the integrator is = 13.263 kHz\n",
      "The gain of the integrator is = 3.18\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt\n",
    "# To determine the magnitude gain of the integrator\n",
    "Vin = 1 #\n",
    "f = 50*10**3 #\n",
    "Rf = 120*10**3 #\n",
    "R = 10*10**3 #\n",
    "C = 0.1*10**-9 #\n",
    "\n",
    "# the magnitude gain of the integrator is given by\n",
    "#A = (Rf/R)/(sqrt(1+(f/fc)**2))#\n",
    "\n",
    "# the cutoff frequency of the integrator \n",
    "fc = 1/(2*pi*Rf*C)/1e3\n",
    "print 'The cutoff frequency of the integrator is = %0.3f'%fc,'kHz'#\n",
    "\n",
    "\n",
    "A = (Rf/R)/(sqrt(1+(f/fc)**2))*1e3#\n",
    "print 'The gain of the integrator is = %0.2f'%A"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.20 Pg 207"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the break frequency fa is = 31.83 kHz \n",
      "the break frequency fb is = 21.22 kHz \n",
      "The gain of the differentiator is = 0.6667  \n"
     ]
    }
   ],
   "source": [
    " # To determine the magnitude gain of the differentiator\n",
    "Vin = 1 #\n",
    "f = 50*10**3 #\n",
    "R = 75*10**3 #\n",
    "R1 = 50*10**3 #\n",
    "C = 0.1*10**-9 #\n",
    "\n",
    "# the magnitude gain of the differentiator is given by\n",
    "#A = (f/fa)/(sqrt(1+(f/fb)**2))#\n",
    "\n",
    "# the break frequency fa is defined as\n",
    "fa = 1/(2*pi*R1*C) / 1e3\n",
    "print 'the break frequency fa is = %0.2f'%fa,'kHz '#\n",
    "\n",
    "# the break frequency fb is defined as\n",
    "fb = 1/(2*pi*R*C) /1e3\n",
    "print 'the break frequency fb is = %0.2f'%fb,'kHz '#\n",
    "\n",
    "\n",
    "A = (f/fa)/(sqrt(1+(f/fb)**2))#\n",
    "print 'The gain of the differentiator is = %0.4f'%A,' '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.21 Pg 209"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The input voltage of an op-amp is = -40 mV\n"
     ]
    }
   ],
   "source": [
    " # to determine the input voltage of an op-amp\n",
    "Vo = 2 # # V\n",
    "R1 = 20*10**3 # # ohm\n",
    "R2 = 1*10**6 #  # ohm\n",
    "\n",
    "# the input voltage of an op-amp\n",
    "Vin = -(R1/R2)*Vo *1000 # mV\n",
    "print 'The input voltage of an op-amp is = %0.f'%Vin,'mV'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.22 Pg 209"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the output voltage of follower Vo1 is = 2.00   V\n",
      "The output voltage of an inverting amplifier is = -20.00  V \n"
     ]
    }
   ],
   "source": [
    "# To determine the output voltage\n",
    "Vin = 2 #\n",
    "R2 = 20*10**3 #\n",
    "R1 = 2*10**3 #\n",
    "\n",
    "# the output voltage of follower Vo1 is\n",
    "Vo1 = Vin #\n",
    "print 'the output voltage of follower Vo1 is = %0.2f'%Vo1,'  V'#\n",
    "# the output voltage of an inverting amplifier\n",
    "Vo = -(R2/R1)*Vo1 #\n",
    "print 'The output voltage of an inverting amplifier is = %0.2f'%Vo,' V '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.23 Pg 210"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output of the inverting amplifier is = -15.00  V\n",
      "The output of the non-inverting amplifier is = 20.00  V\n"
     ]
    }
   ],
   "source": [
    "# to determine the output voltage of an op-amp\n",
    "Vin = 5 # # V\n",
    "R1 = 25*10**3 # # ohm\n",
    "R2 = 75*10**3 #  # ohm\n",
    "\n",
    "# in this problem op-amp A1 perform the voltage follower and op-amp A2 perform inverting amplifier and op-amp A3 perform non-inverting amplifier\n",
    "\n",
    "# the output voltage of follower op-amp A1\n",
    "Vo1 = Vin #\n",
    "\n",
    "# the output of the inverting amplifier A2\n",
    "Vo2 = -((R2/R1)*Vo1) #\n",
    "print 'The output of the inverting amplifier is = %0.2f'%Vo2,' V'#\n",
    "\n",
    "# the output of the non-inverting amplifier A3\n",
    "Vo =(1+(R2/R1))*Vo1 #\n",
    "print 'The output of the non-inverting amplifier is = %0.2f'%Vo,' V'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.24 Pg 211"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output voltage of an inverting amplifier is = 27.50  V \n",
      "the output voltage of follower Vo1 is = 2.50   V\n",
      "the output of the inverting summing amplifier is = 101.25  V \n"
     ]
    }
   ],
   "source": [
    " # To determine the output voltage\n",
    "Vin = 2.5 #\n",
    "Rf = 100*10**3 #\n",
    "R1 = 10*10**3 #\n",
    "RI1 = 25*10**3 #\n",
    "RI2 = 10*10**3 #\n",
    "R2 = 100*10**3 #\n",
    "\n",
    "# the output voltage of an inverting amplifier\n",
    "Vo1 = (1+(R2/R1))*Vin # #\n",
    "print 'The output voltage of an inverting amplifier is = %0.2f'%Vo1,' V '#\n",
    "\n",
    "# the output voltage of follower Vo2 is\n",
    "Vo2 = Vin #\n",
    "print 'the output voltage of follower Vo1 is = %0.2f'%Vo2,'  V'#\n",
    "\n",
    "# the output of the inverting summing amplifier\n",
    "R2 = 75*10**3 #\n",
    "Vo = R2*((Vo1/RI1)+(Vo2/RI2))#\n",
    "print 'the output of the inverting summing amplifier is = %0.2f'%Vo,' V '#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.25 Pg 212"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the total gain of the circuit is = 36.00  \n",
      "The  output voltage of the op-amp is = 90.00  V\n"
     ]
    }
   ],
   "source": [
    "# To calculate the output voltage\n",
    "Vin = 2.5 # \n",
    "R1 = 10*10**3 #\n",
    "R2 = 10*10**3 #\n",
    "R3 = 10*10**3 #\n",
    "Rf = 30*10**3 #\n",
    "\n",
    "# the total gain of the circuit \n",
    "#Av =A1v*A2v*A3v #\n",
    "Av = (1+(Rf/R1))*(-Rf/R2)*(-Rf/R3)#\n",
    "print 'the total gain of the circuit is = %0.2f'%Av,' '#\n",
    "\n",
    "# The  output voltage of the op-amp \n",
    "Vo = Av*Vin #\n",
    "print 'The  output voltage of the op-amp is = %0.2f'%Vo,' V'#"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.26 Pg 212"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output of op-amp A1 is = -10.00 V1\n",
      "The output of op-amp A2 is  Vo = 40V1 - 2V2 \n",
      "The output is equal to the difference between 40V1 and 2V2 \n"
     ]
    }
   ],
   "source": [
    "# to calculate the output voltage of op-amp circuit\n",
    "Rf = 100*10**3 # # ohm\n",
    "R1 = 10*10**3 # # ohm\n",
    "R2 = 25*10**3 # # ohm\n",
    "R3 = 50*10**3 # # ohm\n",
    "\n",
    "# the output of op-amp A1 is\n",
    "# VA1 = (-Rf/R1)*V1 #\n",
    "VA1 = (-Rf/R1)#\n",
    "print 'The output of op-amp A1 is = %0.2f'%VA1,'V1' #       # *V1 because the output is come from 1 op-amp\n",
    "\n",
    "# the output of op-amp A2 is\n",
    "# Vo = -Rf*((VA1/R2)+(V2/R3))#\n",
    "#Vo = -100*(-0.4*V1+0.02V2)#\n",
    "print 'The output of op-amp A2 is  Vo = 40V1 - 2V2 '#   \n",
    "\n",
    "print 'The output is equal to the difference between 40V1 and 2V2 '#   "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.27 Pg 213"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the upper crossover voltage of schmitt trigger is = 1.00  V\n",
      "the lower crossover voltage of schmitt trigger is = -1.00  V\n",
      "the hysteresis width HW of schmitt trigger is = 2.00  V\n"
     ]
    }
   ],
   "source": [
    " # to determine the hysteresis width of a schmitt trigger\n",
    "R1 = 25*10**3 # # ohm\n",
    "R2 = 75*10**3 # # ohm\n",
    "VTH = 4 # # V\n",
    "VTL = -4 # # V\n",
    "\n",
    "# the upper crossover voltage of schmitt trigger is defined as\n",
    "VU = (R1/(R1+R2))*VTH#\n",
    "print 'the upper crossover voltage of schmitt trigger is = %0.2f'%VU,' V'\n",
    "\n",
    "# the lower crossover voltage of schmitt trigger is defined as\n",
    "VL = (R1/(R1+R2))*VTL#\n",
    "print 'the lower crossover voltage of schmitt trigger is = %0.2f'%VL,' V'\n",
    "\n",
    "# the hysteresis width of schmitt trigger is\n",
    "HW = VU-VL #\n",
    "print 'the hysteresis width HW of schmitt trigger is = %0.2f'%HW,' V'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.28 Pg 214"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the upper crossover voltage of schmitt trigger is = 1.43  V\n",
      "the lower crossover voltage of schmitt trigger is = -1.43  V\n",
      "the hysteresis width HW of schmitt trigger is = 2.86  V\n"
     ]
    }
   ],
   "source": [
    " # to determine the hysteresis width of a schmitt trigger\n",
    "R1 = 15*10**3 # # ohm\n",
    "R2 = 90*10**3 # # ohm\n",
    "VTH = 10 # # V\n",
    "VTL = -10 # # V\n",
    "\n",
    "# the upper crossover voltage of schmitt trigger is defined as\n",
    "VU = (R1/(R1+R2))*VTH#\n",
    "print 'the upper crossover voltage of schmitt trigger is = %0.2f'%VU,' V'\n",
    "\n",
    "# the lower crossover voltage of schmitt trigger is defined as\n",
    "VL = (R1/(R1+R2))*VTL#\n",
    "print 'the lower crossover voltage of schmitt trigger is = %0.2f'%VL,' V'\n",
    "\n",
    "# the hysteresis width of schmitt trigger is\n",
    "HW = VU-VL #`\n",
    "print 'the hysteresis width HW of schmitt trigger is = %0.2f'%HW,' V'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.29 Pg 214"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance R1 is = 5.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# to determine the resistance R1 when low and high saturated output states are given\n",
    "R2 = 20*10**3 # # ohm\n",
    "VH = 2 # # V      crossover voltage\n",
    "VL = -2 #  # V     crossover voltage\n",
    "VOH = 10 # # V    saturated output states\n",
    "VOL = -10 # # V    saturated output states\n",
    "\n",
    "# the upper crossover voltage of schmitt trigger is defined as\n",
    "# V = (R1/(R1+R2))*VOH#\n",
    "# solving above equation we get \n",
    "# 2R1+2R2 = 10R1 #\n",
    "R1 = (2*R2)/8/1000 # kohm\n",
    "print 'the value of resistance R1 is = %0.2f'%R1,'kohm'"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 6.30 Pg 215"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "the value of resistance R2 is = 30.00 kohm\n"
     ]
    }
   ],
   "source": [
    "# to determine the value of resistance R1 and R2 when low and high saturated output states are given\n",
    "VH = 3 # # V      crossover voltage\n",
    "VL = -3 #  # V     crossover voltage\n",
    "VOH = 12 # # V    saturated output states\n",
    "VOL = -12 # # V    saturated output states\n",
    "\n",
    "# the upper crossover voltage of schmitt trigger is defined as\n",
    "# V = (R1/(R1+R2))*VOH#\n",
    "# solving above equation we get \n",
    "# 3R1+3R2 = 12R1 #\n",
    "\n",
    "# 3*R1 = R2 #\n",
    "R1 = 10*10**3 # # ohm  we assume\n",
    "R2 = 3*R1 / 1e3#\n",
    "print 'the value of resistance R2 is = %0.2f'%R2,'kohm'"
   ]
  }
 ],
 "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.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}