/* Graph a decimating CIC filter’s B-spline impulse response in ASCII * art. * * It doesn’t work. */ #include #include #include typedef uint32_t u32; /* This should have been the default. */ enum { lg_window_size = 5, filter_order = 3, lg_scale_factor = lg_window_size * filter_order, lg_impulse_size = 6, total_accumulator_bits = 1 + lg_impulse_size + lg_scale_factor, }; int main() { u32 a, b = 0, c = 0, d = 0, f = 0, g = 0, h = 0, m = 0, n = 0, o; a = 1 << (total_accumulator_bits - 1); /* ensure enough bits */ assert(a); for (int i = 0; i < (2 + filter_order) << lg_window_size; i++) { a = (i ? 0 : 1 << lg_impulse_size); if (!(i & ((1 << lg_window_size) - 1))) { g = d - f; /* previous d */ f = d; h = g - m; /* previous g */ m = g; o = (h - n) >> lg_scale_factor; /* previous h */ printf("%6d ", o); for (int j = 0; j < o && j < 1 << lg_impulse_size; j++) { fputs("##", stdout); } puts(""); n = h; } b += a; c += b; d += c; } return 0; }