View Raw SPL
/*****************************************************************************
* *
* SOS2TF.SPL Copyright (C) 2005 DSP Development Corporation *
* All Rights Reserved *
* *
* Author: Randy Race *
* *
* Synopsis: Converts SOS form filter coefficients to direct form *
* *
* Revisions: 30 Mar 2005 RRR Creation *
* *
*****************************************************************************/
#if @HELP_SOS2TF
SOS2TF
Purpose:
Converts second order section form coefficients to direct form.
Format:
SOS2TF(sos, g)
(b, a) = SOS2TF(sos, g)
sos - A Nx6 array where the first 3 columns are the numerator
terms and the last 3 columns are the denominator terms.
Each row represents a 2nd order stage.
g - Optional. A real, the gain, Defaults to 1.0.
Returns:
A two column series, where the first column contains the
direct form numerator coefficients and the second column
contains the direct form denominator coefficients.
(b, a) = SOS2TF(sos, g) returns the direct form numerator
and denominator coefficients as two separate series.
Example:
sos = {{1, 0, 0, 1, -0.5, 0.2}};
d = sos2tf(c);
d == {{1, 1},
{0, -0.5},
{0, 0.2}}
The second order section filter coefficients represent the
following Z transform:
-1 -2
1 + 0.0z + 0.0z
H(z) = 1 * -------------------
-1 -2
1 - 0.5z + 0.2z
The resulting direct form filter coefficients represent the
equivalent Z transform:
1
H(z) = -------------------
-1 -2
1 - 0.5z + 0.2z
Example:
sos = {{1, 0, 0, 1, -0.754856, 0.392379}.
{1, 0, 0, 1, 0.254856, 0}};
d = sos2tf(b, a);
d == {{1, 1},
{0, -0.5},
{0, 0.2},
{0, 0.1}}
The SOS filter coefficients represent the following two stage
cascaded Z transform:
-1 -2
1 + 0.0z + 0.0z
H(z) = 1 * ----------------------------
-1 -2
1 - 0.754856z + 0.392379z
-1 -2
1 + 0.0z + 0.0z
* ------------------------
-1 -2
1 - 0.254856z + 0.0z
The resulting direct form coefficients represent the equivalent
Z transform:
1
H(z) = -----------------------------
-1 -2 -3
1 - 0.5z + 0.2z + 0.1z
Example:
sos = {{1, 0, 0, 1, -0.754856, 0.392379}.
{1, 0, 0, 1, 0.254856, 0}};
(b, a) = sos2tf(sos);
b == {1, 0, 0, 0}
a == {1, -0.5, 0.2, 0.1}
Same as the previous example except the direct form coefficients
are returned as two separate series.
Remarks:
SOS2TF converts second order section form filter coefficients
to direct form. The SOS form coefficients represent the
following Z transform:
-1 -2 -1 -2
b10 + b11 z + b12 z b20 + b21 z + b22 z
H(z) = G * ________________________ * ________________________ ...
-1 -2 -1 -2
1 + a11 z + a12 z 1 + a21 z + a22 z
where the SOS form is an Nx6 array:
{{b10, b11, b12, 1, a11, a12},
{b20, b21, b22, 1, a21, a22},
...
{bN0, bN1, bN2, 1, aN1, aN2}}
Each row of the SOS coefficients represents a second order stage.
The equivalent direct form coefficients represent the following
Z transform:
-1 -Q
Y(z) b[1] + b[2]*z + ... + b[Q+1]*z
H(z) = ---- = -------------------------------------
-1 -P
X(z) 1 + a[2]*z + ... + a[P+1]*z
jw
where z = e unit circle (frequency response)
Q order of zeros (numerator)
P order of poles (denominator)
See TF2SOS to convert direct form coefficients to SOS form.
See Also:
Cas2dir
Cascade
Tf2sos
#endif
/* second order section to transfer function (direct) form */
sos2tf(sos, k)
{
local cas, a, b;
if (argc < 2)
{
if (argc < 1) sos = {};
k = 1.0;
}
if (numcols(sos) != 6) error("sos2tf - Nx6 SOS array required");
/* convert to cascade form */
cas = sos2cas(sos, k);
/* direct terms for cascade */
(b, a) = cas2tf(cas);
if (outargc > 0)
{
return(b, a);
}
else
{
return(ravel(b, a));
}
}