Skip to content
Snippets Groups Projects

Draft: Add more WDF adaptors

Open Oscar Gustafsson requested to merge wdfadaptors into master
Files
2
+ 63
2
@@ -3,7 +3,7 @@ B-ASIC Core Operations Module.
Contains wave digital filter adaptors.
"""
from typing import Dict, Optional
from typing import Dict, Optional, Tuple
from b_asic.graph_component import Name, TypeName
from b_asic.operation import AbstractOperation
@@ -101,7 +101,7 @@ class SeriesTwoportAdaptor(AbstractOperation):
latency_offsets: Optional[Dict[str, int]] = None,
execution_time: Optional[int] = None,
):
"""Construct a SymmetricTwoportAdaptor operation."""
"""Construct a SeriesTwoportAdaptor operation."""
super().__init__(
input_count=2,
output_count=2,
@@ -144,3 +144,64 @@ class SeriesTwoportAdaptor(AbstractOperation):
for i, p in enumerate(self._output_ports):
p._index = i
self.set_param("value", 2 - self.value)
class SeriesThreeportAdaptor(AbstractOperation):
r"""
Wave digital filter series threeport-adaptor operation.
.. math::
\begin{eqnarray}
y_0 & = & x_0 - \text{value}_0\times\left(x_0 + x_1 + x_2\right)\\
y_1 & = & x_1 - \text{value}_1\times\left(x_0 + x_1 + x_2\right)\\
y_2 & = & x_2 - \left(2 - \text{value}_0 - \text{value}_1\right)\times\left(x_0
+ x_1 + x_2\right)
\end{eqnarray}
"""
is_linear = True
is_swappable = True
def __init__(
self,
value: Tuple[Num, Num] = (0, 0),
src0: Optional[SignalSourceProvider] = None,
src1: Optional[SignalSourceProvider] = None,
src2: Optional[SignalSourceProvider] = None,
name: Name = Name(""),
latency: Optional[int] = None,
latency_offsets: Optional[Dict[str, int]] = None,
execution_time: Optional[int] = None,
):
"""Construct a SeriesThreeportAdaptor operation."""
super().__init__(
input_count=3,
output_count=3,
name=Name(name),
input_sources=[src0, src1, src2],
latency=latency,
latency_offsets=latency_offsets,
execution_time=execution_time,
)
self.value = value
@classmethod
def type_name(cls) -> TypeName:
return TypeName("ser3p")
def evaluate(self, a, b, c):
s = a + b + c
val0, val1 = self.value
return a - val0 * s, b - val1 * s, c - (2 - val0 - val1) * s
@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 <= sum(value) <= 2:
self.set_param("value", value)
else:
raise ValueError('sum of value must be between 0 and 2 (inclusive)')
Loading