Created
June 9, 2019 13:46
-
-
Save Micrified/c209b127922d87691b9932fcbdc78bef to your computer and use it in GitHub Desktop.
Butterworth Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fp gain = 0x80; | |
fp k1 = 0x2E00; | |
fp k2 = 0x6C00; | |
fp x_phi[MAX_COEF]; | |
fp y_phi[MAX_COEF]; | |
int32_t c_phi; | |
void butterworth_phi () { | |
// Save the sign, then remove it | |
int32_t sign = (c_phi >> 31); | |
c_phi *= sign; | |
// Shuffle older samples back | |
x_phi[0] = x_phi[1]; x_phi[1] = x_phi[2]; | |
y_phi[0] = y_phi[1]; y_phi[1] = y_phi[2]; | |
// Insert latest sample (gain is actually 1/gain) | |
x_phi[2] = mul(INT_TO_FP(c_phi), gain); | |
// Compute next output sample | |
fp a = mul(k1, y_phi[0]); | |
fp b = mul(k2, y_phi[1]); | |
y_phi[2] = x_phi[0] + (x_phi[1] << 1) + x_phi[2] - a + b; | |
// Update the global variable | |
c_phi = FP_TO_INT(y_phi[2]); | |
// Restore the sign | |
c_phi *= sign; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment