Skip to content

Instantly share code, notes, and snippets.

@merryhime
Last active February 17, 2016 23:43
Show Gist options
  • Save merryhime/e02a1da20ce61d0b1a24 to your computer and use it in GitHub Desktop.
Save merryhime/e02a1da20ce61d0b1a24 to your computer and use it in GitHub Desktop.
Transfer Function Notes
Implementing signal flow graphs:
Signal flow graph for this implementation. All junctions are additive.
G(z) = (b0 + b1 z^-1 + b2 z^-2) / (1 - a1 z^-1 - a2 z^-2)
There are many possible implementations for a given transfer fuction, this is but one of them.
For ease of understanding this implementation uses twice as many delays as necessary, and is thus non-canonical wrt delays.
x tmp y
------+---- b0 ---->o----->o-------------+------>
| ^ ^ |
v | | v
z^-1 | | z^-1
| | | |
+---- b1 ---->o o<---- a1 ----+
| ^ ^ |
v | | v
z^-1 | | z^-1
| | | |
+---- b2 -----+ +----- a2 ----+
for clarity the sample code below doesn't correct for the fact it's fixed-point math
s16 x0; // input x
s16 x1; // x after 1 delay
s16 x2; // x after 2 delays
s16 y0; // output y
s16 y1; // y after 1 delay
s16 y2; // y after 2 delays
while (has data) {
x0 = getX();
// Compute curent state
s16 tmp = b0 * x0 + b1 * x1 + b2 * x2;
y0 = tmp + a1 * y1 + a2 * y2;
// Emit
emitY(y0);
// Advance state
x2 = x1;
x1 = x0;
y2 = y1;
y1 = y0;
}
This is an alternative signal flow graph for the same biquad filter.
This is a canonical delay implementation, using the minimal number of delays.
x y
----->o-------------+---- b0 ---->o----->
^ | ^
| v |
| z^-1 |
| | |
o<---- a1 ----+---- b1 ---->o
^ | ^
| v |
| z^-1 |
| | |
+----- a2 ----+---- b2 -----+
s16 u0;
s16 u1;
s16 u2;
while (true) {
s16 x = getX();
// Compute current state
u0 = x + a1 * u1 + a2 * u2;
s16 y = b0 * u0 + b1 * u1 + b2 * u2;
emitY(y);
// Advance state
u2 = u1;
u1 = u0;
}
This produces equivalent results to the above.
==============================================================
Examples of equivalent signal flow graphs:
G(z) = G(z) = b0 / (1 + a1 z^-1)
Equivalent signal flow graphs for the above transfer function. All junctions are additive.
x y
----- b0 ---->o-------------+------>
^ |
| v
| z^-1
| |
+----- a1 ----+
x y
------->o-------------+---- b0 ----->
^ |
| v
| z^-1
| |
+----- a1 ----+
x y
------->o-----------------+---- b0 ----->
^ |
| |
+--- z^-1 -- a1 --+
Here's an example where one can use the above signal flow graph as a low-pass filter:
http://m.eet.com/media/1051422/C0543-Figure3.gif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment