Cleanest way to store lists of filter coefficients in a C header
Posted
by Nick T
on Stack Overflow
See other posts from Stack Overflow
or by Nick T
Published on 2010-04-21T19:18:12Z
Indexed on
2010/04/21
19:23 UTC
Read the original article
Hit count: 190
I have many (~100 or so) filter coefficients calculated with the aid of some Matlab and Excel that I want to dump into a C header file for general use, but I'm not sure what the best way to do this would be. I was starting out as so:
#define BUTTER 1
#define BESSEL 2
#define CHEBY 3
#if FILT_TYPE == BUTTER
#if FILT_ROLLOFF == 0.010
#define B0 256
#define B1 512
#define B2 256
#define A1 467
#define A2 -214
#elif FILT_ROLLOFF == 0.015
#define B0 256
#define B1 512
// and so on...
However, if I do that and shove them all into a header, I need to set the conditionals (FILT_TYPE
, FILT_ROLLOFF
) in my source before including it, which seems kinda nasty. What's more, if I have 2+ different filters that want different roll-offs/filter types it won't work. I could #undef
my 5 coefficients (A1-2, B0-2) in that coefficients file, but it still seems wrong to have to insert an #include
buried in code.
© Stack Overflow or respective owner