%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)')
%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)')
%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
%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)');
%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');
%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)')
%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');
# 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);