Take the 2-minute tour ×
Signal Processing Stack Exchange is a question and answer site for practitioners of the art and science of signal, image and video processing. It's 100% free, no registration required.


Often times I am doing some sort of signal processing task that requires a unique filter. Usually at this point I go to Matlab and generate a new unique filter using firpm(). The Matlab firpm() function implements that Parks-McClellan algorithm. Now I have a filter and I put the filter into a hardcoded array. But here's the problem I now have a hardcoded filter that only works for one scenario.

The problem:

I can now solve my signal processing problem du-jour... but only for a very SPECIFIC single sample rate or SPECIFIC scenario.

The goal:

I want to be able to call firpm() from C code or some other language and make my signal processing code more generic. I can't find an open source implementation of firpm()!

Where can I get an open source implementation of the Parks-McClellan optimal FIR filter design algorithm (aka firpm() in Matlab)?

p.s. I am aware that I can design filters differently using windowing or something else... feel free to mention those in the comments. But the point of this question is not to ask "what are other filter design techniques?" the point is to find an open source implementation of the VERY VERY useful firpm()... or something similar.

p.p.s. One of the goals of this question is to learn how the parks-mcclelan algorithm works by looking at the code first and then I plan on reading some background theory.

share|improve this question
Is it important that the solution is free? Have you investigated the Matlab C API? –  user42 Aug 21 '11 at 16:21
The highest priority is I want to see the source code (preferably not fortran so I don't have to stab my eyes out). I won't put the restriction that it must be free (maybe there is some sort of open source but non-free source code). –  Trevor Boyd Smith Aug 21 '11 at 16:38
I am aware that you can compile Matlab using the Matlab compiler and then distribute using Matlab Runtime... so technically your customer doesn't have to pay for Matlab license. I am also aware of the Matlab Engine (aka C to Matlab API). Both of these are irrelevant because I usually run on an embedded platform where neither are available. –  Trevor Boyd Smith Aug 21 '11 at 16:42
@TrevorBoydSmith Since you just want to look at the source code, have you tried type firpm.m in MATLAB? That will show you MATLAB's implementation of the function. –  Lorem Ipsum Aug 22 '11 at 15:48
FIR filter design is very useful for signal processing and parks-mcclelan is a non-trivial subject matter. And yet I am being down voted repeatedly for asking about a subject that IMO fits squarely in the dsp.stackexchange charter. Please explain your downvotes. –  Trevor Boyd Smith Aug 23 '11 at 16:26

6 Answers 6

up vote 4 down vote accepted

Here's an LGPL version of the Remez exchange algorithm. The octave code seems to be derived from it. It was linked from the wikipedia page Parks McClellan page.
The original Janovetz code might be more easily usable in your project, since it doesn't have the octave calls, but it would be wise to dig through the octave-forge svn changelog for any info about bugfixes or speedups in the remez.cc file.

share|improve this answer
I agree using the Janovetz code in a project would be easier because it is straight C. I also definitely agree that checking the change log of the octave implementation would be very smart. –  Trevor Boyd Smith Sep 13 '11 at 16:25
The Janovetz code IMO is probably a first or second draft... but hasn't been used heavily like the Octave code. –  Trevor Boyd Smith Sep 13 '11 at 16:25
VERY IMPORTANT NOTE: The Janovetz code is LGPL so you can use it in a commercial setting. –  Trevor Boyd Smith Sep 13 '11 at 16:26
The first link from the answer is broken so here is a link to a library where the same implementation is used. –  Machta Feb 17 '14 at 16:12

There is an open-source implementation of Parks-McClellan (also known as the Remez exchange algorithm) in GNU Octave, a free-software implementation of a MATLAB-like environment. The function, called "remez", is contained in the "signal" package, which is hosted at Octave-Forge. If you download the package, you'll find "remez.cc", a C++ implementation of the algorithm.

One nice thing about Octave is that it is almost code-compatible with MATLAB, so you can easily port code over to use there if you like. It's a good way to peek under the hood at implementations of algorithms that are provided in MEX form in MATLAB.

share|improve this answer
"The Parks-McClellan algorithm is a variation of the Remez algorithm or Remez exchange algorithm, with the change that it is specifically designed for FIR filters and has become a standard method for FIR filter design." Also in SciPy: docs.scipy.org/doc/scipy/reference/generated/… –  endolith Aug 22 '11 at 14:35

A convenient version can be found in Python's scipy.signal.remez. Nice if using numpy/scipy.

share|improve this answer
The C-source code appears to be here: github.com/scipy/scipy/blob/master/scipy/signal/… –  Dave C Feb 11 '13 at 5:00

Here is another source for the Parks McClellan algorithm in C. This code is different from the SciPy code mentioned above in that it has 61 of the original 69 goto statements removed (the SciPy code still has about 37 goto's). It also fixes the code in 3 places where divide by zero can occur and it has some additional code that range checks the band edge values.


share|improve this answer

maybe you already know this, but if you have matlab you can use the matlab coder, and create a simple function that uses the feature you want to examine. Then run it and see the created C code. I tried with with the FFT, and with QR decomposition, and while it is a bit messy, it can be understood just fine.

share|improve this answer

Here is a paper which does an actual Matlab version of the "core" remez algorithm. “A MATLAB based optimum multiband FIR filters design program following the original idea of the Remez multiple exchange algorithm” -2011 IEEE International Symposium on Circuits and Systems (ISCAS) - Authors (Ahsan, Saramaki)

This paper does a good job at explaining the basic algorithm. The goal of the paper was to avoid using the original Fortran code - which does not explain the algorithm very well and often just gets translated into various other languages directly.

One thing I will comment on. One of the core ideas of the algorithm is to fit a curve and then find the extremal points. Usually a Lagrange Interpolation is used to explain this idea, but Lagrange Interpolation has poor numerical properties. In the original algorithm the use Barycentric Implementation of Lagrange Interpolation - which avoids many of the associated pitfalls of Lagrangian interpolation. So if you are trying to fully understand the code, you may want to look up Barycentric Interpolation.

share|improve this answer
Looking at the paper - it is a modified version of the Parks-McClellan code. It is still based on the Remez exchange algorithm, but it tends to have better performance, and allows you to design filters which are much longer than those you get from the PM algorithm (or Matlab's implementation of it). –  David Jan 23 '14 at 13:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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