## Example 1 - pg 150¶

In :
#calculate the image frequency and rejection ratio in both cases
import math
from math import sqrt
#given data
Q = 100.#quality factor
f_i = 455.*10**3#intermediate frequency

#calculations
#first case
f_s = 1000.*10**3#incoming frequecy of first case
f_si = f_s + 2*f_i#image frequency of first case
p = (f_si/f_s) - (f_s/f_si);
alpha = sqrt(1+(Q**2*p**2))#rejection ratio of first case
#second case
f_s1 = 25.*10**6#incoming frequecy of second case
f_si1 = f_s1+ 2*f_i#image frequency of second case
p1 = ((f_si1/f_s1) - (f_s1/f_si1));
alpha1 = sqrt(1+(Q**2*p1**2))#rejection ratio of second  case

#results
print "(i)a.Image frequency of first case (kHz)",f_si/1000.
print "   b.Rejection ratio of first case = ",round(alpha,1)
print " (ii)a.Image frequency of second case (MHz) = ",round(f_si1/10**6,2)
print "     b.Rejection ratio of second case = ",round(alpha1,2)
print "Note: Their is mistake in textbook  in the calculation of rejection ratio"

(i)a.Image frequency of first case (kHz) 1910.0
b.Rejection ratio of first case =  138.6
(ii)a.Image frequency of second case (MHz) =  25.91
b.Rejection ratio of second case =  7.22
Note: Their is mistake in textbook  in the calculation of rejection ratio


## Example 2 - pg 150¶

In :
#calculate the image frequency and rejection ratio in both cases
import math
from math import sqrt
#given data
Q = 90.
f_i = 455.*10**3#intermediate frequency

#calculations
#first case
f_s = 950.*10**3#incoming frequency of first case
f_si = f_s + 2*f_i#image frequency of first case
p = (f_si/f_s) - (f_s/f_si);
alpha = sqrt(1+(Q**2*p**2))#rejection ratio of first case
#second case
f_s1 = 10.*10**6#incoming frequecy of second case
f_si1 = f_s1+ 2*f_i#image frequency of second case
p1 = ((f_si1/f_s1) - (f_s1/f_si1));
alpha1 = sqrt(1+(Q**2*p1**2))#rejection ratio of second  case

#results
print "(i)a.Image frequency of first case (kHz)",f_si/1000.
print "   b.Rejection ratio of first case = ",round(alpha,1)
print " (ii)a.Image frequency of second case (MHz) = ",round(f_si1/10**6,2)
print "     b.Rejection ratio of second case = ",round(alpha1,2)

(i)a.Image frequency of first case (kHz) 1860.0
b.Rejection ratio of first case =  130.2
(ii)a.Image frequency of second case (MHz) =  10.91
b.Rejection ratio of second case =  15.73


## Example 3 - pg 151¶

In :
#calculate the quality factor and new intermediate frequency
#given
import math
from math import sqrt
a1 = 130.5#rejection ratio
f_s = 10.*10**3#incoming frequency
print ("from fig 4.8 from t/b we can write that")

#calculations
#first case
alpha = 130.5#from problem 4.2 of first case
alpha2 = 15.72#from problem 4.2 of second case
alpha1 = alpha/alpha2#rejection ratio ofgiven RF amplifer
p1 =.174#from problem 4.2 of second case
Q = (sqrt(alpha1**2 - 1)/p1)#quality factor
#second case
p2 = 1.45#from problem 4.2 of second case
f_si =1860.*10**3#from problem 4.2 of second case
f_i = 950.*10**3#incoming frequency
f_i1 = 10.*10**6#good image frequency
f_si1 = (f_si*f_i1)/f_i; #image frequency
f_i2 = (f_si1 - f_i1)/2#new intermediate frequency

#results
print "(i)Quality factor =  ",round(Q,2)
print "(ii)New intermediate frequency (MHz) = ",round(f_i2/10**6,3)

from fig 4.8 from t/b we can write that
(i)Quality factor =   47.36
(ii)New intermediate frequency (MHz) =  4.789


## Example 5 - pg 152¶

In :
#calculate the local oscillator frequency and image frequency rejection ratio
import math
from math import sqrt
#given
IF = 455.*10**3#intermediate frequency in hertz
f_s = 900.*10**3#signal frequency in hertz
Q = 80.#quality factor

#calculations
f_0 = f_s + IF#local oscillator frequency
f_si = f_s + 2* IF#image frequency
p = (f_si/f_s)-(f_s/f_si)
a = sqrt(1+(Q*p)**2)#image frequency rejection ratio

#results
print "(i)Local oscillator frequency (kHz) = ",f_0/1000.
print "(ii)Image frequency (kHz) = ",f_si/1000.
print "(iii)Image frequency rejection ratio = ",a
print "Note:Their is mistake in textbook in the calculation of image frequency"

(i)Local oscillator frequency (kHz) =  1355.0
(ii)Image frequency (kHz) =  1810.0
(iii)Image frequency rejection ratio =  121.114011776
Note:Their is mistake in textbook in the calculation of image frequency


## Example 6 - pg 153¶

In :
#calculate the image frequency, rejection ratio
import math
from math import sqrt
#given
Q = 125. #quality factor

#calculations
#first case
IF1 = 465.*10**3#intermediate frequency
f_s1 = 1.*10**6#incoming frequency for first case in hertz
f_s2 = 30.*10**6#second incoming frequency for first case in hertz
f_si1 = f_s1 + 2*IF1#image frequency for incoming frequency 1MHz for first case
f_si2 = f_s2 + 2*IF1#image frequency for incoming frequency 30MHz for first case
p1 = (f_si1/f_s1)-(f_s1/f_si1);
p2 = (f_si2/f_s2)-(f_s2/f_si2);
alpha1 = sqrt(1+(Q*p1)**2);#rejection ratio at 1MHz incoming frequency
alpha2 = sqrt(1+(Q*p2)**2);#rejection ratio at 30MHz incoming frequency
#second case
f_s3 = 1.*10**6#incoming frequency for second case in hertz
f_si3 = (f_si1*f_s2)/f_s3#image  frequency
IF2 =  (f_si3-f_s2)/2.#intermediate frequency

#results
print "(i)a.Image frequency for 1MHz incoming frequency (kHz) = ",f_si1/1000.
print "   b.Rejection ratio for 1MHz incoming frequency = ",round(alpha1,2)
print "   c.Image frequency for 30MHz incoming frequency (MHz) = ",f_si2/10**6
print "   d.Rejection ratio for 30MHz incoming frequency =",round(alpha2,2)
print "(ii)intermediate frequency for second case (Hz) = ",round(IF2/10**6,1)
print 'The answers are a bit different from textbook due to rounding off error'

(i)a.Image frequency for 1MHz incoming frequency (kHz) =  1930.0
b.Rejection ratio for 1MHz incoming frequency =  176.49
c.Image frequency for 30MHz incoming frequency (MHz) =  30.93
d.Rejection ratio for 30MHz incoming frequency = 7.7
(ii)intermediate frequency for second case (Hz) =  13.9
The answers are a bit different from textbook due to rounding off error


## Example 7 - pg 173¶

In :
#calculate the range of local oscillator frequency and image frequency
#given
fs1=3 #MHz
fs2=30 #MHz
IF=40.525 #MHZ
#calculations
f01=fs1+IF
f02=fs2+IF
fsi1=fs1+2*IF
fsi2=fs2+2*IF
#results
print 'The range of local oscillator frequency is ',f01,'MHz to',f02,'MHz'
print 'The range of image frequency is ',fsi1,'MHz to',fsi2,'MHz'

The range of local oscillator frequency is  43.525 MHz to 70.525 MHz
The range of image frequency is  84.05 MHz to 111.05 MHz


## Example 8 - pg 174¶

In :
#calculate the Q factor of RF amplifier
#given
fr=1*10**6 #Hz
BW=10.*10**3 #Hz
#calculations
Q=fr/BW
#results
print 'Q factor = ',Q

Q factor =  100.0