Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 6 of 6

Thread: Calculation of FIR coefficients

  1. #1
    Junior Member
    Join Date
    Jun 2018

    Library for calculation of FIR coefficients

    Those who use FIR filters may be interested in a very early version of a library to calculate FIR coefficients which I created. It is a translation of the firwin Python code in the scipy library. Scipy does a fantastic job at calculating these coefficients. In my library (fir_filters) I implemented only a subset of firwin, only the code to calculate a (single) bandpass filter, and only using the Kaiser window. Expanding the library to include other filters should not be too difficult. I do not know about using other window types. That may be a bit harder.

    The library has been (lightly) tested in my SDR running on a Teensy 3.6. It is very fast, and allows runtime calculation of the coefficients. Calculating the FIR coefficients at development time is not necessary anymore!

    The code for this library is available at Let me know what you think. I am neither an expert in DSP, nor in Python, so there may (will) still be bugs in the code.

    Have fun!
    Last edited by koen; 08-07-2018 at 01:04 PM.

  2. #2
    Junior Member
    Join Date
    Jun 2018
    I have included some example code in

  3. #3
    Senior Member
    Join Date
    May 2017
    Thanks for sharing. I have bookmarked your lib for future reference.
    Do you have a youtube video of your SDR in action?

    I played with some DSP coding a long time ago. I wonder if you would consider code for a low pass filter. I remember that low pass filter constants could be changed into high pass and bandpass fairly easily.

    Ok. I have located my old code. And here are the functions I wrote back then ( DOS Mix Power C ).

    void modtohigh(){  
    int i;
      for( i= 1; i < order; i+= 2 ) a[i]= -a[i];  /* pretty simple heh? */
    void mod( int freq, int sample ){     // where freq is center freq and sample is the sample rate
    double update, phase;
    int i,j,k;
    extern int order;
     if( freq ){
        update= (double)sample/(double)freq;   /* # of samples in 360 deg */
        update= 6.2831852/update;               /* update in radians */
        phase= 0; 
    /* try starting in the middle so we keep the linear phase characteristic */
    /* preset the phase so can go from start to finish */    
        j= order/2;
        k= 2*j;
        if( k == order ) {         /* even order */
           phase+= update/2.0;   /* split the diff */
        while( --j >= 0 ) phase-= update;   /* find starting phase */
        for( i= 0; i < order; ++i ){
           a[i]= cos( phase ) * a[i] * 2;   /* mod constants to new freq */
           phase += update;

  4. #4
    Junior Member
    Join Date
    Jun 2018
    No, unfortunately I do not have a video of my SDR running.

    Thanks for sharing your code. I will study it. But as the original Python sources encompass all type of filters (LP, HP, BP, notch, ...), I will translate that code into C when there is a need. This is not so difficult now the foundation is there in C.

  5. #5
    Senior Member DD4WH's Avatar
    Join Date
    Oct 2015
    Central Europe

    there is a function providing FIR coeffs for lowpass, highpass, bandpass, notch and Hilbert transform written by Walter for the Teensy (in the context of Fast Convolution filtering, but the coefficients are identical whether you perform filtering in the time or frequency domain):

    look for:
    void calc_FIR_coeffs (float * coeffs, int numCoeffs, float32_t fc, float32_t Astop, int type, float dfc)
    It was discussed here:

    Maybe that helps!

    All the best, have fun,

    Frank DD4WH

  6. #6
    Analog Devices has a book called, "The Scientist and Engineer's Guide to Digital Signal Processing" that is available on their website. Chapter 16 provides a step-by-step process for designing your own FIR filter. See I've used it to design filters in Excel and then download the filter coefficients into my applications.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts