[RFC PATCH] rtl-sdr: add support to change FIR coefficients

Luigi Tarenga luigi.tarenga at gmail.com
Thu Dec 29 16:31:54 UTC 2016


Hello list,
these days I was experimenting with the FIR filters. If my reasoning are 
correct
there is rooms for improvement  with some trade-off between bandwidth 
flatness
and image aliasing. I'm not saying the default FIR is to trash but I 
think there can
be specialized application that will benefit from a custom FIR.
Even to just let more people test my theory I need support for FIR 
coefficient loading
so even who can't program the driver but have lab test equipment can 
give me a
feedback. I have prepared a patch for rtl-sdr and gr-osmosdr to load FIR 
coefficients
with a device string like 
"rtl=0,fir=50:54:57:60:63:65:68:70:72:74:75:77:78:78:79:79"

for a little discussion see here with some screenshot:
https://www.reddit.com/r/RTLSDR/comments/5jqk5h/playing_with_rtl2832u_fir_filter/

I'm looking for feedback and once this patch get accepted (I hope so :) )
I will push the one for gr-osmosdr.

best regards
Luigi

PS: I hope to not send another garbage patch....

Signed-off-by: Luigi Tarenga <luigi.tarenga at gmail.com>
---
  include/rtl-sdr.h | 9 +++++++++
  src/librtlsdr.c   | 6 ++++++
  2 files changed, 15 insertions(+)

diff --git a/include/rtl-sdr.h b/include/rtl-sdr.h
index fe64bea..74cd765 100644
--- a/include/rtl-sdr.h
+++ b/include/rtl-sdr.h
@@ -169,6 +169,15 @@ RTLSDR_API int 
rtlsdr_set_freq_correction(rtlsdr_dev_t *dev, int ppm);
   */
  RTLSDR_API int rtlsdr_get_freq_correction(rtlsdr_dev_t *dev);

+/*!
+ * Load and set FIR filter coefficients.
+ *
+ * \param dev the device handle given by rtlsdr_open()
+ * \param new_fir the vector of 16 integer FIR coefficients
+ * \return 0 on success
+ */
+RTLSDR_API int rtlsdr_load_fir_coefficients(rtlsdr_dev_t *dev, int 
*new_fir);
+
  enum rtlsdr_tuner {
      RTLSDR_TUNER_UNKNOWN = 0,
      RTLSDR_TUNER_E4000,
diff --git a/src/librtlsdr.c b/src/librtlsdr.c
index 9b7ba52..4b7855f 100644
--- a/src/librtlsdr.c
+++ b/src/librtlsdr.c
@@ -613,6 +613,12 @@ int rtlsdr_set_fir(rtlsdr_dev_t *dev)
      return 0;
  }

+int rtlsdr_load_fir_coefficients(rtlsdr_dev_t *dev, int *new_fir)
+{
+    memcpy(dev->fir, new_fir, sizeof(fir_default));
+    return rtlsdr_set_fir(dev);
+}
+
  void rtlsdr_init_baseband(rtlsdr_dev_t *dev)
  {
      unsigned int i;
-- 
2.11.0



More information about the osmocom-sdr mailing list