summaryrefslogtreecommitdiff
path: root/Electronics_Circuits_and_Systems_by_Y._N._Bapat/Ch7.ipynb
blob: af9fd2a9d8db4022fb97217a9ecc527271706d33 (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
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Chapter 7 - Feedback Amplifiers and Sinusoidal Oscillators"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_1 Page No. 204"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A= 60000.00\n",
      "Af= 10000.00\n",
      "N_dB=20*log10(Af/A)= -15.56 dB\n",
      "B=(1/(Af))-(1/A)= 8.33e-05\n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "from __future__ import division  \n",
    "A=60000\n",
    "print \"A= %0.2f\"%(A) #Amplifier gain\n",
    "Af=10000\n",
    "print \"Af= %0.2f\"%(Af) #Feedback gain\n",
    "N_dB=20*log10(Af/A)\n",
    "print \"N_dB=20*log10(Af/A)= %0.2f\"%(N_dB),\"dB\" #Negative feedback gain\n",
    "B=(1/(Af))-(1/A)# formulae using (Af=A/(1+A*B))\n",
    "print \"B=(1/(Af))-(1/A)= %0.2e\"%(B) #Feedback factor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_2 Page No. 205"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "A= 10000.00\n",
      "B= 0.01\n",
      "Af= (A/(1+A*B))=99.01\n",
      "A1= 100000.00\n",
      "Af1= (A1/(1+A1*B))=99.90\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division  \n",
    "A=10000\n",
    "print \"A= %0.2f\"%(A) #Amplifier gain\n",
    "B=0.01\n",
    "print \"B= %0.2f\"%(B) #Feedback factor\n",
    "Af=(A/(1+A*B))\n",
    "print \"Af= (A/(1+A*B))=%0.2f\"%(Af) #Feedback gain\n",
    "A1=100000\n",
    "print \"A1= %0.2f\"%(A1) #New amplifier gain value\n",
    "Af1=(A1/(1+A1*B))\n",
    "print \"Af1= (A1/(1+A1*B))=%0.2f\"%(Af1) #New feedback gain"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_3 Page No. 208"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Vo= 50.00  volts\n",
      "Vi= 0.50  volts\n",
      "part(i)\n",
      "A= Vo/Vi=100.00\n",
      "Harmonic_distortion=10.00 %\n",
      "D= (10*Vo)/100 = 5.00  volts\n",
      "Df= (1*Vo)/100 = 0.50  volts\n",
      "B=(D/(Df*A))-(1/A) = 0.09\n",
      "part(ii)\n",
      "Af= (A/(1+A*B)) = 10.00\n",
      "part(iii)\n",
      "Vif= Vo/Af = 5.00  volts\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division  \n",
    "Vo=(50)\n",
    "print \"Vo= %0.2f\"%(Vo),\" volts\" # output voltage\n",
    "Vi=(0.5)\n",
    "print \"Vi= %0.2f\"%(Vi),\" volts\" # input voltage\n",
    "print \"part(i)\"  \n",
    "A=Vo/Vi\n",
    "print \"A= Vo/Vi=%0.2f\"%(A) #Amplifier gain\n",
    "HD=10\n",
    "print \"Harmonic_distortion=%0.2f\"%(HD),\"%\"# Percentage second harmonic distortion\n",
    "D=(10*Vo)/100\n",
    "print \"D= (10*Vo)/100 = %0.2f\"%(D),\" volts\" # Second Harmonic distortion \n",
    "Df=(1*Vo)/100\n",
    "print \"Df= (1*Vo)/100 = %0.2f\"%(Df),\" volts\" # Harmonic distortion with Feedback\n",
    "B=(D/(Df*A))-(1/A) #Using formulae Df=(D/(1+A*B))\n",
    "print \"B=(D/(Df*A))-(1/A) = %0.2f\"%(B) #Feedback factor\n",
    "print \"part(ii)\" \n",
    "Af=(A/(1+A*B))\n",
    "print \"Af= (A/(1+A*B)) = %0.2f\"%(Af) #Feedback gain\n",
    "print \"part(iii)\" \n",
    "Vif=Vo/Af\n",
    "print \"Vif= Vo/Af = %0.2f\"%(Vif),\" volts\" # New input voltage required"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_4 Page No. 210"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "GBW= 1000000.00  Hz\n",
      "AMf=100.00\n",
      "fHF=GBW/AMf= 10000.00  Hz\n",
      "f_10per cent=(10*fHF)/100= 1000.00  Hz\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division  \n",
    "GBW=10**(6)\n",
    "print \"GBW= %0.2f\"%(GBW),\" Hz\"# Gain-Bandwidth product\n",
    "AMf=100\n",
    "print \"AMf=%0.2f\"%(AMf) # Midband gain with feedback\n",
    "fHF=GBW/AMf\n",
    "print \"fHF=GBW/AMf= %0.2f\"%(fHF),\" Hz\"#Signal bandwidth\n",
    "f_10percent=(10*fHF)/100\n",
    "print \"f_10per cent=(10*fHF)/100= %0.2f\"%(f_10percent),\" Hz\"#Frequency below which AMf will not deviate by more than 10 percent"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_5 Page No. 212"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AM=50000.00\n",
      "fH= 20000.00  Hz\n",
      "fL= 30.00  Hz\n",
      "B= 5.00e-05\n",
      "AMf=AM/(1+B*AM)=14285.71\n",
      "fHf=fH*(1+B*AM)= 70000.00  Hz\n",
      "fLf=fL/(1+B*AM)= 8.57  Hz\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division  \n",
    "AM=50000\n",
    "print \"AM=%0.2f\"%(AM) # Midband gain \n",
    "fH=20*10**(3)\n",
    "print \"fH= %0.2f\"%(fH),\" Hz\"# Upper cut-off frequency\n",
    "fL=30\n",
    "print \"fL= %0.2f\"%(fL),\" Hz\"# Lower cut-off frequency\n",
    "B=5*10**(-5)\n",
    "print \"B= %0.2e\"%(B) #Feedback factor\n",
    "AMf=AM/(1+B*AM)\n",
    "print \"AMf=AM/(1+B*AM)=%0.2f\"%(AMf) # Midband gain with feedback\n",
    "fHf=fH*(1+B*AM)\n",
    "print \"fHf=fH*(1+B*AM)= %0.2f\"%(fHf),\" Hz\"#Upper cut-off frequency with feedback\n",
    "fLf=fL/(1+B*AM)\n",
    "print \"fLf=fL/(1+B*AM)= %0.2f\"%(fLf),\" Hz\"#Lower cut-off frequency with feedback\n",
    "#NOTE: calculated value of AMf is AMf=14285.714  and fLF=8.5714286 but in book given as AMf=14286  and fLF=8.58 Hz"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_6 Page No. 214"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AM=100.00 dB\n",
      "fc1= 10000.00  Hz\n",
      "fc2= 100000.00  Hz\n",
      "fc3= 1000000.00  Hz\n",
      "part(i)\n",
      "Af1=85.00 dB\n",
      "f= 50000.00  Hz\n",
      "theta_A=-108.12  degree\n",
      "theta_pm=180-abs(theta_A)=71.88  degree\n",
      "Amplifier stable\n",
      "part(ii)\n",
      "Af2=50.00  dB\n",
      "f= 500000.00  Hz\n",
      "theta_A= -194.11  degree\n",
      "theta_pm=180-abs(theta_A)=-14.11  degree\n",
      "Amplifier  unstable\n",
      "part(iii)\n",
      "Af3=20.00 dB\n",
      "f= 1100000.00  Hz\n",
      "theta_A=-222.01  degree\n",
      "theta_pm=180-abs(theta_A)=-42.01  degree\n",
      "Amplifier unstable\n"
     ]
    }
   ],
   "source": [
    "from math import atan,pi\n",
    "from __future__ import division  \n",
    "AM=100\n",
    "print \"AM=%0.2f\"%(AM),\"dB\" # Midband gain \n",
    "fc1=1*10**(4)\n",
    "print \"fc1= %0.2f\"%(fc1),\" Hz\"# First Critical frequency\n",
    "fc2=10**5\n",
    "print \"fc2= %0.2f\"%(fc2),\" Hz\"# Second Critical frequency\n",
    "fc3=10**6\n",
    "print \"fc3= %0.2f\"%(fc3),\" Hz\"# Third Critical frequency\n",
    "print \"part(i)\"\n",
    "Af1=85\n",
    "print \"Af1=%0.2f\"%(Af1),\"dB\" #  gain at 50 kHz and -20dB/decade roll-off\n",
    "f=50*10**(3)\n",
    "print \"f= %0.2f\"%(f),\" Hz\"# operating frequency\n",
    "theta_A=- atan(f/fc1)*180/pi-  atan(f/fc2)*180/pi-  atan(f/fc3)*180/pi#phase shift in radians\n",
    "print \"theta_A=%0.2f\"%(theta_A),\" degree\"# Phase shift for feedback gain Af1\n",
    "theta_pm=180-abs(theta_A)# formulae phase margin\n",
    "print \"theta_pm=180-abs(theta_A)=%0.2f\"%(theta_pm),\" degree\"# Phase Margin for feedback gain Af1\n",
    "print \"Amplifier stable\"# Since phase margin is (+)ive\n",
    "print \"part(ii)\"\n",
    "Af2=50\n",
    "print \"Af2=%0.2f\"%(Af2),\" dB\" #  gain at 500 kHz and -40dB/decade roll-off\n",
    "f=500*10**(3)\n",
    "print \"f= %0.2f\"%(f),\" Hz\"#  frequency\n",
    "theta_A=- atan(f/fc1)-  atan(f/fc2)-  atan(f/fc3)#phase shift in radians\n",
    "theta_A=theta_A*180/pi # degree\n",
    "print \"theta_A= %0.2f\"%(theta_A),\" degree\"#  Phase shift for feedback gain Af2\n",
    "theta_pm=180-abs(theta_A)# formulae phase margin\n",
    "print \"theta_pm=180-abs(theta_A)=%0.2f\"%(theta_pm),\" degree\"# Phase Margin for feedback gain Af1\n",
    "print \"Amplifier  unstable\"# Since phase margin is (-)ive\n",
    "print \"part(iii)\"\n",
    "Af3=20\n",
    "print \"Af3=%0.2f\"%(Af3),\"dB\" #  gain at 1100 kHz and -60dB/decade roll-off\n",
    "f=1100*10**(3)\n",
    "print \"f= %0.2f\"%(f),\" Hz\"#  frequency\n",
    "theta_A=- atan(f/fc1)-  atan(f/fc2)-  atan(f/fc3)#phase shift in radians\n",
    "theta_A=theta_A*180/pi # degree\n",
    "print \"theta_A=%0.2f\"%(theta_A),\" degree\"# Phase shift for feedback gain Af3\n",
    "theta_pm=180-abs(theta_A)# formulae phase margin\n",
    "print \"theta_pm=180-abs(theta_A)=%0.2f\"%(theta_pm),\" degree\"# Phase Margin for feedback gain Af1\n",
    "print \"Amplifier unstable\"# Since phase margin is (-)ive\n",
    "#NOTE:Correct ans for part(i) phase margin ,theta_pm=71.882476 degree but in book given as 71.86 degree\n",
    "# correct ans for part(iii) phase shift, theta_A=-222.01103 degree but in book given as -220.02 degree    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_7 Page No. 216"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AV=50000.00\n",
      "Ri= 5.00e+07  ohm\n",
      "R0= 1000.00  ohm\n",
      "AVf=10.00\n",
      "RSf= 50000.00  ohm\n",
      "RF=AVf*(R1)= 5.00e+05  ohm\n",
      "VS= 30.00  volts\n",
      "Vomax=0.5*(VS)= -15.00 , +15.00  volts\n",
      "Vsmax=Vomax/AVf= -1.50 , +1.50  volts\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division  \n",
    "AV=50000\n",
    "print \"AV=%0.2f\"%(AV) # Voltage gain \n",
    "Ri=50*10**(6)\n",
    "print \"Ri= %0.2e\"%(Ri),\" ohm\"  #Input resistance of OP-AMP\n",
    "R0=1*10**(3)\n",
    "print \"R0= %0.2f\"%(R0),\" ohm\"  #Output resistance\n",
    "AVf=10\n",
    "print \"AVf=%0.2f\"%(AVf) # Overall Voltage gain \n",
    "RSf=50*10**(3)\n",
    "print \"RSf= %0.2f\"%(RSf),\" ohm\"  #Source resistance\n",
    "R1=RSf\n",
    "RF=AVf*(R1)\n",
    "print \"RF=AVf*(R1)= %0.2e\"%(RF),\" ohm\"  #Feedback resistance\n",
    "VS=30\n",
    "print \"VS= %0.2f\"%(VS),\" volts\" # Peak-peak output swing voltage\n",
    "Vomax=0.5*(VS)\n",
    "print \"Vomax=0.5*(VS)= -%0.2f\"%(Vomax),\", +%0.2f\"%(Vomax),\" volts\" # Maximum output voltage swing at negative and positive polarities respectively\n",
    "Vsmax=Vomax/AVf\n",
    "print \"Vsmax=Vomax/AVf= -%0.2f\"%(Vsmax),\", +%0.2f\"%(Vsmax),\" volts\" # Maximum output voltage without overload clipping at both polarities\n",
    "\n",
    "\n",
    "#for overall voltage gain author has used two notations 'Avf' and 'Af' ... but I am working with 'Avf' only"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_8 Page No. 218"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "R1= 50000.00  ohm\n",
      "RF= 500000.00  ohm\n",
      "VS= 1.00  volts\n",
      "part(i)\n",
      "A = infinite\n",
      "Vo1=-(RF/R1)= -10.00  volts\n",
      "part(ii)\n",
      "A=50000.00\n",
      "B=R1/(R1+RF)= 0.09\n",
      "Vo2=-((RF)*(B*A))/(R1*(1+A*B))= -10.00  volts\n",
      "%Error,e= ((Vo2-Vo1)*100)/Vo1=0.02 % \n",
      "part(iii)\n",
      "%Error,e=0.01 % \n",
      "Vo3=Vo1-(e*Vo1/100)= 10.00  volts\n",
      "A=(Vo*R1)/(B*RF*(1-(Vo*RF/R1)))=1.10e+05\n"
     ]
    }
   ],
   "source": [
    "from __future__ import division  \n",
    "R1=50*10**(3)\n",
    "print \"R1= %0.2f\"%(R1),\" ohm\"  # resistance at input terminal of OP-AMP\n",
    "RF=500*10**(3)\n",
    "print \"RF= %0.2f\"%(RF),\" ohm\"  #Feedback resistance\n",
    "VS=1\n",
    "print \"VS= %0.2f\"%(VS),\" volts\" # Peak-peak output swing voltage\n",
    "print \"part(i)\"  \n",
    "print \"A = infinite\"# voltage gain\n",
    "Vo1=-(RF/R1) #Output voltage when gain, A=infinite\n",
    "print \"Vo1=-(RF/R1)= %0.2f\"%(Vo1),\" volts\"\n",
    "print \"part(ii)\"  \n",
    "A=50000\n",
    "print \"A=%0.2f\"%(A) #  gain of OP-AMP\n",
    "B=R1/(R1+RF)\n",
    "print \"B=R1/(R1+RF)= %0.2f\"%(B) #Feedback factor\n",
    "Vo2=-((RF)*(B*A))/(R1*(1+A*B))\n",
    "print \"Vo2=-((RF)*(B*A))/(R1*(1+A*B))= %0.2f\"%(Vo2),\" volts\"# output voltage for A=50000\n",
    "e=-((Vo2-Vo1)*100)/Vo1\n",
    "print \"%%Error,e= ((Vo2-Vo1)*100)/Vo1=%0.2f\"%(e),\"% \"#  calculation for percentage error in output voltage\n",
    "print \"part(iii)\"  \n",
    "e=0.01\n",
    "print \"%%Error,e=%0.2f\"%(e),\"% \"#Given percentage error in output voltage\n",
    "Vo3=-(Vo1-(e*Vo1/100))\n",
    "print \"Vo3=Vo1-(e*Vo1/100)= %0.2f\"%(Vo3),\" volts\"# output voltage for error 0.01%\n",
    "x=Vo3*(R1/RF)\n",
    "A=(x)/(B*(1-x)) #using formulae Vo=-(RF/R1)*((B*A)/1+A*B))\n",
    "print \"A=(Vo*R1)/(B*RF*(1-(Vo*RF/R1)))=%0.2e\"%(A) # New Required gain for error less than 0.01%\n",
    "\n",
    "# while solving the problem I have used 'e' for the error as no varriable is given for the same in textbook by author\n",
    "# in textbook author has used 'Vo' for output voltage in all parts.. but to remove any ambiguity in the programe I have used 'Vo1' 'Vo2' 'Vo3' for part i, ii, iii, respectively"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_9 Page No. 218"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AV=100000.00\n",
      "Ri= 10000.00  ohm\n",
      "Ro= 10.00  ohm\n",
      "Rs= 1.00e+07  ohm\n",
      "RL= 1000.00  ohm\n",
      "B=(Rs-Ri)/(AV*Ri)= 0.01\n",
      "AVf=AV/(1+B*AV)=100.00\n",
      "Rof=Ro/(1+B*AV) =0.01  ohm\n",
      "Rif=Ri/(1+B*AV) =1.00e+07  ohm\n",
      "Ap=(AVf**2)*(Rif/RL)=1.00e+08\n",
      "AP=10*log10(Ap)=80.00 dB\n"
     ]
    }
   ],
   "source": [
    "from math import log10\n",
    "from __future__ import division  \n",
    "AV=100000\n",
    "print \"AV=%0.2f\"%(AV) # Voltage gain \n",
    "Ri=10*10**(3)\n",
    "print \"Ri= %0.2f\"%(Ri),\" ohm\"  #Input resistance of OP-AMP\n",
    "Ro=10\n",
    "print \"Ro= %0.2f\"%(Ro),\" ohm\"  #Output resistance\n",
    "Rs=10*10**(6)\n",
    "print \"Rs= %0.2e\"%(Rs),\" ohm\"  #Source resistance\n",
    "RL=1*10**(3)\n",
    "print \"RL= %0.2f\"%(RL),\" ohm\"  #Load resistance\n",
    "B=(Rs-Ri)/(AV*Ri)\n",
    "print \"B=(Rs-Ri)/(AV*Ri)= %0.2f\"%(B) #Feedback factor\n",
    "AVf=AV/(1+B*AV)\n",
    "print \"AVf=AV/(1+B*AV)=%0.2f\"%(AVf) # Overall Voltage gain with feedback\n",
    "Rof=Ro/(1+B*AV)\n",
    "print \"Rof=Ro/(1+B*AV) =%0.2f\"%(Rof),\" ohm\"  #output resistance with feedback\n",
    "Rif=Ri*(1+B*AV)\n",
    "print \"Rif=Ri/(1+B*AV) =%0.2e\"%(Rif),\" ohm\"  #Input resistance with feedback\n",
    "Ap=(AVf**2)*(Rif/RL)\n",
    "print \"Ap=(AVf**2)*(Rif/RL)=%0.2e\"%(Ap) # Overall Power gain \n",
    "AP=10*log10(Ap)\n",
    "print \"AP=10*log10(Ap)=%0.2f\"%(AP),\"dB\" # Overall Power gain in dB "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example 7_10 Page No. 220"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "gm = 0.01  A/V\n",
      "Cgs= 5.00e-12  farad\n",
      "Cds= 1.00e-12  farad\n",
      "rd= 50000.00  ohm\n",
      "RG= 1.00e+07  ohm\n",
      "Rse= 1.00e+03  ohm\n",
      "L= 0.50  H\n",
      "C2= 5.00e-14  farad\n",
      "C1= 1.00e-12  farad\n",
      "part(i)\n",
      "CT= 0.00  farad\n",
      "part(ii)\n",
      "fo= sqrt(2)/(2*pi*sqrt(L*CT))=1.44e+06  Hz\n",
      "part(iii)\n",
      "fp= 1.03e+06  Hz\n",
      "fs= 1.01e+06  Hz\n",
      "Q=(sqrt(L/C2))/(Rse)= 3162.28\n",
      "part(iv)\n",
      "AB=gm*rd*(Cds/Cgs)= 100.00\n",
      "T_bias=RG*(Cgs+Cds)= 6.00e-05 s\n",
      "T_r =1/(2*pi*fo)= 1.10e-07 s\n",
      "for proper operation T_bias >> T_r\n"
     ]
    }
   ],
   "source": [
    "from math import sqrt,pi,log10\n",
    "from __future__ import division  \n",
    "gm=10*10**(-3)\n",
    "print \"gm = %0.2f\"%(gm),\" A/V\"#  transconductance \n",
    "Cgs=5*10**(-12)\n",
    "print \"Cgs= %0.2e\"%(Cgs),\" farad\"  # capacitance between gate-source\n",
    "Cds=1*10**(-12)\n",
    "print \"Cds= %0.2e\"%(Cds),\" farad\"  # capacitance between drain-source\n",
    "rd=50*10**(3)\n",
    "print \"rd= %0.2f\"%(rd),\" ohm\"  #Drain resistance\n",
    "RG=10*10**(6)\n",
    "print \"RG= %0.2e\"%(RG),\" ohm\"  #Gate resistance\n",
    "Rse=1*10**(3)\n",
    "print \"Rse= %0.2e\"%(Rse),\" ohm\"  #Gate resistance\n",
    "L=0.5\n",
    "print \"L= %0.2f\"%(L),\" H\"  #Inductance\n",
    "C2=0.05*10**(-12)\n",
    "print \"C2= %0.2e\"%(C2),\" farad\"  # Crystal parameter \n",
    "C1=1*10**(-12)\n",
    "print \"C1= %0.2e\"%(C1),\" farad\"  # Crystal parameter\n",
    "print \"part(i)\" \n",
    "x=C1+((Cds*Cgs)/(Cds+Cgs))\n",
    "CT=1/((1/C2)+(1/x))\n",
    "print \"CT= %0.2f\"%(CT),\" farad\"  # Equivalent series-resonating capacitance\n",
    "print \"part(ii)\" \n",
    "fo=sqrt(2)/(2*pi*sqrt(L*CT))\n",
    "print \"fo= sqrt(2)/(2*pi*sqrt(L*CT))=%0.2e\"%(fo),\" Hz\"# frequency of oscillations\n",
    "print \"part(iii)\"\n",
    "z=sqrt((L*C1*C2)/(C1+C2))\n",
    "fp=1/(2*pi*z)\n",
    "print \"fp= %0.2e\"%(fp),\" Hz\"# parallel-resonant frequency\n",
    "p=sqrt(L*C2)\n",
    "fs=1/(2*pi*p)\n",
    "print \"fs= %0.2e\"%(fs),\" Hz\"# series-resonant frequency\n",
    "Q=(sqrt(L/C2))/(Rse)\n",
    "print \"Q=(sqrt(L/C2))/(Rse)= %0.2f\"%(Q) #Quality factor\n",
    "print \"part(iv)\"\n",
    "AB=gm*rd*(Cds/Cgs)\n",
    "print \"AB=gm*rd*(Cds/Cgs)= %0.2f\"%(AB) #Loop gain\n",
    "T_bias=RG*(Cgs+Cds)\n",
    "print \"T_bias=RG*(Cgs+Cds)= %0.2e\"%(T_bias),\"s\"#Bias Time-Constant\n",
    "T_r = 1/(2*pi*fo)\n",
    "print \"T_r =1/(2*pi*fo)= %0.2e\"%(T_r),\"s\"#resonant Time-Constant for 'fo'\n",
    "print \"for proper operation T_bias >> T_r\"\n",
    "\n",
    "\n",
    "# in part (ii)... value calculated for series resonant frequecy 'fo' is wrong in textbook.\n",
    "# NOTE: in part(iii)... there is a misprint in the calculated value of Quality factor 'Q' in the textbook.\n",
    "#I have used T_r instead of 1/wo (given in the book)"
   ]
  }
 ],
 "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
}