steve_bank
Diabetic retinopathy and poor eyesight. Typos ...
I bet you are wondering what complex numbers are used for. A simple example with a series resistor capacitor low pass filter. Search on RC low pass fiiter for more information,
A little bit of applied math and Python coding.
A pure capacitance has a phase of -90 degrees or -j, and inductance +90 degrees or +j where j is the imaginary number sqrt(-1)
Impedance Z = real resistance +- imaginary reactance, a complex number/
Capacative reactance = 1/(2pi*f*c) = Xc
Capacative impedance Zc = rc - jXc where rc is the internal resistance of a capacitor.
The magnitude of the impedance Zc = sqrt(rc^2 +Xc^2)
The phase = imaginary/real
In an audio amplifier complex phase represents the shift in time of a sine wave as frequency increases.
For 2 series resistors across a battery the voltage out is vin*r2/(r1+r2). Resistors are considered complex with a zero imaginary part.
The output of two series resistors across a battery is vout = vbattery*r2/(r1 + r2). As resistors are real simple arithmetic works.
For an RC circuit vout = vin*Zc/(r + Zc) which involves complex numbers.
Python does complex math. At the end you only need to find the magnitude ad phase for display. purposes.
It is common to express the gain of a circuit in decibels. As a logarithmic transformation chains of gains can be added instead of multiplying in your head.
When plotting gain and phase it is common to plot log-normal if you run the code.
In the file the frequency associated with the -3db magnitude point is called the pole or break frequency.
A little bit of applied math and Python coding.
A pure capacitance has a phase of -90 degrees or -j, and inductance +90 degrees or +j where j is the imaginary number sqrt(-1)
Impedance Z = real resistance +- imaginary reactance, a complex number/
Capacative reactance = 1/(2pi*f*c) = Xc
Capacative impedance Zc = rc - jXc where rc is the internal resistance of a capacitor.
The magnitude of the impedance Zc = sqrt(rc^2 +Xc^2)
The phase = imaginary/real
In an audio amplifier complex phase represents the shift in time of a sine wave as frequency increases.
For 2 series resistors across a battery the voltage out is vin*r2/(r1+r2). Resistors are considered complex with a zero imaginary part.
The output of two series resistors across a battery is vout = vbattery*r2/(r1 + r2). As resistors are real simple arithmetic works.
For an RC circuit vout = vin*Zc/(r + Zc) which involves complex numbers.
Python does complex math. At the end you only need to find the magnitude ad phase for display. purposes.
It is common to express the gain of a circuit in decibels. As a logarithmic transformation chains of gains can be added instead of multiplying in your head.
When plotting gain and phase it is common to plot log-normal if you run the code.
In the file the frequency associated with the -3db magnitude point is called the pole or break frequency.
Code:
#Python
#rc low pass
import os
import math
import cmath
os.chdir('c:\\python')
def save_nums(fname,delim,*args):
nrows = len(args[0])
# check number of rows the same
for i in range(len(args)):
if len(args[i]) != nrows : return 1
f = open(fname,'w')
for i in range(nrows):
s = ' ' # row string
j = 0
for x in args:
s += repr(x[i])
if j < len(args)-1:s += delim
j += 1
s += '\n'
f.write(s)
f.close()
return 0
def rc_lopass(n,r,rc,f,m,p,vin):
#simulated frequency sweep of an RC low pass filter
for i in range(n):
Xc = 1./(2.*math.pi*f[i]*c) # reacrance
Zc = rc - 1j*Xc # complex capcitive impedance
vout = vin*Zc/(r + Zc) # complex result
m[i] = 20*math.log10(abs(vout)/vin) # gain ratio of output to input in decibels
p[i] = cmath.phase(vout)*360./(2.*math.pi) # phase shift in degrees
def make_freqs(n,fstart,df,freqs):
# linear array of frequencies in Hertz
f = fstart
for i in range(n):
freqs[i] = f
f += df
fn = 'c:\\python\\lopass.txt'
n = 1000
r = 1000. # series resitor real
rc = 10. # capacitor internal resystance
c = 1.e-6 # capctnce
fpole = 1./(2*math.pi*r*c) # -3db frequncy
print(fpole)
vin = 10.
f = n*[0] # frequency sweep
m = n*[0] # magnitude frequncy response
p = n*[0] # phase response
make_freqs(n,1,1,f)
rc_lopass(n,r,rc,f,m,p,vin)
s = save_nums(fn,' \t',f,m,p)
print(s)