Analytical Impedance Match with Python

I created a quick Python function to calculate the component values for an impedance match between two real (resistive) terminations using the technique taught in the Introduction to Impedance Matching course. Here is what the code ends up looking like, and it shows how useful Python can be for working as a "quick programmable calculator." In the old days, I might have been tempted to program my old HP48 calculator to crank out the same values. It only took a few minutes to put the code together, which is the beauty of working with Python.

def getMatch(source,load,freq):
        R1 = source
        R2 = load
	if R2 > R1:
		Q = R2/R1
	else:
		Q = R1/R2
        Q = Q - 1
        Q = math.sqrt(Q)
        
        XP = R1/Q
        LP = XP/(6.28*freq)
        CP = 159/(freq * XP)
        
        XS = R2*Q
        CS = 159/(freq*XS)
        LS = XS/(6.28 *freq)
        
        print "Q = %f" % Q
        print "XP = %f Ohms" % XP
        print "XS = %f Ohms" % XS 
        
        print "Highpass: "
        print "LP = %f nH" % LP
        print "CS = %f pF" % CS   
        
        print "Lowpass: "
        print "CP = %f pF" % CP
        print "LS = %f nH" % LS  

I'm planning on making this calculation available in the online course workbook using an integration of "Skulpt," which is a JavaScript based Python interpreter.

Category: 

Tags: