Chapter 7 - Sampling Theory and Pulse modulation

Example 1 - pg 324

In [2]:
#calculate the nyquist rate

import math
#given
#analog signal x(t) = 3*cos(50*math.pi*t) + 10*sin(300*math.pi*t) - cos(100*math.pi*t)
#comparing signal with x(t) = 3*cos(w_1*t) + 10*sin(w_2*t) - cos(w_3*t)
#therefore
w_1 = 50*math.pi;#first frequency in rad/sec
w_2 = 300*math.pi;#second frequency in rad/sec
w_3 = 100*math.pi;#third frequency in rad/sec

#calculations
f_1 = w_1/(2*math.pi);#first frequency in Hz
f_2 = w_2/(2*math.pi);#second frequency in Hz
f_3 = w_3/(2*math.pi);#third frequency in Hz
f_m = f_2#maximum frequency 
f_s = 2*f_m#nyquist rate for a signal

#results
print "Nyquist rate (Hz) = ",f_s
Nyquist rate (Hz) =  300.0

Example 2 - pg 325

In [9]:
#calculate the Nyquist rate and interval
import math
#given
#x(t) = (1/()2*math.pi))*cos(4000*math.pi*t)*cos(1000*math.pi*t)
#expanding
print("x(t) = (1/(2*math.pi)*cos(4000*math.pi*t)*cos(1000*math.pi*t)");
print("x(t) = (1/(4*math.pi)*2*cos(4000*math.pi*t)*cos(1000*math.pi*t)");
print("x(t) = (1/(4*math.pi))*[cos(4000*math.pi*t + 1000*pi*t)*cos(4000*math.pi*t - 1000*math.pi*t)]")
print("x(t) = (1/(4*math.pi))*[cos(5000*math.pi*t + cos(3000*math.pi*t))]")
#by comparing above equation with x(t) = (1/(4*math.pi))*[cos(w_1*t) + cos(w_2*t)] 
w_1 = 5000.*math.pi
w_2 = 3000.*math.pi

#calculations
f_1 = w_1/(2*math.pi);
f_2 = w_2 /(2*math.pi);
f_m = f_1
f_s = 2*f_m#Nyquist rate
T_s = 1/f_s#Nyquist interval

#results
print "Nyquist rate (Hz) = ",f_s
print "Nyquist interval  (msec) = ",T_s*1000
x(t) = (1/(2*math.pi)*cos(4000*math.pi*t)*cos(1000*math.pi*t)
x(t) = (1/(4*math.pi)*2*cos(4000*math.pi*t)*cos(1000*math.pi*t)
x(t) = (1/(4*math.pi))*[cos(4000*math.pi*t + 1000*pi*t)*cos(4000*math.pi*t - 1000*math.pi*t)]
x(t) = (1/(4*math.pi))*[cos(5000*math.pi*t + cos(3000*math.pi*t))]
Nyquist rate (Hz) =  5000.0
Nyquist interval  (msec) =  0.2

Example 3 - pg 326

In [6]:
#calculate the discrete time signal for all conditions

#given
#x(t) = 8*cos(200*%pi*t)
f= 100.#highest frequency component of continuous time signal in hertz
f_s2 = 400.#sampling frequency in hertz for second condition
f_s3 = 400.#sampling frequency in hertz for third condition
f_s4 = 150.#sampling frequency in hertz for fourth condition since 0 < f_s4 < f_s2/2 

#calcultions
NR = 2*f#Nyquist rate
F_1 = f/NR;
F_2 = f/f_s2;
F_3 = f/f_s3;
F_4 = f/f_s4;
f_4 = f_s4*F_4;

#results
print "The discrete time signal x(n) for the first condition is x(n) = 8*cos(2*pi*",F_1,"*n)"
print "the discrete time signal x(n) for the second condition is x(n) = 8*cos(2*pi*",F_2,"*n)"
print "the discrete time signal x(n) for the third condition is x(n) = 8*cos(2*pi*",F_3,"*n)"
print "The discrete time signal x(n) for the fourth condition is x(n) = 8*cos(2*pi*",f_4,"*t)"
The discrete time signal x(n) for the first condition is x(n) = 8*cos(2*pi* 0.5 *n)
the discrete time signal x(n) for the second condition is x(n) = 8*cos(2*pi* 0.25 *n)
the discrete time signal x(n) for the third condition is x(n) = 8*cos(2*pi* 0.25 *n)
The discrete time signal x(n) for the fourth condition is x(n) = 8*cos(2*pi* 100.0 *t)

Example 4 - pg 327

In [5]:
#calculate the nyquist rate
import math
#given
#x(t) = 6*cos(50*math.pi*t)  + 20*sin(300*math.pi*t) - 10*cos(100*math.pi*t)
#by comparing with standard eqn x(t) = A_1*cos(w_1*t)  + A_2*sin(w_2*t) + A_3*cos(w_3*t) we get 
w_1 = 50*math.pi#frequency in rad/sec
w_2 =300*math.pi#frequency in rad/sec
w_3 = 100*math.pi#frequency in rad/sec

#calculations
f_1 = w_1/(2*math.pi)#frequency in hertz
f_2 = w_2/(2*math.pi)#frequency in hertz
f_3 = w_3/(2*math.pi)#frequency in hertz
if f_1 > f_2  and f_1> f_3:
     f_max = f_1
elif f_2 > f_1 and f_2> f_3:
    f_max = f_2
elif f_3 > f_1 and f_3> f_2:
    f_max = f_3

f_s = 2*f_max;#nyquist rate

#results
print "Nyquist rate for a continuous signal (Hz) = ",f_s
Nyquist rate for a continuous signal (Hz) =  300.0