import math
# Calculations and Results
#v(t) = 12coos(2pi*2000t)
A = 12.; #in volts
print '(a) The amplitude is idetified as',A,'V'
w = 2*math.pi*2000;
print '(b) The radian frequincy is',w,'rad/s'
f = w/(2*math.pi);
print '(c) The cyclic frequency is',f,'Hz'
T = 1/f;
print '(d) The period is',T,'s'
import math
from sympy import acot
# Variables
#i(t) = 4math.cos50t + 3math.sin50t
A = 4.;
B = 3.;
# Calculations and Results
C = math.sqrt(A**2+B**2); #right triangle
theta = -1*math.atan(3./4); #in rad
print '(a) The current is expressed as 5math.cos(50t + theta),where theta is',theta,'rad'
phi = math.radians(acot(3./4)); #from figure 2.5 in radian
print '(b) The current is expressed as 5math.sin(50t+phi), where phi is',phi,'rad',
phi = phi*180/math.pi;
print 'or',phi,'degrees'
# Variables
T = 12.5*10**-6; #in sec
f0 = 0; #dc
# Calculations
f1 = 1./T*10**-3; #in kHz
f2 = f0+2*f1;
f3 = f0+3*f1;
f4 = f0+4*f1;
# Results
print 'The lowest five frequencies are (in kH)',f0,f1,f2,f3,f4,'kHz'
%matplotlib inline
import math
from numpy import zeros,arange,concatenate
from matplotlib.pylab import plot,suptitle,xlabel,ylabel
# Variables
#all frequencies are in Hz
f = 0;
f1 = 500.; #fundamental freq.
f2 = 1000.;
f3 = 1500.; #harmonics
print (f3,f2,f1,f,'(a) The frequencies in signal are');
#for plot
fHz = arange(0,1600);
Cn = concatenate(([5],zeros(499),[8],zeros(499),[6],zeros(499), [3], zeros(99)))
plot(fHz,Cn)#,[3],rect = [-0.5,0,1550,10])
suptitle('Linear amplitude spectrum')
xlabel('f,Hz')
ylabel('Cn(V)')
#xgrid
print ('(c) The required bandwidth is 1500 Hz');
%matplotlib inline
import math
from numpy import zeros,concatenate
from matplotlib.pylab import plot,suptitle,xlabel,ylabel,title
#page no 43
#problem 2.5
# Variables
#All voltages are in V
#All power in watts
R = 5.; #ohm
C0 = 5.; #dc value
C1 = 8.;
C2 = 6.;
C3 = 3.; #volts
# Calculations and Results
Vrms = math.sqrt(C0**2+0.5*(C1**2+C2**2+C3**2)); #rms voltage
print '(a) The rms value of voltage is',Vrms
P = Vrms**2/R; #watts
print '(b) The average power dissipated in resistor is',P,'W'
P0 = C0**2/R;
print '(c) The dc power is ',P0
P1 = C1**2/(2*R);
print 'The power in fundamental is',P1
P2 = C2**2/(2*R);
P3 = C3**2/(2*R);
print 'The second and third harmonics are',P2,P3
#for plot
fHz = range(1600);
f1 = 500; #fundamental freq.
f2 = 1000; f3 = 1500;
Pn = concatenate(([P0],zeros(499), [P1], zeros(499), [P2], zeros(499), [P3], zeros(99)))
plot(fHz,Pn,color="red")#,rect = [0,0,1600,8])
suptitle('Power spectrum')
xlabel('f,Hz')
ylabel('Pn(W)')
#xgrid
# Variables
#All frequencies in Hz
#There is no dc component
T = 4.*10**-3;
# Calculations and Results
f1 = 1/T;
print 'The fundmental frequency is',f1
#The function have only odd numbered components
print 'The five lowest frequencies are ',f1,f1*3,f1*5,f1*7,f1*9
print ('(b) The rolloff rate is -6dB/octave');
import math
# Variables
#All frequencies in kHz
#The time is in ms
#Power in WATTS
#All voltage in volts
T = 0.2; #ms
# Calculations and Results
f1 = 1/T;
print 'The fundamental frequency is',f1
#There are only odd numbered harmonics
Ap2p = 40.; # peak to peak
R = 50.; #ohm
A = Ap2p/2;
C1 = 4*A/math.pi;
C3 = 4*A/(3*math.pi);
C5 = 4*A/(5*math.pi);
print 'The magnitude of fundamental , third and fifth harmonics are ',C1,C3,C5,'respectively',
def Power(Cn,R):
return Cn**2/(2*R);
P1 = Power(C1,R);
P3 = Power(C3,R);
P5 = Power(C5,R);
#power is calculated umath.sing the function Power defined above
print ('Frequency Amplitude Power')
table = [[f1,C1,P1],[3*f1,C3,P3],[5*f1,C5,P5]];
print (table);
import math
# Variables
#All frequencies in kHz
#The time is in ms
#Power in WATTS
#All voltage in volts
#following values are copied from Ex2-7
T = 0.2; #ms
f1 = 1/T;
#There are only odd numbered harmonics
Ap2p = 40.; # peak to peak
R = 50.; #ohm
# Calculations
A = Ap2p/2;
C1 = 4*A/math.pi;
C3 = 4*A/(3*math.pi);
C5 = 4*A/(5*math.pi);
def Power(Cn,R):
return Cn**2/(2*R);
P1 = Power(C1,R);
P3 = Power(C3,R);
P5 = Power(C5,R);
# Results
Vrms = A;
P = Vrms**2/R;
print 'Total power is',P,"W"
P135 = P1+P3+P5
print 'Power of fundamental , third and fifth harmonics is',P135
prcnt = P135/P*100;
print 'The percent of power is ',prcnt
%matplotlib inline
import math
from numpy import zeros,concatenate,array,arange
from matplotlib.pyplot import plot,suptitle,xlabel,ylabel,subplot
# Variables
f0 = 0;
f1 = 500.; #fundamental freq.
f2 = 1000.;
f3 = 1500.; #harmonics
# Calculations and Results
#Values from ex 2.4
C = [5, 8, 6, 3]# Values in Volts
#Values from ex 2.5
P = [5, 6.4, 3.6, .9]; #poweer in watts
# plot two sided linear amplitude spectrum
#fHz = -1510:10**-2:1510; #x-axis matrix
fHz = arange(-1510,1510.01,10**-2)
#Y-axis matrix
Cn = [C[0]]
for i in range(1,4):
Cn = concatenate(([zeros(49999), Cn, zeros(49999)]))
Cn = concatenate(([C[i]/2], Cn, [C[i]/2]));
Cn = concatenate((zeros(1000), Cn, zeros(1000)))
subplot(211)
plot(fHz,Cn)#,[2],rect = [-2000,0,2000,6])
suptitle('Two-sided Linear amplitude spectrum')
xlabel('f,Hz')
ylabel('Vn(V)')
# plot two power spectrum
fHz = arange(-1510,1510.01,10**-2); #x-axis matrix
#Y-axis matrix
Pn = [P[0]]
for i in range(1,4):
Pn = concatenate((zeros(49999), Pn, zeros(49999)))
Pn = concatenate(([P[i]/2], Pn ,[P[i]/2]));
Pn = concatenate((zeros(1000), Pn ,zeros(1000)))
subplot(212)
plot(fHz,Pn)#,[6],rect = [-2000,0,2000,6])
suptitle('Two-sided power spectrum')
xlabel('f,Hz')
ylabel('Pn(W)')