block TransferFunction "Complex Transfer Function"
import Modelica.ComplexMath.j;
import Modelica.ComplexMath.'sum';
extends Modelica.ComplexBlocks.Interfaces.ComplexSISO;
parameter Real b[:] = {1} "Numerator coefficients of transfer function (e.g., 2*s+3 is specified as {2,3})";
parameter Real a[:] = {1} "Denominator coefficients of transfer function (e.g., 5*s+6 is specified as {5,6})";
Modelica.Blocks.Interfaces.RealInput w "Frequency input"
annotation (Placement(transformation(
extent = {
{-20, -20},
{20, 20}},
rotation = 90,
origin = {0, -120})));
protected
Complex bw[size(b, 1)];
Complex aw[size(a, 1)];
Complex bSum;
Complex aSum;
equation
y = u * bSum / aSum;
aSum = Complex(sum(aw.re), sum(aw.im));
aw = {a[i] * (j * w) ^ (i - 1) for i in 1:size(a, 1)};
bSum = Complex(sum(bw.re), sum(bw.im));
bw = {b[i] * (j * w) ^ (i - 1) for i in 1:size(b, 1)};
annotation (
Icon(graphics = {
Text(
lineColor = {0, 0, 127},
extent = {
{-90, 10},
{90, 90}},
textString = "b(jw)"),
Line(
points = {
{-80, 0},
{80, 0}},
color = {0, 0, 127}),
Text(
lineColor = {0, 0, 127},
extent = {
{-90, -90},
{90, -10}},
textString = "a(jw)")}),
Documentation(info = "<html>\n<p>\nThe complex input u is multiplied by the complex transfer function (depending on frequency input w) to obtain the complex output y (nb = dimension of b, na = dimension of a):\n</p>\n<pre>\n b[1]*(jw)^[nb-1] + b[2]*(jw)^[nb-2] + ... + b[nb]\n y(jw) = ------------------------------------------------- * u(jw)\n a[1]*(jw)^[na-1] + a[2]*(jw)^[na-2] + ... + a[na]\n</pre>\n</html>"));
end TransferFunction;