aboutsummaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
authorAndreas Eversberg <jolly@eversberg.eu>2017-11-13 19:15:09 +0100
committerAndreas Eversberg <jolly@eversberg.eu>2017-11-13 19:15:09 +0100
commit669705c6edb5cfbcb2f0ca672612777d1e819aa6 (patch)
tree18738791ae76f22a2dedf2007c202bfaad72d69b /src/common
parentfc1c5de54746857cc7b21e44b83b042792b3ddaa (diff)
Restructure: Move filters from common code to 'libfilter'
Diffstat (limited to 'src/common')
-rw-r--r--src/common/Makefile.am1
-rw-r--r--src/common/emphasis.c2
-rw-r--r--src/common/fm_modulation.h2
-rw-r--r--src/common/iir_filter.c167
-rw-r--r--src/common/iir_filter.h17
-rw-r--r--src/common/samplerate.h2
6 files changed, 3 insertions, 188 deletions
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 6005e56..7a59d64 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -10,7 +10,6 @@ libcommon_a_SOURCES = \
wave.c \
goertzel.c \
jitter.c \
- iir_filter.c \
dtmf.c \
samplerate.c \
emphasis.c \
diff --git a/src/common/emphasis.c b/src/common/emphasis.c
index 5a1453e..08f944a 100644
--- a/src/common/emphasis.c
+++ b/src/common/emphasis.c
@@ -22,7 +22,7 @@
#include <string.h>
#include <math.h>
#include "sample.h"
-#include "iir_filter.h"
+#include "../libfilter/iir_filter.h"
#include "emphasis.h"
#include "debug.h"
diff --git a/src/common/fm_modulation.h b/src/common/fm_modulation.h
index d0bdaa1..68f0bcd 100644
--- a/src/common/fm_modulation.h
+++ b/src/common/fm_modulation.h
@@ -1,4 +1,4 @@
-#include "../common/iir_filter.h"
+#include "../libfilter/iir_filter.h"
enum fm_mod_state {
MOD_STATE_OFF, /* transmitter off, no IQ vector */
diff --git a/src/common/iir_filter.c b/src/common/iir_filter.c
deleted file mode 100644
index 3d1e15c..0000000
--- a/src/common/iir_filter.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* cut-off filter (biquad) based on Nigel Redmon (www.earlevel.com)
- *
- * (C) 2016 by Andreas Eversberg <jolly@eversberg.eu>
- * All Rights Reserved
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <stdio.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-#include <math.h>
-#include "sample.h"
-#include "iir_filter.h"
-
-#define PI M_PI
-
-void iir_lowpass_init(iir_filter_t *filter, double frequency, int samplerate, int iterations)
-{
- double Fc, Q, K, norm;
-
- if (iterations > 64) {
- fprintf(stderr, "%s failed: too many iterations, please fix!\n", __func__);
- abort();
- }
-
- memset(filter, 0, sizeof(*filter));
- filter->iter = iterations;
- Q = pow(sqrt(0.5), 1.0 / (double)iterations); /* 0.7071 @ 1 iteration */
- Fc = frequency / (double)samplerate;
- K = tan(PI * Fc);
- norm = 1 / (1 + K / Q + K * K);
- filter->a0 = K * K * norm;
- filter->a1 = 2 * filter->a0;
- filter->a2 = filter->a0;
- filter->b1 = 2 * (K * K - 1) * norm;
- filter->b2 = (1 - K / Q + K * K) * norm;
-}
-
-void iir_highpass_init(iir_filter_t *filter, double frequency, int samplerate, int iterations)
-{
- double Fc, Q, K, norm;
-
- memset(filter, 0, sizeof(*filter));
- filter->iter = iterations;
- Q = pow(sqrt(0.5), 1.0 / (double)iterations); /* 0.7071 @ 1 iteration */
- Fc = frequency / (double)samplerate;
- K = tan(PI * Fc);
- norm = 1 / (1 + K / Q + K * K);
- filter->a0 = 1 * norm;
- filter->a1 = -2 * filter->a0;
- filter->a2 = filter->a0;
- filter->b1 = 2 * (K * K - 1) * norm;
- filter->b2 = (1 - K / Q + K * K) * norm;
-}
-
-void iir_bandpass_init(iir_filter_t *filter, double frequency, int samplerate, int iterations)
-{
- double Fc, Q, K, norm;
-
- memset(filter, 0, sizeof(*filter));
- filter->iter = iterations;
- Q = pow(sqrt(0.5), 1.0 / (double)iterations); /* 0.7071 @ 1 iteration */
- Fc = frequency / (double)samplerate;
- K = tan(PI * Fc);
- norm = 1 / (1 + K / Q + K * K);
- filter->a0 = K / Q * norm;
- filter->a1 = 0;
- filter->a2 = -filter->a0;
- filter->b1 = 2 * (K * K - 1) * norm;
- filter->b2 = (1 - K / Q + K * K) * norm;
-}
-
-void iir_notch_init(iir_filter_t *filter, double frequency, int samplerate, int iterations)
-{
- double Fc, Q, K, norm;
-
- memset(filter, 0, sizeof(*filter));
- filter->iter = iterations;
- Q = pow(sqrt(0.5), 1.0 / (double)iterations); /* 0.7071 @ 1 iteration */
- Fc = frequency / (double)samplerate;
- K = tan(PI * Fc);
- norm = 1 / (1 + K / Q + K * K);
- filter->a0 = (1 + K * K) * norm;
- filter->a1 = 2 * (K * K - 1) * norm;
- filter->a2 = filter->a0;
- filter->b1 = filter->a1;
- filter->b2 = (1 - K / Q + K * K) * norm;
-}
-
-void iir_process(iir_filter_t *filter, sample_t *samples, int length)
-{
- double a0, a1, a2, b1, b2;
- double *z1, *z2;
- double in, out;
- int iterations = filter->iter;
- int i, j;
-
- /* get states */
- a0 = filter->a0;
- a1 = filter->a1;
- a2 = filter->a2;
- b1 = filter->b1;
- b2 = filter->b2;
-
- /* these are state pointers, so no need to write back */
- z1 = filter->z1;
- z2 = filter->z2;
-
- /* process filter */
- for (i = 0; i < length; i++) {
- in = *samples;
- for (j = 0; j < iterations; j++) {
- out = in * a0 + z1[j];
- z1[j] = in * a1 + z2[j] - b1 * out;
- z2[j] = in * a2 - b2 * out;
- in = out;
- }
- *samples++ = in;
- }
-}
-
-void iir_process_baseband(iir_filter_t *filter, float *baseband, int length)
-{
- double a0, a1, a2, b1, b2;
- double *z1, *z2;
- double in, out;
- int iterations = filter->iter;
- int i, j;
-
- /* get states */
- a0 = filter->a0;
- a1 = filter->a1;
- a2 = filter->a2;
- b1 = filter->b1;
- b2 = filter->b2;
-
- /* these are state pointers, so no need to write back */
- z1 = filter->z1;
- z2 = filter->z2;
-
- /* process filter */
- for (i = 0; i < length; i++) {
- in = *baseband;
- for (j = 0; j < iterations; j++) {
- out = in * a0 + z1[j];
- z1[j] = in * a1 + z2[j] - b1 * out;
- z2[j] = in * a2 - b2 * out;
- in = out;
- }
- *baseband = in;
- baseband += 2;
- }
-}
-
diff --git a/src/common/iir_filter.h b/src/common/iir_filter.h
deleted file mode 100644
index a5956c8..0000000
--- a/src/common/iir_filter.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _FILTER_H
-#define _FILTER_H
-
-typedef struct iir_filter {
- int iter;
- double a0, a1, a2, b1, b2;
- double z1[64], z2[64];
-} iir_filter_t;
-
-void iir_lowpass_init(iir_filter_t *filter, double frequency, int samplerate, int iterations);
-void iir_highpass_init(iir_filter_t *filter, double frequency, int samplerate, int iterations);
-void iir_bandpass_init(iir_filter_t *filter, double frequency, int samplerate, int iterations);
-void iir_notch_init(iir_filter_t *filter, double frequency, int samplerate, int iterations);
-void iir_process(iir_filter_t *filter, sample_t *samples, int length);
-void iir_process_baseband(iir_filter_t *filter, float *baseband, int length);
-
-#endif /* _FILTER_H */
diff --git a/src/common/samplerate.h b/src/common/samplerate.h
index 4fbf680..8f8ea87 100644
--- a/src/common/samplerate.h
+++ b/src/common/samplerate.h
@@ -1,4 +1,4 @@
-#include "iir_filter.h"
+#include "../libfilter/iir_filter.h"
typedef struct samplerate {
double factor;