Skip to content

Instantly share code, notes, and snippets.

@superctr
Last active December 20, 2017 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save superctr/b804c255d3f6a27efe9d8c82441c6069 to your computer and use it in GitHub Desktop.
Save superctr/b804c255d3f6a27efe9d8c82441c6069 to your computer and use it in GitHub Desktop.
IIR low pass cutoff calculator
/*
Calculate filter constant for a single pole low pass IIR filter
given cut off freq and the sample rate.
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc,char *argv[])
{
if(argc<2)
{
printf("usage:f1,f2\n");
return -1;
}
double cutoff = strtof(argv[1],NULL);
double rate = strtof(argv[2],NULL);
double omega_c = 2*M_PI*(cutoff/rate);
double b = 2 - cos(omega_c) - sqrt(pow(2-cos(omega_c),2)-1);
printf("b = %.15g\n",b);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment