/* * This program is free software; you can redistribute it and modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the license or (at your * option) any later version. * * Authors: Markus Fick fir-resampler, technical information * Chris Moeller Table/struct file generator * */ #include #include /* ------------------------------------------------------------------------------------------------ fir interpolation doc, (derived from "an engineer's guide to fir digital filters", n.j. loy) calculate coefficients for ideal lowpass filter (with cutoff = fc in 0..1 (mapped to 0..nyquist)) c[-N..N] = (i==0) ? fc : sin(fc*pi*i)/(pi*i) then apply selected window to coefficients c[-N..N] *= w(0..N) with n in 2*N and w(n) being a window function (see loy) then calculate gain and scale filter coefs to have unity gain. ------------------------------------------------------------------------------------------------ */ // quantizer scale of window coefs #define WFIR_QUANTBITS 14 #define WFIR_QUANTSCALE (1L<>1) // cutoff (1.0 == pi/2) #define WFIR_CUTOFF 0.90f #define WFIR_CUTOFFBITS 9 #define WFIR_CUTOFFLEN ((1L<<(WFIR_CUTOFFBITS))+1) // wfir type #define WFIR_HANN 0 #define WFIR_HAMMING 1 #define WFIR_BLACKMANEXACT 2 #define WFIR_BLACKMAN3T61 3 #define WFIR_BLACKMAN3T67 4 #define WFIR_BLACKMAN4T92 5 #define WFIR_BLACKMAN4T74 6 #define WFIR_KAISER4T 7 #define WFIR_TYPE WFIR_BLACKMANEXACT // wfir help #ifndef M_zPI #define M_zPI 3.1415926535897932384626433832795 #endif #define M_zEPS 1e-8 #define M_zBESSELEPS 1e-21 class CzWINDOWEDFIR { public: CzWINDOWEDFIR( ); ~CzWINDOWEDFIR( ); float coef( int _PCnr, float _POfs, float _PCut, int _PWidth, int _PType ) //float _PPos, float _PFc, int _PLen ) { double _LWidthM1 = _PWidth-1; double _LWidthM1Half = 0.5*_LWidthM1; double _LPosU = ((double)_PCnr - _POfs); double _LPos = _LPosU-_LWidthM1Half; double _LPIdl = 2.0*M_zPI/_LWidthM1; double _LWc,_LSi; if( fabs(_LPos)_LScale)?_LScale:_LCoef) ); } } } CzWINDOWEDFIR::~CzWINDOWEDFIR() { // nothing todo } CzWINDOWEDFIR sfir; // extern "C" signed short *fir_lut = &CzWINDOWEDFIR::lut[0]; #define lut(a) CzWINDOWEDFIR::lut[a] int main() { FILE *f; int i; f = fopen("fir_table.h","w"); fprintf(f,"static __int64 fir_lut[%d] = {\n",WFIR_LUTLEN * 2); for (i=0;i<(WFIR_LUTLEN*WFIR_WIDTH);i+=WFIR_WIDTH) { fprintf(f,"\t0x%.4hx%.4hx%.4hx%.4hx, 0x%.4hx%.4hx%.4hx%.4hx%s", lut(i+3), lut(i+2), lut(i+1), lut(i), lut(i+7), lut(i+6), lut(i+5), lut(i+4), (i<((WFIR_LUTLEN-1)*WFIR_WIDTH)) ? ",\n" : "\n};\n"); } fclose(f); return(0); }