#include #include #include #include #include int order = 8, factor = 64, bits = 24; /* * convert double to fixed-point integer */ int mkfp(double x) { long long r, unit; unit = 1LL << (bits - 1); r = x * unit + ((x >= 0) ? 0.5 : -0.5); if (r < -unit || r >= unit) { fprintf(stderr, "%g: sample out of range\n", x); exit(1); } return r; } /* * Blackman window function */ double win_blackman(double a, double x) { if (x < 0) x = -x; return (x >= 0.5) ? 0 : 0.5 * (1 - a) + 0.5 * cos(2 * M_PI * x) + 0.5 * a * cos(4 * M_PI * x); } /* * Ideal low-pass filter response */ double lowpass_sinc(double cutoff, double t) { double arg; if (t == 0) return cutoff; arg = M_PI * t; return sin(cutoff * arg) / arg; } /* * Convert table index to time */ double timeof(int i) { return (double)(i - order * factor / 2) / factor; } int main(void) { double t; double h; double cutoff = 3. / 4.; double param = 0.16; int i; printf("{"); for (i = 0; i <= order * factor; i++) { t = timeof(i); h = lowpass_sinc(cutoff, t) * win_blackman(param, t / order); if (i != 0) printf(","); printf("%s", (i % 8 == 0) ? "\n\t" : " "); printf("%7d", mkfp(h)); } printf("\n};\n"); return 0; }