<commit_before>'''
#       transmissionLine.py
#       
#       Copyright 2010 <NAME> <<EMAIL>>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later versionpy.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
'''
try:
	from scipy.constants import  epsilon_0, mu_0, c,pi, mil
	#from scipy import signal
	
except:
	raise ImportError ('Depedent Packages not found. Please install: scipy')
try:
	import numpy as npy
	from numpy import sqrt, exp, array,tan,sin,cos,inf, log, real,imag,\
	 interp, linspace, shape,zeros, reshape
except:
	raise ImportError ('Depedent Packages not found. Please install: numpy')	

import mwavepy as mv
	

# TEM transmission lines
class transmissionLine(object):
	'''
	This is a general super-class for TEM transmission lines. The 
	structure behind the methods dependencies is a results of the 
	physics. a brief summary is given below. 
	
	
	
	a TEM transmission line is defined by its:
	
		distributed Capacitance, C'
		distributed Inductance, I'
		distributed Resistance, R'
		distributed Conductance, G'
		
	from these the following quantities may be calculated, which
	are functions of angular frequency (w):
	
		distributed Impedance,  Z'(w) = R' + jwI'
		distributed Admittance, Y'(w) = G' + jwC'
	
	from these we can get to properties which define their wave behavoir
		
		characteristic Impedance, Z0(w) = sqrt(Z'(w)/Y'(w))		[ohms]
		propagation Constant,	gamma(w) = sqrt(Z'(w)*Y'(w))	
		
	
	and then finnally produce methods which we use 
		
		electrical Length
		input Impedance
		relfection Coefficient
		
	
	'''
	fBand = None
	def __init__(self, \
		distributedCapacitance,	distributedInductance,\
		distributedResistance, distributedConductance, fBand=None ):
		
		self.distributedCapacitance = distributedCapacitance
		self.distributedInductance = distributedInductance
		self.distributedResistance = distributedResistance
		self.distributedConductance = distributedConductance

		self.fBand = fBand
		
	def distributedImpedance(self,omega=None):
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return self.distributedResistance+1j*omega*self.distributedInductance
	
	def distributedAdmittance(self,omega=None):
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return self.distributedConductance+1j*omega*self.distributedCapacitance
	# could put a test for losslessness here and choose whether to make this
	# a funtion of omega or not.
	def characteristicImpedance(self,omega=None):
		'''
		returns the characteristic impedance at a given angular frequency
		
		takes:
			omega: radian angular frequency
		returns:
			Z0: characteristic impedance  ohms
		
		'''
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return sqrt(self.distributedImpedance(omega)/self.distributedAdmittance(omega))
	
	def propagationConstant(self,omega=None):
		'''
		the propagation constant, (usually represented by gamma)
		
		takes: 
			omega
			
		returns:
			gamma: possibly complex propagation constant, [jrad/m+]
		'''
		
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return 1j*sqrt(self.distributedImpedance(omega)*self.distributedAdmittance(omega))
	
	#@classmethod
	def electricalLength(self, l , f=None, gamma=None,deg=False):
		'''
		calculates the electrical length of a section of transmission line.
	
		takes:
			l - length of line in meters
			f: frequency at which to calculate, array-like or float
			gamma: propagationConstant a function of angular frequency (omega), 
				and returns a value with units radian/m.  
			
		returns:
			electricalLength: electrical length in radians or degrees, 
				if deg =True
		note:
			you can pass a function on the fly, like  
			electricalLength(freqVector, l, beta = lambda omega: omega/c )
		'''
		if gamma is None:
			gamma = self.propagationConstant
		if f is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				f = self.fBand.axis
				
		if deg==False:
			return  gamma(2*pi*f )*l 
		elif deg ==True:
			return  mv.rad2deg(gamma(2*pi*f ) *l )
	
	
	#@classmethod
	def reflectionCoefficient(self, l,zl,f=None,z0=None, gamma=None):
		'''
		calculates the reflection coefficient for a given load 
		takes:
			l: distance of transmission line to load, in meters (float)
			f: frequency at which to calculate, array-like or float
			zl: load impedance. may be a function of omega (2*pi*f), or 
				a number 
			z0 - characteristic impedance may be a function of omega 
				(2*pi*f), or a number 
			gamma: propagationConstant a function of angular frequency (omega), 
				and returns a value with units radian/m.
		'''<commit_msg>comenting<commit_after>'''
#       transmissionLine.py
#       
#       Copyright 2010 <NAME> <<EMAIL>>
#       
#       This program is free software; you can redistribute it and/or modify
#       it under the terms of the GNU General Public License as published by
#       the Free Software Foundation; either version 2 of the License, or
#       (at your option) any later versionpy.
#       
#       This program is distributed in the hope that it will be useful,
#       but WITHOUT ANY WARRANTY; without even the implied warranty of
#       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#       GNU General Public License for more details.
#       
#       You should have received a copy of the GNU General Public License
#       along with this program; if not, write to the Free Software
#       Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#       MA 02110-1301, USA.
'''
try:
	from scipy.constants import  epsilon_0, mu_0, c,pi, mil
	#from scipy import signal
	
except:
	raise ImportError ('Depedent Packages not found. Please install: scipy')
