I am trying to apply some filtering in C/C++ code, I have designed an algorithm using Matlab and it works well, so now I am moving it to native code.

I am interested in the filter function.
In my matlab script it is used as follows.

[y_blk, fir1_state] = filter( h, 1, x.*c, fir1_state ); 

Where the h argument is coefficients generated by firpm function.

I have tried to find any implementation, but unfortunately no results.

I would be very grateful if someone could provide an implementation of this function

Or maybe there is an existing implementation of this function in some library.


  • 1
    $\begingroup$ The filter function is implemented in a large number of open-source packages, such as octave and SciPy. $\endgroup$
    – MBaz
    Nov 19, 2017 at 19:33
  • $\begingroup$ look at dsp.stackexchange.com/questions/1571/… and also Google "signal processing c library" $\endgroup$
    – user28715
    Nov 19, 2017 at 21:28
  • $\begingroup$ You can find a lot of implementations of a FIR Filter on the INTERNET. I wanted to write the code but I already found it on the below link. stackoverflow.com/questions/14997850/… $\endgroup$ Feb 22, 2018 at 15:23

1 Answer 1


FIR filtering is an operation whose implementation hugely benefits from utilization of architecture-specific instructions, compiler intrinsics, etc. Hence, if your only goal is to get a performant FIR algorithm, you should try to find a dsp library specifically for your target architecture. Those are most likely written in assembly language with a C interface and you can expect an orders-of-magnitude better performance than you would achieve with a generic C implementation of a transversal FIR.

If the latter is exactly what you're looking for - a generic FIR implementation in C - let me point you towards https://iowegian.com/. They offer a commercial filter design software called ScopeFIR. You can download and install a free trial version of it (no registration). In the program directory, you can find a source file "FirAlgs.c" that offers a variety of well-documented FIR implementations. It's written for MSVC but should be portable to basically anywhere without hassle.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.