summaryrefslogtreecommitdiff
path: root/gr-filter/python
diff options
context:
space:
mode:
authorYamakaja <dastw@gmx.net>2020-08-29 14:28:23 +0200
committermormj <34754695+mormj@users.noreply.github.com>2020-10-20 09:56:24 -0400
commit0f045e515352973a4effe5dc50b7bccf7b1ae371 (patch)
tree598febdeec4a3bde0b89129600b61cd01c86676a /gr-filter/python
parent465dea1e73006da6e45ea2eee3b2caab80a9490e (diff)
gr-filter: Add complex band rejection design helpers
Diffstat (limited to 'gr-filter/python')
-rw-r--r--gr-filter/python/filter/bindings/docstrings/firdes_pydoc_template.h6
-rw-r--r--gr-filter/python/filter/bindings/firdes_python.cc29
-rw-r--r--gr-filter/python/filter/optfir.py26
3 files changed, 59 insertions, 2 deletions
diff --git a/gr-filter/python/filter/bindings/docstrings/firdes_pydoc_template.h b/gr-filter/python/filter/bindings/docstrings/firdes_pydoc_template.h
index 3eccb93fcb..441e430b57 100644
--- a/gr-filter/python/filter/bindings/docstrings/firdes_pydoc_template.h
+++ b/gr-filter/python/filter/bindings/docstrings/firdes_pydoc_template.h
@@ -57,6 +57,12 @@ static const char* __doc_gr_filter_firdes_band_reject = R"doc()doc";
static const char* __doc_gr_filter_firdes_band_reject_2 = R"doc()doc";
+static const char* __doc_gr_filter_firdes_complex_band_reject = R"doc()doc";
+
+
+static const char* __doc_gr_filter_firdes_complex_band_reject_2 = R"doc()doc";
+
+
static const char* __doc_gr_filter_firdes_hilbert = R"doc()doc";
diff --git a/gr-filter/python/filter/bindings/firdes_python.cc b/gr-filter/python/filter/bindings/firdes_python.cc
index 5de53ccb63..1f7dc94f99 100644
--- a/gr-filter/python/filter/bindings/firdes_python.cc
+++ b/gr-filter/python/filter/bindings/firdes_python.cc
@@ -13,8 +13,8 @@
/* If manual edits are made, the following tags should be modified accordingly. */
/* BINDTOOL_GEN_AUTOMATIC(0) */
/* BINDTOOL_USE_PYGCCXML(0) */
-/* BINDTOOL_HEADER_FILE(firdes.h) */
-/* BINDTOOL_HEADER_FILE_HASH(d9728e3175c510584d65ddba33955bb2) */
+/* BINDTOOL_HEADER_FILE(firdes.h) */
+/* BINDTOOL_HEADER_FILE_HASH(0b2837cc3e5dcdc4435575d7ce1950df) */
/***********************************************************************************/
#include <pybind11/complex.h>
@@ -177,6 +177,31 @@ void bind_firdes(py::module& m)
D(firdes, band_reject_2))
+ .def_static("complex_band_reject",
+ &firdes::complex_band_reject,
+ py::arg("gain"),
+ py::arg("sampling_freq"),
+ py::arg("low_cutoff_freq"),
+ py::arg("high_cutoff_freq"),
+ py::arg("transition_width"),
+ py::arg("window") = ::gr::filter::firdes::win_type::WIN_HAMMING,
+ py::arg("beta") = 6.7599999999999998,
+ D(firdes, complex_band_reject))
+
+
+ .def_static("complex_band_reject_2",
+ &firdes::complex_band_reject_2,
+ py::arg("gain"),
+ py::arg("sampling_freq"),
+ py::arg("low_cutoff_freq"),
+ py::arg("high_cutoff_freq"),
+ py::arg("transition_width"),
+ py::arg("attenuation_dB"),
+ py::arg("window") = ::gr::filter::firdes::win_type::WIN_HAMMING,
+ py::arg("beta") = 6.7599999999999998,
+ D(firdes, complex_band_reject_2))
+
+
.def_static("hilbert",
&firdes::hilbert,
py::arg("ntaps") = 19,
diff --git a/gr-filter/python/filter/optfir.py b/gr-filter/python/filter/optfir.py
index f26617a42a..1e6ac5b544 100644
--- a/gr-filter/python/filter/optfir.py
+++ b/gr-filter/python/filter/optfir.py
@@ -100,6 +100,32 @@ def complex_band_pass (gain, Fs, freq_sb1, freq_pb1, freq_pb2, freq_sb2,
taps = [s*t for s,t in zip(spinner, lptaps)]
return taps
+def complex_band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2,
+ passband_ripple_db, stopband_atten_db,
+ nextra_taps=2):
+ """
+ Builds a band reject filter with complex taps by making an HPF and
+ spinning it up to the right center frequency
+
+ Args:
+ gain: Filter gain in the passband (linear)
+ Fs: Sampling rate (sps)
+ freq_pb1: End of pass band (in Hz)
+ freq_sb1: Start of stop band (in Hz)
+ freq_sb2: End of stop band (in Hz)
+ freq_pb2: Start of pass band (in Hz)
+ passband_ripple_db: Pass band ripple in dB (should be small, < 1)
+ stopband_atten_db: Stop band attenuation in dB (should be large, >= 60)
+ nextra_taps: Extra taps to use in the filter (default=2)
+ """
+ center_freq = (freq_sb2 + freq_sb1) / 2.0
+ hp_pb = (freq_pb2 - center_freq) / 1.0
+ hp_sb = freq_sb2 - center_freq
+ hptaps = high_pass(gain, Fs, hp_sb, hp_pb, passband_ripple_db,
+ stopband_atten_db, nextra_taps)
+ spinner = [cmath.exp(2j*cmath.pi*center_freq/Fs*i) for i in range(len(hptaps))]
+ taps = [s*t for s,t in zip(spinner, hptaps)]
+ return taps
def band_reject (gain, Fs, freq_pb1, freq_sb1, freq_sb2, freq_pb2,
passband_ripple_db, stopband_atten_db,