Chapter 3 : Spectral Analysis II Fourier Transform and Pulse Spectra

Example 3.1 Page No : 75

In [2]:
%matplotlib inline
from numpy import zeros,concatenate,array,arange,ones
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot
import math 

A = 1.    #arbitrary value provided
T = 10.    #T represents tau (arbitrary value provided)
#plot for non periodic pulse
t = arange(-2*T,2*T+0.001,.001)
vt = concatenate((zeros(15001), ones(9999), zeros(15002)))
subplot(211)
plot(t,vt) #,[2],rect = [-2*T,0,2*T,A+1])
suptitle('(a) Non periodic pulse')
xlabel('t')
ylabel('v(t)')

#plot for amplitude spectum
f = arange(-4/T,4/T,0.001);
Vf = []
for i in range(len(f)):
    if f[i] == 0:
        Vf.append(A*T);    #according to L'Hopitals rule math.sin(x)/x = 1 at lim x->0
    else:
        Vf.append(A*T*math.sin(math.pi*f[i]*T)/(math.pi*f[i]*T))


subplot(212)
plot(f,Vf)
suptitle('(b) Amplitude spectrum')
xlabel('f')
ylabel('V(f)')
Out[2]:
<matplotlib.text.Text at 0x10649a590>

Example 3.2 Page No : 76

In [3]:
%matplotlib inline
from numpy import zeros,concatenate,array,arange,ones
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot
import math 

#plot for impulse function
t = arange(-2,2.001,.001)
vt = concatenate((zeros(len(arange(-2,0,.001))), [1], zeros(len(arange(0+.001,2.001,.001)))))     #impulse function matrix

subplot(211)
plot(t,vt)#|,[2],rect = [-2,0,2,2])
suptitle('(a) Unit Impulse function')
xlabel('t')
ylabel('v(t)')


#plot for amplitude spectum
f = arange(-2,2.001,0.001)
Vf = ones(len(f))
subplot(212)
plot(f,Vf)#,[5])
suptitle('(b) Amplitude spectrum')
xlabel('f')
ylabel('V(f)')
Out[3]:
<matplotlib.text.Text at 0x106665310>

Example 3.3 Page No : 82

In [5]:
%matplotlib inline
import math 
from numpy import array,log10

A = 20.;    #Volts
T = 1.*10**-3;    #second
def Fourier_transform(f,T,A):
    if f == 0 :
        return A*T;
    else:
        return A*T*math.sin((math.pi*f*T))/(math.pi*f*T);
        
print 'a)Equation for fourier transform is  Vf) = %.2f * math.sin %.3f*pi*f)/%.3f*pi*f)'%(A*T,T,T);
#Part b Calculation
f = [0., 500., 1000, 1500];
Vf = []
for i in range(4):
    Vf.append(Fourier_transform(f[i],T,A))

#Part c calculation
RdB = 20*log10(array(Vf)/.02)
#Result Table
print 'fHz     Vfin V     RdB'
for i in range(4):
    print '%5i   %f    %f '%(f[i],Vf[i],RdB[i])

#All values are rounding off error
a)Equation for fourier transform is  Vf) = 0.02 * math.sin 0.001*pi*f)/0.001*pi*f)
fHz     Vfin V     RdB
    0   0.020000    0.000000 
  500   0.012732    -3.922398 
 1000   0.000000    -328.182780 
 1500   -0.004244    nan 

Example 3.4 Page No : 85

In [6]:
%matplotlib inline
import math 
from numpy import zeros,concatenate,array,arange,ones
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot

#chapter 3
#page no 85
#example 3.4
A = 20.;    #Volts
T = 1.*10**-3;    #seconds
f = arange(-3/T,3/T+1,1);    #in kHz
Vf = []
for i in range(len(f)):
    if f[i] == 0:
        Vf.append(A*T);
    else:
        Vf.append(A*T*math.sin(math.pi*f[i]*T)/(math.pi*f[i]*T));
    
plot(f,Vf)#,[5])
suptitle('Amplitude Spectrum')
xlabel('f,Hz')
ylabel('V(f)');

Example 3.5 Page No : 86

In [7]:
%matplotlib inline
from numpy import zeros,concatenate,array,arange,ones
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot
import math 

A = 20.;    #Volts
T = 5.*10**-3;    #period in seconds
tau = 1.*10**-3;   #pulse width in second
d = tau/T;        #duty cycle
f1 = 1/T;        #Fundamental frequency in Hz

#for plot
n = arange(-14,15+1,1);    #in Hz
Vf = zeros(len(n)*200)
for i in range(len(n)):
    if n[i] == 0:
        Vf[i*200] = A*d;
    else:
       Vf[i*200] = A*d*math.sin(math.pi*d*n[i])/(math.pi*d*n[i]) 

    #to get the magnitudes of components
    if Vf[i*200] < 0:
        Vf[i*200] = -Vf[i*200]

f = arange(-3000,3000,1)
plot(f,Vf)#,[5],rect = [-3000,0,3000,5])
suptitle('Amplitude Spectrum')
xlabel('f,Hz')
ylabel('Vn');

Example 3.6 Page No : 89

In [8]:
%matplotlib inline
from numpy import zeros,concatenate,array,arange,ones
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot
import math 

A = 1.    #arbitrary value provided
Tau = 10.**-3    #in seconds
fc = 30.*10**6;  #centre frequency in Hz
#plot for amplitude spectum
f = arange(-3/Tau,3/Tau+1);
Vf = []
for i in range(len(f)):
    if f[i] == 0:
        Vf.append(A*Tau);    #according to L'Hopitals rule math.sin(x)/x = 1 at lim x->0
    else:
        Vf.append(A*Tau*math.sin(math.pi*f[i]*Tau)/(math.pi*f[i]*Tau))
        
f = f+fc   #shifting
f = f*10**-6   #MHz

plot(f,Vf)#,[5])
suptitle('Amplitude spectrum')
xlabel('f,MHz')
ylabel('Vrf(f)')
Out[8]:
<matplotlib.text.Text at 0x106806510>

Example 3.7 Page No : 89

In [9]:
%matplotlib inline
from numpy import zeros,concatenate,array,arange,ones
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot
import math 

A = 1.;    #arbitrary vaule
T = (1.+4)*10**-3;    #period in seconds
tau = 1.*10**-3;   #pulse width in second
fc = 30.*10**6;    #centre frequency in Hz
d = tau/T;        #duty cycle
f1 = 1/T;        #Fundamental frequency in Hz

#for plot
n = arange(-14,15+1);    #in Hz
Vf = zeros(len(n)*200)
for i in range(len(n)):
    if n[i] == 0:
        Vf[i*200] = A*d;
    else:
       Vf[i*200] = A*d*math.sin(math.pi*d*n[i])/(math.pi*d*n[i]) 

f = arange(-3000,3000)
f = f+fc;    #Shifting by fc
f = f*10**-6;   #in MHz

plot(f,Vf)#,[5])
suptitle('Amplitude Spectrum')
xlabel('f,MHz')
ylabel('Vn');

Example 3.8 Page No : 90

In [10]:
# Calculations
print 'a The RF burst frequency is 500 MHz';
print ' b The pulse repetition rate is 1 MHz';
f0 = 10.*10**6;    #Zero crosmath.sing frequency in Hz
tau = 1./f0;     #in second

# Results
print ' c) The pulse width is %.1f micro second'%(tau*10**6);
a The RF burst frequency is 500 MHz
 b The pulse repetition rate is 1 MHz
 c) The pulse width is 0.1 micro second