Digital filter design and test program

For an electronic engineer designing hardware and software, filters are essential building blocks. Be it old fashioned analog filters or digital filters.

When I studied for my degree, digital filters was mainly something you talked about, but hardly used. 😉 Yes, that was back in the early Eighties.

Later on, I decided to learn more about the digital filter world and I stumbled over this website:

http://www-users.cs.york.ac.uk/~fisher/mkfilter/

Mr. Tony Fisher and I had at least three things in common: A huge red beard,  a keen interest in electronics and at that time (in the Nineties) we were both lecturing new generation of engineers, Tony in UK and me in Denmark!

I learned a lot from this site and from reading Tony’s source code.

Sadly, Tony passed away way too early in 2000. See here  http://www-users.cs.york.ac.uk/~fisher/tribute.html

Years later I found his website again and I decided to pay Tony a tribute of my own: I have compiled his source code nearly ‘as is’ and made it part of a digital filter design package. My work is nothing compared to Tony’s: I have just made a wrapper to design and graph digital filters. This is a work in progress, so please comment, come up with suggestions and report bugs. Thanks.

Currently, it is only possible to make IIR filters. FIR will be added later. Also, the PI filter selection is not implemented yet.

The compiler I used is Code::Blocks, an open source C, C++ and /Fortran compiler.

A couple of screen shots:

(When using the program: To zoom in on a graph, use left mouse button and drag down/right. To zoom out, left button and drag up/left. To pan, use the right mouse button.)

The filter response

The filter response

Filter2

The output from the process is listed here: As you can see, only small changes need to be made to the generated filter source code.


CFilter.exe -Bu -Bp -l -o 2 -a 0.00625 0.009375
G = 1.0519144258e+004
 NZ = 4
  1.0000000000e+000
  0.0000000000e+000
 -2.0000000000e+000
  0.0000000000e+000
  1.0000000000e+000
 NP = 4
 -9.7261396931e-001
  3.9129314819e+000
 -5.9079629924e+000
  3.9676402044e+000
 -1.0000000000e+000
 /* Digital filter designed by mkfilter/mkshape/gencode A.J. Fisher
 Command line: CFilter.exe -Bu -Bp -l -o 2 -a 0.00625 0.009375 */

// Code snippet begin
#define NZEROS 4
#define NPOLES 4
#define GAIN 1.051914426e+004
static float xv[NZEROS+1], yv[NPOLES+1];

static void filterloop()
{ 
 for (;;)
   { 
      xv[0] = xv[1]; xv[1] = xv[2]; xv[2] = xv[3]; xv[3] = xv[4];
      xv[4] = `next input value' / GAIN;
      yv[0] = yv[1]; yv[1] = yv[2]; yv[2] = yv[3]; yv[3] = yv[4];
      yv[4] = (xv[0] + xv[4]) - 2 * xv[2] 
            + ( -0.9726139693 * yv[0]) + ( 3.9129314819 * yv[1])
            + ( -5.9079629924 * yv[2]) + ( 3.9676402044 * yv[3]);
      `next output value' = yv[4];
   }
}
// Code snippet end
Command line: CFilter.exe -Bu -Bp -o 2 -a 0.00625 0.009375
 raw alpha1 = 0.0062500000
 raw alpha2 = 0.0093750000
 warped alpha1 = 0.0062508033
 warped alpha2 = 0.0093777117
 gain at dc : mag = 0.000000000e+000
 gain at centre: mag = 1.051914426e+004 phase = -0.0451288069 pi
 gain at hf : mag = 0.000000000e+000
S-plane zeros:
  0.00000000000000 + j 0.00000000000000 2 times
S-plane poles:
 -0.00794903284609 + j  0.05506235983393
 -0.00794903284609 + j -0.05506235983393
 -0.00594345510846 + j -0.04116987187937
 -0.00594345510846 + j  0.04116987187937
Z-plane zeros:
  1.00000000000000 + j  0.00000000000000 2 times
 -1.00000000000000 + j  0.00000000000000 2 times
Z-plane poles:
  0.99058556207380 + j  0.05458621543982
  0.99058556207380 + j -0.05458621543982
  0.99323454013401 + j -0.04090903481545
  0.99323454013401 + j  0.04090903481545
Recurrence relation:
 y[n] = ( 1 * x[n- 4])
 + (  0 * x[n- 3])
 + ( -2 * x[n- 2])
 + (  0 * x[n- 1])
 + (  1 * x[n- 0])
 + ( -0.97261396931306 * y[n- 4])
 + (  3.91293148191814 * y[n- 3])
 + ( -5.90796299238891 * y[n- 2])
 + (  3.96764020441562 * y[n- 1])

As can be seen, it is also possible to test a real life signal by reading in a text file containing one sample per line. Just select ‘Read from text file’ !

To use the package, simply unpack the filters.zip into a directory of your choice and run the filter.exe. [Windows only at the moment]

Download link
One final note: This is free software and not supposed to be used commercially. Please respect Mr. Tony Fisher’s copyrights.


 

PS If you find this tool valuable to you, please consider a donation to an organization involved in finding a cure for cancer.  Thanks.

I can higly recommend you to support  http://www.lls.org/ or  http://www.teamintraining.org/


One Response

  1. emsm06
    emsm06 April 14, 2021 at 05:47 |

    Hello

    We used to use the web based platform from Mr. Tony Fisher to design IRR lowpass filter c code, but unfortunatelly its not available anymore, so i tried to use this FIlter Software, but when i press make filter it appears a window with a message : “‘-1.#IND00000000000’ IS NOT A VALID FLOATING POINT VALUE” do you know why its happening?

    Regards

    Eduardo Maia


Leave a Reply

You must be logged in to post a comment.

This site uses Akismet to reduce spam. Learn how your comment data is processed.