Skip to content

Commit

Permalink
added "Filter" Component
Browse files Browse the repository at this point in the history
  • Loading branch information
Ott Alexander authored and Ott Alexander committed Jan 8, 2020
1 parent 9f60858 commit e490f10
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 7 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ The current Documentation is found under this link : <https://rf-linkbudget.read
## Abstract
RF-LinkBudget is a software package to aid RF Hardware Developer in defining and comparing LinkBudget’s of RF Ciruits.
It calculates key parameter’s like cumulative Noise Figure, cumulates Gain, Intermodulation Signal Amplitudes and so on.

## Changelog

# 1.0.2
Added `Filter` Component
17 changes: 17 additions & 0 deletions docs/rf_linkbudget_circuit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,23 @@ As we see in this example, we set the attenuator to 15.6dB for all input powers
The function **setAttenuation** will set it to the nearest attenuation value defined in the constructor.
In this case the zero value will get set to effectively 1.0dB and the 15.6dB will be rounded up to 16.0dB.


Filter
^^^^^^^^^^^^^^

An filter is a classical two port device.
It has a frequency response

.. code-block:: python
:linenos:
filter = rf.Filter("Filter 1",
Att=[(100, 1.5),(200, 4.5),(300, 55)])
As we see, we can define the frequency response like the frequency response of an Amplifier.


SPDT
^^^^^^^^^^^^^^

Expand Down
1 change: 1 addition & 0 deletions rf_linkbudget/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .circuit import Amplifier
from .circuit import Attenuator
from .circuit import Filter
from .circuit import SPDT
from .circuit import Mixer
#from .circuit import ADC
Expand Down
74 changes: 68 additions & 6 deletions rf_linkbudget/circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ class genericTwoPort(AbstractDevice):
device name
Gain : list of [f, Gain]
Gain representation in [dB], frequency in [Hz]
Tn : list of [Tn @ Port 1, Tn @ Port 2]
Tn : list of [Tn @ Port 1, Tn @ Port 2] : Tn np.float or list of [f, Tn]
noisetemperature of object, represented at the "target" port [°K]
P1 : list of [P1 @ Port 1, P1 @ Port 2]
Signal Compression Point of object, represented at the "target" port in [dB]
Expand Down Expand Up @@ -593,7 +593,7 @@ def fromSParamFile(cls, name, filename, Tn, P1, IP3, patchString='S12DB'):
sparam = rf.touchstone.Touchstone(filename)
sparam = sparam.get_sparameter_data(format='db')

Gain = [[f, [s21]] for f, s21 in zip(sparam['frequency'], sparam[patchString])]
Gain = [(f, s21) for f, s21 in zip(sparam['frequency'], sparam[patchString])]

return cls(name, Gain=Gain, Tn=Tn, P1=P1, IP3=IP3)

Expand Down Expand Up @@ -627,18 +627,48 @@ def calcCurrentEdge(self, start, end, data):

if start == self.ports[0] and end == self.ports[1]:

Gain = np.interp(data['f'], *zip(*self.Gain)) # interpolate Gain value
# Gain = np.interp(data['f'], *zip(*self.Gain)) # interpolate Gain value
Gain = self.interpolateIfListOfFreqValTuple(data['f'], self.Gain)
Tn = self.interpolateIfListOfFreqValTuple(data['f'], self.Tn[1])
P1 = self.interpolateIfListOfFreqValTuple(data['f'], self.P1[1])
IP3 = self.interpolateIfListOfFreqValTuple(data['f'], self.IP3[1])

out['Gain'] = data['Gain'] + Gain # calc cumulative Gain
out['Tn'] = RFMath.calc_Tn(data['Tn'], self.Tn[1], Gain) # calc output NoiseTemperature
out['Tn'] = RFMath.calc_Tn(data['Tn'], Tn, Gain) # calc output NoiseTemperature
out['p'] = RFMath.calc_Pout(data['p'], Gain) # calc output signal power
out['P1'] = RFMath.calc_P1(data['P1'], self.P1[1], Gain) # calc output P1dB point
out['IP3'] = RFMath.calc_IP3(data['IP3'], self.IP3[1], Gain) # calc output IP3 point (simple)
out['P1'] = RFMath.calc_P1(data['P1'], P1, Gain) # calc output P1dB point
out['IP3'] = RFMath.calc_IP3(data['IP3'], IP3, Gain) # calc output IP3 point (simple)
# calc other values...
return out

else:
raise ValueError('this should not happen')

def interpolateIfListOfFreqValTuple(self, freq, value):
"""
if value is of the form: [(f,val)] then interpolate, otherwise ignore this function
Parameters
----------
freq : np.float
frequency of interest
value : float, or [(f,val)]
value which might get interpolated
Returns
-------
data : np.float
value or interpolated value
"""

if type(value) != list:
return value
if len(value) == 0:
raise ValueError('value does not contain any values... thats shouldn\'t happen')
if type(value[0]) == tuple:
# Good thats what we expect and want to interpolate
return np.interp(freq, *zip(*value))

# ============================================================================ #


Expand Down Expand Up @@ -823,6 +853,38 @@ def setAttenuation(self, Att):
# ============================================================================ #


class Filter(genericTwoPort):
"""
| A filter device.
Parameters
----------
name : str
device name
Att : list of (f, Att)
Attenuation representation in [dB]
"""

def __init__(self, name, Att, OP1dB=None):
"""
Parameters
----------
name : str
device name
Att : list of (f, Att)
Attenuation representation in [dB]
OP1dB : numpy.float
Output Signal Compression Point in [dB]
"""

Tn = [(f, 10**(att/10) * RFMath.T0 - RFMath.T0) for f, att in Att]
Gain = [(f, -att) for f, att in Att]
super().__init__(name, Gain=Gain, Tn=[0, Tn], P1=[0, OP1dB], IP3=[0, None])


# ============================================================================ #


class SPDT(AbstractDevice):
"""
| An spdt device.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
long_description = fh.read()

setuptools.setup(name='rf-linkbudget',
version='1.0.1',
version='1.0.2',
description='A simple rf-linkbudget calculation tool',
url='https://github.com/hwengineer/rf_linkbudget',
author='Alexander Ott',
Expand Down

0 comments on commit e490f10

Please sign in to comment.