From 068d08bf44aafc1b36fec7302130f1a5b2fde08c Mon Sep 17 00:00:00 2001 From: ZoRo Date: Fri, 9 Jul 2021 09:01:22 +0100 Subject: FIR filter C snippet --- fir1/Makefile | 2 ++ fir1/simple_fir.c | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ fir1/verify_fir.m | 85 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 184 insertions(+) create mode 100644 fir1/Makefile create mode 100644 fir1/simple_fir.c create mode 100644 fir1/verify_fir.m diff --git a/fir1/Makefile b/fir1/Makefile new file mode 100644 index 0000000..70c416d --- /dev/null +++ b/fir1/Makefile @@ -0,0 +1,2 @@ +make: + gcc simple_fir.c -o simple_fir -lm \ No newline at end of file diff --git a/fir1/simple_fir.c b/fir1/simple_fir.c new file mode 100644 index 0000000..8f48569 --- /dev/null +++ b/fir1/simple_fir.c @@ -0,0 +1,97 @@ +#include +#include +#include +#include + +double sinc(double x) { + if (x>-1.0E-5 && x < 1.0E-5) return (1.0); + return sin(x)/x; +} + +int main() { + + const int buf_N=200; + //int N1 = N/2; + + int i=0; + double h[buf_N],w[buf_N]; + int filter_N=20; + int even = filter_N ? 0: 1; + int filter_N1=filter_N/2; + int filter_FS_hz=10000; + int filter_FC_hz=2000; + double omega_c=1.0*filter_FC_hz/filter_FS_hz; + double arg; + double dN; + + //nullify all coefficients + for (i=0;i