Skip to content
Snippets Groups Projects

Draft: Add more WDF adaptors

Open Oscar Gustafsson requested to merge wdfadaptors into master
Files
2
+ 93
7
@@ -85,8 +85,11 @@ class SeriesTwoportAdaptor(AbstractOperation):
.. math::
\begin{eqnarray}
y_0 & = & x_0 - \text{value}\times\left(x_0 + x_1\right)\\
y_1 & = & x_1 - (2-\text{value})\times\left(x_0 + x_1\right)
y_1 & = & x_1 - (2-\text{value})\times\left(x_0 + x_1\right)\\
& = & -2x_0 - x_1 + \text{value}\times\left(x_0 + x_1\right)
\end{eqnarray}
Port 1 is the dependent port.
"""
is_linear = True
is_swappable = True
@@ -120,7 +123,85 @@ class SeriesTwoportAdaptor(AbstractOperation):
def evaluate(self, a, b):
s = a + b
val = self.value
return a - val * s, b - (2 - val) * s
t = val * a
y0 = a - t
y1 = -(s + y0)
return y0, y1
@property
def value(self) -> Num:
"""Get the constant value of this operation."""
return self.param("value")
@value.setter
def value(self, value: Num) -> None:
"""Set the constant value of this operation."""
if 0 <= value <= 2:
self.set_param("value", value)
else:
raise ValueError('value must be between 0 and 2 (inclusive)')
def swap_io(self) -> None:
# Swap inputs and outputs and, hence, which port is dependent
self._input_ports.reverse()
for i, p in enumerate(self._input_ports):
p._index = i
self._output_ports.reverse()
for i, p in enumerate(self._output_ports):
p._index = i
self.set_param("value", 2 - self.value)
class ParallelTwoportAdaptor(AbstractOperation):
r"""
Wave digital filter parallel twoport-adaptor operation.
.. math::
\begin{eqnarray}
y_0 & = & - x_0 + \text{value}\times x_0 + (2 - \text{value}) \times x_1\\
& = & 2x_1 - x_0 + \text{value}\times \left(x_0 - x_1\right)
y_1 & = & - x_1 + \text{value}\times x_0 + (2 - \text{value}) \times x_1\\
& = & x_1 + \text{value}\times\left(x_0 - x_1\right)
\end{eqnarray}
Port 1 is the dependent port.
"""
is_linear = True
is_swappable = True
def __init__(
self,
value: Num = 0,
src0: Optional[SignalSourceProvider] = None,
src1: Optional[SignalSourceProvider] = None,
name: Name = Name(""),
latency: Optional[int] = None,
latency_offsets: Optional[Dict[str, int]] = None,
execution_time: Optional[int] = None,
):
"""Construct a ParallelTwoportAdaptor operation."""
super().__init__(
input_count=2,
output_count=2,
name=Name(name),
input_sources=[src0, src1],
latency=latency,
latency_offsets=latency_offsets,
execution_time=execution_time,
)
self.value = value
@classmethod
def type_name(cls) -> TypeName:
return TypeName("par2p")
def evaluate(self, a, b):
s = b - a
val = self.value
t = val * s
y1 = b - t
y0 = y1 + s
return y0, y1
@property
def value(self) -> Num:
@@ -196,7 +277,8 @@ class SeriesThreeportAdaptor(AbstractOperation):
val0, val1 = self.value
y0 = a - val0 * s
y1 = b - val1 * s
return y0, y1, -(y0 + y1 + s)
y2 = -(y0 + y1 + s)
return y0, y1, y2
@property
def value(self) -> Tuple[Num, Num]:
@@ -220,9 +302,12 @@ class ReflectionFreeSeriesThreeportAdaptor(AbstractOperation):
.. math::
\begin{eqnarray}
y_0 & = & x_0 + \text{value}\times\left(x_0 - x_1 + x_2\right)\\
y_0 & = & x_0 - \text{value}\times\left(x_0 + x_1 + x_2\right)\\
y_1 & = & -x_0 - x_2\\
y_2 & = & -x_0 - x_2 - \text{value}\times\left(x_0 - x_1 + x_2\right)
y_2 & = & x_2 - \left(1 - \text{value}\right)\times\left(x_0
+ x_1 + x_2\right) \\
& = & -x_0 - x_1 + \text{value}\times\left(x_0
+ x_1 + x_2\right)
\end{eqnarray}
Port 1 is the reflection-free port and port 2 is the dependent port.
@@ -258,8 +343,9 @@ class ReflectionFreeSeriesThreeportAdaptor(AbstractOperation):
return TypeName("rfs3p")
def evaluate(self, a, b, c):
y1 = -(a + c)
y0 = a - self.value * (b + y1)
s = a + c
y1 = -s
y0 = a - self.value * (b + s)
y2 = -(y0 + b)
return y0, y1, y2
Loading