# Chapter 2 : Spectral Analysis I Fourier Series¶

## Example 2.1 Page No : 31¶

In [1]:
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;

f = w/(2*math.pi);
print '(c)  The cyclic frequency is',f,'Hz'

T = 1/f;
print '(d)  The period is',T,'s'

(a)  The amplitude is idetified as 12.0 V
(c)  The cyclic frequency is 2000.0 Hz
(d)  The period is 0.0005 s


## Example 2.2 Page No : 32¶

In [3]:
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
print '(a)  The current is expressed as 5math.cos(50t + theta),where theta is',theta,'rad'

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'

(a)  The current is expressed as 5math.cos(50t + theta),where theta is -0.643501108793 rad
(b)  The current is expressed as 5math.sin(50t+phi), where phi is 0.0161843546921 rad or 0.927295218002 degrees


## Example 2.3 Page No : 37¶

In [4]:
# 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'

The lowest five frequencies are (in kH) 0 80.0 160.0 240.0 320.0 kHz


## Example 2.4 Page No : 40¶

In [11]:
%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');

(1500.0, 1000.0, 500.0, 0, '(a)  The frequencies in signal are')
(c)  The required bandwidth is 1500 Hz


## Example 2.5 Page No : 43¶

In [12]:
%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

(a)  The rms value of voltage is 8.91627725006
(b)  The average power dissipated in resistor is 15.9 W
(c)  The dc power is  5.0
The power in fundamental is 6.4
The second and third harmonics are 3.6 0.9

Out[12]:
<matplotlib.text.Text at 0x10f003250>

## Example 2.6 Page No : 48¶

In [13]:
# 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');

The fundmental frequency is 250.0
The five lowest frequencies are  250.0 750.0 1250.0 1750.0 2250.0
(b)  The rolloff rate is -6dB/octave


## Example 2.7 Page No : 51¶

In [15]:
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);

The fundamental frequency is 5.0
The magnitude of fundamental , third and fifth harmonics are  25.4647908947 8.48826363157 5.09295817894 respectively Frequency  Amplitude   Power
[[5.0, 25.464790894703256, 6.4845557531096185], [15.0, 8.48826363156775, 0.7205061947899574], [25.0, 5.092958178940651, 0.2593822301243847]]


## Example 2.8 Page No : 52¶

In [16]:
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

Total power is 8.0 W
Power of fundamental , third and fifth harmonics is 7.46444417802
The percent of power is  93.3055522253


## Example 2.9 Page No : 54¶

In [17]:
%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)')

Out[17]:
<matplotlib.text.Text at 0x10f030290>