summaryrefslogtreecommitdiff
path: root/Linear_Integrated_Circuit_by_M._S._Sivakumar/Ch7.ipynb
blob: b665ce024167b7a6cc3252bda12d5529109b64a8 (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 7 Filters and Rectifiers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.1 Pg 232"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistor value is = 1.59  k ohm \n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "from math import pi, sqrt\n",
    "# Design active low filter with cut-off frequency 10 kHz\n",
    "fc = 10 # # kHz\n",
    "C = 0.01 # #uF # we assume\n",
    "\n",
    "# the cut-off frequency of active low pass filter is defined as\n",
    "# fc = (1/2*pi*R3*C)#\n",
    "\n",
    "# R3 can be calculated as\n",
    "R3 = (1/(2*pi*fc*C))#\n",
    "print 'The resistor value is = %0.2f'%R3,' k ohm '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.2 Pg 233"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistor value is = 106  ohm \n",
      "The pass band gain is = 1.50  \n"
     ]
    }
   ],
   "source": [
    " # Design active low filter with cut-off frequency 15 kHz\n",
    "fc = 15*10**3 # # Hz \n",
    "C = 0.1*10**-6 # #F # we assume\n",
    "\n",
    "# the cut-off frequency of active low pass filter is defined as\n",
    "# fc = (1/2*pi*R3*C)#\n",
    "\n",
    "# R3 can be calculated as\n",
    "R3 = (1/(2*pi*fc*C))#\n",
    "print 'The resistor value is = %0.f'%R3,' ohm '\n",
    "\n",
    "# the pass band gain of filter is given by\n",
    "# Af = 1+(R2/R1)#\n",
    "# assume that the inverting terminal resistor R2=0.5*R1#\n",
    "# in Af equation if we put R2=0.5R1 in R1 R1 cancellout each other \n",
    "Af = 1+(0.5)\n",
    "print 'The pass band gain is = %0.2f'%Af,' '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.3 Pg 234"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistor value is = 159  Kohm \n",
      "The resistor R2 value is = 900.00  k ohm \n",
      "The magnitude of an active low pass filter is = 1.96  \n",
      "The phase angle of the filter is = -78.69  \n"
     ]
    }
   ],
   "source": [
    "from __future__ import division\n",
    "# Design active low filter with cut-off frequency 20 kHz\n",
    "fc = 20 # # kHz \n",
    "f = 100 # # frequency of filter\n",
    "Af = 10 #  # desired pass band gain\n",
    "C = 0.05 # #nF # we assume\n",
    "\n",
    "# the cut-off frequency of active low pass filter is defined as\n",
    "# fc = (1/2*pi*R3*C)#\n",
    "\n",
    "# R3 can be calculated as\n",
    "R3 = (1/(2*pi*fc*1e3*C*1e-9))/1e3 # Kohm\n",
    "print 'The resistor value is = %0.f'%R3,' Kohm '\n",
    "\n",
    "# the pass band gain of filter is given by\n",
    "# Af = 1+(R2/R1)#\n",
    "# assume that the inverting terminal resistor R1= 100 k ohm#\n",
    "R1 = 100 # # k ohm\n",
    "R2 = (Af*R1)-R1#\n",
    "print 'The resistor R2 value is = %0.2f'%R2,' k ohm '\n",
    "\n",
    "# the magnitude of an active low pass filter is given as\n",
    "A = Af/(sqrt(1+(f/fc)**2))#\n",
    "print 'The magnitude of an active low pass filter is = %0.2f'%A,' '\n",
    "\n",
    "#the phase angle of the filter\n",
    "from math import atan , degrees\n",
    "Angle = -degrees(atan(f/fc))#\n",
    "print 'The phase angle of the filter is = %0.2f'%Angle,' '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.4 Pg 236"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The frequency of the first order low pass filter is = 2.65  kHz \n",
      "The pass band gain of filter is = 13.00 \n"
     ]
    }
   ],
   "source": [
    " # to determine the cut-off frequency and pass band gain Af\n",
    "R1 = 1 # # k ohm\n",
    "R2 = 12 # # k ohm\n",
    "R3 = 1.2 #  # k ohm\n",
    "C = 0.05 # #uF # we assume\n",
    "\n",
    "# the frequency of the first order low pass filter is defined as\n",
    "fc = (1/(2*pi*R3*C))#\n",
    "print 'The frequency of the first order low pass filter is = %0.2f'%fc,' kHz '\n",
    "\n",
    "# the pass band gain of filter is given by\n",
    "Af =(1+R2/R1)#\n",
    "print 'The pass band gain of filter is = %0.2f'%Af,''"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.5 Pg 236"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The capacitor of high pass filter is = 25.13  uF \n",
      "The second resistor value is = 90.00  K ohm \n"
     ]
    }
   ],
   "source": [
    " # to design a first order high pass filter with cut-off frequency 2kHz\n",
    "Af = 10 #\n",
    "fc = 2 # # kHz \n",
    "R3 = 2 # #K ohm # we assume\n",
    "R1 = 10 # # k ohm\n",
    "# the capacitor of high pass filter is given by\n",
    "C = 2*pi*R3*fc#\n",
    "print 'The capacitor of high pass filter is = %0.2f'%C,' uF '\n",
    "\n",
    "# the voltage gain of the high pass filter is\n",
    "# Af = 1+(R2/R1)#\n",
    "R2 = R1*(Af-1)#\n",
    "print 'The second resistor value is = %0.2f'%R2,' K ohm '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.6 Pg 237"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistance R3 is = 1.59  K ohm \n"
     ]
    }
   ],
   "source": [
    " # to design an active high pass filter with cut-off frequency 10kHz\n",
    "fc = 10 # # kHz \n",
    "C = 0.01 # #uF # we assume\n",
    "# the cut-off frequency of active high pass filter is given by\n",
    "# fc = 2*pi*R3*C#\n",
    "# R3 can be calculated as\n",
    "R3 = (1/(2*pi*fc*C))#\n",
    "print 'The resistance R3 is = %0.2f'%R3,' K ohm '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.7 Pg 238"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistance R3 is = 64  Kohm \n",
      "The pass band gain is = 1.20  \n"
     ]
    }
   ],
   "source": [
    "# to design an active high pass filter with cut-off frequency 25kHz\n",
    "fc = 25 # # kHz \n",
    "C = 0.1 # #nF # we assume\n",
    "# the cut-off frequency of active high pass filter is given by\n",
    "# fc = 2*pi*R3*C#\n",
    "# R3 can be calculated as\n",
    "R3 = (1/(2*pi*fc*1e3*C*1e-9)) / 1e3 # Kohm\n",
    "print 'The resistance R3 is = %0.f'%R3,' Kohm '\n",
    "\n",
    "# the desire pass band gain of filter is given by \n",
    "#Af = 1+(R2/R1)#\n",
    "# assume that the inverting terminal resistor R2=0.2*R1#\n",
    "# in Af equation if we put R2=0.2R1 in R1 R1 cancellout each other \n",
    "Af = 1+(0.2)\n",
    "print 'The pass band gain is = %0.2f'%Af,' '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.8 Pg 239"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistance R3 is = 159  K ohm \n",
      "The resistance R2 is = 700.00  K ohm \n",
      "The magnitude of an active high pass filter is = 14.55  \n",
      "The phase angle of the filter is = 14.04  degree\n"
     ]
    }
   ],
   "source": [
    "## # to design an active high pass filter with cut-off frequency 20kHz \n",
    "Af = 15 #\n",
    "fc = 20 # #kHz\n",
    "f = 80 # # kHz  the frequency of filter \n",
    "C = 0.05 # #nF # we assume\n",
    "# the cut-off frequency of active high pass filter is given by\n",
    "# fc = 2*pi*R3*C#\n",
    "# R3 can be calculated as\n",
    "R3 = (1/(2*pi*fc*C))#\n",
    "print 'The resistance R3 is = %0.f'%(R3*1000),' K ohm '  # Round Off Error\n",
    "\n",
    "# the desire pass band gain of filter is given by \n",
    "#Af = 1+(R2/R1)#\n",
    "# assume that the inverting terminal resistor R1=50 K ohm#\n",
    "R1 = 50 # # K ohm\n",
    "R2 = (R1*Af)-(R1)\n",
    "print 'The resistance R2 is = %0.2f'%R2,' K ohm '\n",
    "\n",
    "# the magnitude of an active high pass filter is given as\n",
    "A = Af*(f/fc)/(sqrt(1+(f/fc)**2))#\n",
    "print 'The magnitude of an active high pass filter is = %0.2f'%A,' '\n",
    "\n",
    "#the phase angle of the filter\n",
    "from numpy import inf\n",
    "Angle = degrees(-atan(f/fc)+atan(inf))\n",
    "print 'The phase angle of the filter is = %0.2f'%Angle,' degree'  # Round Off Error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.9 Pg 241"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The lower cut-off frequency FLC of band pass filter is = 159.2  Hz \n",
      "The upper cut-off frequency FUC of band pass filter is = 15.92  kHz \n"
     ]
    }
   ],
   "source": [
    "# to calculate upper and lower cut-off frequency of the band pass filter\n",
    "R1 = 10*10**3 # #K ohm\n",
    "R2 = 10 # #K ohm\n",
    "C1 = 0.1*10**-6 # # uF\n",
    "C2 = 0.001 #  #uF\n",
    "\n",
    "# the lower cut-off frequency of band pass filter is\n",
    "fLC = 1/(2*pi*R1*C1)#\n",
    "print 'The lower cut-off frequency FLC of band pass filter is = %0.1f'%fLC,' Hz '\n",
    "\n",
    "# The upper cut-off frequency of band pass filter is\n",
    "fUC = 1/(2*pi*R2*C2)#\n",
    "print 'The upper cut-off frequency FUC of band pass filter is = %0.2f'%fUC,' kHz '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.10 Pg 242"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistance R3 Value is = 7.96  M ohm \n",
      "The resistance R6 value is = 1.59  M ohm \n"
     ]
    }
   ],
   "source": [
    "# to design an active band pass filter with lower cut-off frequency 10 kHz an upper 50 kHz\n",
    "fL = 10 # # kHz\n",
    "fH = 50 # # kHz\n",
    "C1 = 0.002 # # nF\n",
    "C2 = 0.002 #  # nF\n",
    "\n",
    "# the lower cut-off frequency of band pass filter is\n",
    "# fL = 1/(2*pi*R3*C1)#\n",
    "R3 = 1/(2*pi*fL*C1)#\n",
    "print 'The resistance R3 Value is = %0.2f'%R3,' M ohm '\n",
    "\n",
    "# The upper cut-off frequency of band pass filter is\n",
    "# fH = 1/(2*pi*R6*C2)#\n",
    "R6 = 1/(2*pi*fH*C2)#\n",
    "print 'The resistance R6 value is = %0.2f'%R6,' M ohm '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.11 Pg 243"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistance R3 Value is = 7.96  M ohm \n",
      "The resistance R6 value is = 3.98  M ohm \n",
      "The desire pass band gain of filter is = 15  \n"
     ]
    }
   ],
   "source": [
    "# to design an active band pass filter with lower cut-off frequency 20 kHz an upper 40 kHz\n",
    "fL = 20 # # kHz\n",
    "fH = 40 # # kHz\n",
    "# the inverting terminal resistance 2R1=R2 and 4R4=R5\n",
    "C1 = 0.001 # # nF\n",
    "C2 = 0.001 #  # nF\n",
    "\n",
    "# the lower cut-off frequency of band pass filter is\n",
    "# fL = 1/(2*pi*R3*C1)#\n",
    "R3 = 1/(2*pi*fL*C1)#\n",
    "print 'The resistance R3 Value is = %0.2f'%R3,' M ohm '\n",
    "\n",
    "# The upper cut-off frequency of band pass filter is\n",
    "# fH = 1/(2*pi*R6*C2)#\n",
    "R6 = 1/(2*pi*fH*C2)#\n",
    "print 'The resistance R6 value is = %0.2f'%R6,' M ohm '\n",
    "\n",
    "# the desire pass band gain of filter is defined as\n",
    "R1 = 1 # # M ohm we assume\n",
    "#we define inverting terminal resistance 2R1=R2\n",
    "R2 = 2 # # M ohm\n",
    "# then\n",
    "R4 = 1 # #M ohm\n",
    "R5 = 4 # # M ohm\n",
    "Af = (1+(R2/R1))*(1+(R5/R4))#\n",
    "print 'The desire pass band gain of filter is = %d'%Af,' '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.12 Pg 244"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The resistance R3 Value is = 7.96  M ohm \n",
      "The resistance R6 value is = 1.99  M ohm \n",
      "The desire pass band gain of filter is = 15.00  \n",
      "The magnitude of gain of band pass filter  is = 11.49  \n",
      "The phase angle of gain of band pass filter  is = 50 degree\n"
     ]
    }
   ],
   "source": [
    "# to design an active band pass filter with lower cut-off frequency 20 kHz an upper 80 kHz\n",
    "f = 100 # # kHz  the frequency of band pass filter\n",
    "fL = 20 # # kHz\n",
    "fH = 80 # # kHz\n",
    "# the inverting terminal resistance R1=0.5*R2 and R4=0.25*R5\n",
    "C1 = 0.001 # # nF\n",
    "C2 = 0.001 #  # nF\n",
    "\n",
    "# the lower cut-off frequency of band pass filter is\n",
    "# fL = 1/(2*pi*R3*C1)#\n",
    "R3 = 1/(2*pi*fL*C1)#\n",
    "print 'The resistance R3 Value is = %0.2f'%R3,' M ohm '\n",
    "\n",
    "# The upper cut-off frequency of band pass filter is\n",
    "# fH = 1/(2*pi*R6*C2)#\n",
    "R6 = 1/(2*pi*fH*C2)#\n",
    "print 'The resistance R6 value is = %0.2f'%R6,' M ohm '  # Round Off Error\n",
    "\n",
    "# the desire pass band gain of filter is defined as\n",
    "R1 = 1 # # M ohm we assume\n",
    "#we define inverting terminal resistance R1=0.5*R2\n",
    "R2 = 2 # # M ohm\n",
    "# then\n",
    "R4 = 1 # #M ohm\n",
    "R5 = 4 # # M ohm\n",
    "Af = (1+(R2/R1))*(1+(R5/R4))#\n",
    "print 'The desire pass band gain of filter is = %0.2f'%Af,' '\n",
    "\n",
    "# the magnitude of gain of band pass filter is given as\n",
    "A = Af*(f**2/(fL*fH))/((sqrt(1+(f/fL)**2))*(sqrt(1+(f/fH)**2)))#\n",
    "print 'The magnitude of gain of band pass filter  is = %0.2f'%A,' '  # Round Off Error\n",
    "\n",
    "#the phase angle of the filter\n",
    "from numpy import inf\n",
    "Angle = degrees(2*atan(inf)-atan(f/fL)-atan(f/fH))\n",
    "print 'The phase angle of gain of band pass filter  is = %0.f'%Angle,'degree'  # Round Off Error"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.13 Pg 247"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output of the half wave precision rectifier Vo is = -20.00  V \n"
     ]
    }
   ],
   "source": [
    " # to determine the output voltage of the precision rectifier circuit\n",
    "Vi = 10 # #V i/p volt\n",
    "R1 = 20 # # K ohm\n",
    "R2 = 40 # # K ohm\n",
    "Vd = 0.7 # # V   the diode voltage drop\n",
    "\n",
    "# the output of the half wave precision rectifier is defined as\n",
    "# Vo = -(R2/R1)*Vi # for Vi < 0\n",
    "#    = 0 otherwise\n",
    "# i.e for Vi > 0\n",
    "#              Vo = 0\n",
    "# for Vi < 0\n",
    "Vo = -(R2/R1)*Vi\n",
    "print 'The output of the half wave precision rectifier Vo is = %0.2f'%Vo,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.14 Pg 247"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The output of the half wave precision rectifier Vo is = -15.00  V \n",
      "The output of the half wave precision rectifier Vo is = 15.00  V \n"
     ]
    }
   ],
   "source": [
    "# to determine the output voltage of the precision rectifier circuit for i/p voltage a) Vi = 5 b) Vi = -5\n",
    "Vi = 5 # #V i/p volt\n",
    "R1 = 5 # # K ohm\n",
    "R2 = 15 # # K ohm\n",
    "Vd = 0.7 # # V   the diode voltage drop\n",
    "\n",
    "# the output of the half wave precision rectifier is defined as\n",
    "# Vo = -(R2/R1)*Vi # for Vi < 0\n",
    "#    = 0 otherwise\n",
    "\n",
    "# for Vi = 5 V\n",
    "# i.e for Vi > 0\n",
    "#              Vo = 0\n",
    "# for Vi < 0\n",
    "Vo = -(R2/R1)*Vi#\n",
    "print 'The output of the half wave precision rectifier Vo is = %0.2f'%Vo,' V '\n",
    "\n",
    "# for Vi = -5 V\n",
    "# i.e for Vi > 0\n",
    "#              Vo = 0\n",
    "# for Vi < 0\n",
    "Vi =-5 # # V\n",
    "Vo = -(R2/R1)*Vi#\n",
    "print 'The output of the half wave precision rectifier Vo is = %0.2f'%Vo,' V '"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7.15 Pg 248"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The gain of precision full wave rectifier A is = 6.00  \n",
      "The output voltage Vo is = 42.00  V \n",
      "The output voltage Vo is = 42.00  V \n"
     ]
    }
   ],
   "source": [
    " # to determine the output voltage of the precision rectifier circuit for i/p voltage a) Vi = 7 b) Vi = -7\n",
    "Vi = 7 # #V i/p volt\n",
    "R1 = 5 # # K ohm\n",
    "R3 = 5 # # K ohm\n",
    "R4 = 5 # # K ohm\n",
    "R2 = 15 # # K ohm\n",
    "R5 = 15 # # K ohm\n",
    "Vd = 0.7 # # V   the diode voltage drop\n",
    "\n",
    "# the output of the full wave precision rectifier is defined as\n",
    "# Vo = -A*Vi #      for Vi < 0                      equation 1\n",
    "#    = A*Vi  #      otherwise                       equation 2\n",
    "\n",
    "# or  Vo = abs(A*Vi) #\n",
    "\n",
    "# The gain of precision full wave rectifier\n",
    "A = (((R2*R5)/(R1*R3))-(R5/R4)) #\n",
    "print 'The gain of precision full wave rectifier A is = %0.2f'%A,' '\n",
    "\n",
    "\n",
    "# for Vi = 7 V           the output voltage is\n",
    "Vi = 7 #\n",
    "Vo = -A*Vi #      # from equation 1\n",
    "Vo =  A*Vi #      # from equation 2\n",
    "Vo = abs(A*Vi) #\n",
    "print 'The output voltage Vo is = %0.2f'%Vo,' V '\n",
    "\n",
    "# for Vi = -7 V           the output voltage is\n",
    "Vi = -7 #\n",
    "Vo = -A*Vi #      # from equation 1\n",
    "Vo =  A*Vi #      # from equation 2\n",
    "Vo = abs(A*Vi) #\n",
    "print 'The output voltage Vo is = %0.2f'%Vo,' V '"
   ]
  }
 ],
 "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
}