try:
	import numpy as npy
	from numpy import sqrt, exp, array,tan,sin,cos,inf, log, real,imag,\
	 interp, linspace, shape,zeros, reshape
except:
	raise ImportError ('Depedent Packages not found. Please install: numpy')	

import mwavepy as mv
	

# TEM transmission lines
class transmissionLine(object):
	'''
	This is a general super-class for TEM transmission lines. The 
	structure behind the methods dependencies is a results of the 
	physics. a brief summary is given below. 
	
	
	
	a TEM transmission line is defined by its:
	
		distributed Capacitance, C'
		distributed Inductance, I'
		distributed Resistance, R'
		distributed Conductance, G'
		
	from these the following quantities may be calculated, which
	are functions of angular frequency (w):
	
		distributed Impedance,  Z'(w) = R' + jwI'
		distributed Admittance, Y'(w) = G' + jwC'
	
	from these we can get to properties which define their wave behavoir
		
		characteristic Impedance, Z0(w) = sqrt(Z'(w)/Y'(w))		[ohms]
		propagation Constant,	gamma(w) = sqrt(Z'(w)*Y'(w))	
		
	
	and then finnally produce methods which we use 
		
		electrical Length
		input Impedance
		relfection Coefficient
		
	
	'''
	fBand = None
	def __init__(self, \
		distributedCapacitance,	distributedInductance,\
		distributedResistance, distributedConductance, fBand=None ):
		'''
		constructor.
		
		takes:
			distributedCapacitance, C'
			distributedInductance, I'
			distributedResistance, R'
			distributedConductance, G'
			fBand: a mwavepy.fb.frequencyBand object. this provides all 
				the	methods of the transmissionLine, with frequency info.
				this is solely for convinience, because frequently many
				calculations are done over a given range of frequencies.
				
		'''
		
		self.distributedCapacitance = distributedCapacitance
		self.distributedInductance = distributedInductance
		self.distributedResistance = distributedResistance
		self.distributedConductance = distributedConductance

		self.fBand = fBand
		
	def distributedImpedance(self,omega=None):
		'''
		distributed Impedance,  Z'(w) = R' + jwI'
		
		'''
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return self.distributedResistance+1j*omega*self.distributedInductance
	
	def distributedAdmittance(self,omega=None):
		'''
		distributed Admittance, Y'(w) = G' + jwC'
		'''
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return self.distributedConductance+1j*omega*self.distributedCapacitance
	# could put a test for losslessness here and choose whether to make this
	# a funtion of omega or not.
	def characteristicImpedance(self,omega=None):
		'''
		
		The  characteristic impedance at a given angular frequency.
			Z0(w) = sqrt(Z'(w)/Y'(w))
		takes:
			omega: radian angular frequency
		returns:
			Z0: characteristic impedance  ohms
		
		'''
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return sqrt(self.distributedImpedance(omega)/self.distributedAdmittance(omega))
	
	def propagationConstant(self,omega=None):
		'''
		the propagation constant 
			gamma(w) = sqrt(Z'(w)*Y'(w))
		
		takes: 
			omega
			
		returns:
			gamma: possibly complex propagation constant, [jrad/m+]
		'''
		
		if omega is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				omega = 2*pi*self.fBand.axis
		else:
			omega = array(omega)
		return 1j*sqrt(self.distributedImpedance(omega)*self.distributedAdmittance(omega))
	
	#@classmethod
	def electricalLength(self, l , f=None, gamma=None,deg=False):
		'''
		calculates the electrical length of a section of transmission line.
	
		takes:
			l: length of line. in meters
			f: frequency at which to calculate. array-like or float. if
				left as None and self.fBand exists, it will use that.
			gamma: propagationConstant a function of angular frequency 
				(omega), and returns a value with units radian/m. if 
				not given, will use self.propagationConstant
			deg: return in degrees or not. boolean.
		
		returns:
			theta: electrical length in radians or degrees, 
				depending on  value of deg.
		
		
		note:
			you can pass a function on the fly, like  
			electricalLength(l,f, gamma = lambda omega: omega/c )
		'''
		if gamma is None:
			gamma = self.propagationConstant
		if f is None:
			if  self.fBand is None:
				raise ValueError('please supply frequency information')
			else:
				f = self.fBand.axis
				
		if deg==False:
			return  gamma(2*pi*f )*l 
		elif deg ==True:
			return  mv.rad2deg(gamma(2*pi*f ) *l )
	
	
	#@classmethod
	def reflectionCoefficient(self, l,zl,f=None,z0=None, gamma=None):
		'''
		calculates the reflection coefficient for a given load 
		takes:
			l: distance of transmission line to load, in meters (float)
			zl: load impedance. may be a function of omega (2*pi*f), or 
				a number 
			f: frequency at which to calculate, array-like or float. if
				left as None, and self.fBand exists, it will use that.
			z0 - characteristic impedance may be a function of omega 
				(2*pi*f), or a number 
			gamma: propagationConstant a function of angular frequency (omega), 
				and returns a value with units radian/m.
		'''
{'fraction_non_alphanumeric': 0.08092345078979343, 'fraction_numerical': 0.005589307411907655, 'mean_word_length': 3.4829339143064635, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4122358', 'n_tokens_mistral': 4326, 'n_tokens_neox': 3632, 'n_words': 1347}