Skip to content

Instantly share code, notes, and snippets.

@harieamjari
Created February 15, 2023 13:03
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 harieamjari/5ba664699cf9734f2824145e64433761 to your computer and use it in GitHub Desktop.
Save harieamjari/5ba664699cf9734f2824145e64433761 to your computer and use it in GitHub Desktop.
Notch filter transfer function
/* Notch filter at 10000Hz */
#include <stdio.h>
#include <complex.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
int main(int argc, char *argv[]){
assert(argc == 2);
float complex e = M_E;
float sample = 32.0;
float rp = 2.0*M_PI*10000.0/44100.0;
float deg = 2.0*M_PI/44100.0;
float con = 1.0;
float complex r = con*cpowf(e, I*rp);
float complex p = con*cpowf(e, I*rp)*0.95;
for (int i = 0; i < 32*44100; i++){
float magr = cabsf(con*cpowf(e, I*deg*(float)i/sample) - r);
float magp = cabsf(con*cpowf(e, I*deg*(float)i/sample) - p);
printf("%f %f\n", (float)i/sample, magr/magp );
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment