summaryrefslogtreecommitdiff
path: root/gr-filter
diff options
context:
space:
mode:
Diffstat (limited to 'gr-filter')
-rw-r--r--gr-filter/include/filter/fir_filter_with_buffer.h3
-rw-r--r--gr-filter/lib/fir_filter_with_buffer.cc75
-rw-r--r--gr-filter/lib/qa_fir_filter_with_buffer.cc10
-rw-r--r--gr-filter/lib/qa_mmse_fir_interpolator_cc.cc8
-rw-r--r--gr-filter/lib/qa_mmse_fir_interpolator_ff.cc10
-rwxr-xr-xgr-filter/python/qa_pfb_channelizer.py8
6 files changed, 69 insertions, 45 deletions
diff --git a/gr-filter/include/filter/fir_filter_with_buffer.h b/gr-filter/include/filter/fir_filter_with_buffer.h
index 8b5d9e064..007eae3fa 100644
--- a/gr-filter/include/filter/fir_filter_with_buffer.h
+++ b/gr-filter/include/filter/fir_filter_with_buffer.h
@@ -40,6 +40,7 @@ namespace gr {
private:
std::vector<float> d_taps;
unsigned int d_ntaps;
+ float *d_buffer_ptr;
float *d_buffer;
unsigned int d_idx;
float **d_aligned_taps;
@@ -136,6 +137,7 @@ namespace gr {
private:
std::vector<gr_complex> d_taps;
unsigned int d_ntaps;
+ gr_complex *d_buffer_ptr;
gr_complex *d_buffer;
unsigned int d_idx;
gr_complex **d_aligned_taps;
@@ -232,6 +234,7 @@ namespace gr {
private:
std::vector<float> d_taps;
unsigned int d_ntaps;
+ gr_complex *d_buffer_ptr;
gr_complex *d_buffer;
unsigned int d_idx;
float **d_aligned_taps;
diff --git a/gr-filter/lib/fir_filter_with_buffer.cc b/gr-filter/lib/fir_filter_with_buffer.cc
index 105214087..7a35a9225 100644
--- a/gr-filter/lib/fir_filter_with_buffer.cc
+++ b/gr-filter/lib/fir_filter_with_buffer.cc
@@ -40,7 +40,7 @@ namespace gr {
d_align = volk_get_alignment();
d_naligned = d_align / sizeof(float);
- d_buffer = NULL;
+ d_buffer_ptr = NULL;
d_aligned_taps = NULL;
set_taps(taps);
@@ -50,9 +50,9 @@ namespace gr {
fir_filter_with_buffer_fff::~fir_filter_with_buffer_fff()
{
- if(d_buffer != NULL) {
- fft::free(d_buffer);
- d_buffer = NULL;
+ if(d_buffer_ptr != NULL) {
+ fft::free(d_buffer_ptr);
+ d_buffer_ptr = NULL;
}
// Free aligned taps
@@ -71,9 +71,9 @@ namespace gr {
void
fir_filter_with_buffer_fff::set_taps(const std::vector<float> &taps)
{
- if(d_buffer != NULL) {
- fft::free(d_buffer);
- d_buffer = NULL;
+ if(d_buffer_ptr != NULL) {
+ fft::free(d_buffer_ptr);
+ d_buffer_ptr = NULL;
}
// Free the taps if already allocated
@@ -89,8 +89,15 @@ namespace gr {
d_taps = taps;
std::reverse(d_taps.begin(), d_taps.end());
- d_buffer = fft::malloc_float(2*d_ntaps);
- memset(d_buffer, 0, 2*d_ntaps*sizeof(float));
+ // We allocate enough to be able to look back and forth
+ // d_naligned beyond the buffer boundaries and make sure these
+ // are zeroed out (or they may be nan, which will cause
+ // problems). We then set d_buffer to the position in the
+ // d_buffer_ptr such that we only touch the internally
+ // allocated space.
+ d_buffer_ptr = fft::malloc_float(2*(d_ntaps + d_naligned));
+ memset(d_buffer_ptr, 0, 2*(d_ntaps + d_naligned)*sizeof(float));
+ d_buffer = d_buffer_ptr + d_naligned;
// Allocate aligned taps
d_aligned_taps = (float**)malloc(d_naligned*sizeof(float**));
@@ -186,7 +193,7 @@ namespace gr {
d_align = volk_get_alignment();
d_naligned = d_align / sizeof(gr_complex);
- d_buffer = NULL;
+ d_buffer_ptr = NULL;
d_aligned_taps = NULL;
set_taps(taps);
@@ -196,9 +203,9 @@ namespace gr {
fir_filter_with_buffer_ccc::~fir_filter_with_buffer_ccc()
{
- if(d_buffer != NULL) {
- fft::free(d_buffer);
- d_buffer = NULL;
+ if(d_buffer_ptr != NULL) {
+ fft::free(d_buffer_ptr);
+ d_buffer_ptr = NULL;
}
// Free aligned taps
@@ -217,9 +224,9 @@ namespace gr {
void
fir_filter_with_buffer_ccc::set_taps(const std::vector<gr_complex> &taps)
{
- if(d_buffer != NULL) {
- fft::free(d_buffer);
- d_buffer = NULL;
+ if(d_buffer_ptr != NULL) {
+ fft::free(d_buffer_ptr);
+ d_buffer_ptr = NULL;
}
// Free the taps if already allocated
@@ -235,8 +242,15 @@ namespace gr {
d_taps = taps;
std::reverse(d_taps.begin(), d_taps.end());
- d_buffer = fft::malloc_complex(2*d_ntaps);
- memset(d_buffer, 0, 2*d_ntaps*sizeof(gr_complex));
+ // We allocate enough to be able to look back and forth
+ // d_naligned beyond the buffer boundaries and make sure these
+ // are zeroed out (or they may be nan, which will cause
+ // problems). We then set d_buffer to the position in the
+ // d_buffer_ptr such that we only touch the internally
+ // allocated space.
+ d_buffer_ptr = fft::malloc_complex(2*(d_ntaps + d_naligned));
+ memset(d_buffer_ptr, 0, 2*(d_ntaps + d_naligned)*sizeof(gr_complex));
+ d_buffer = d_buffer_ptr + d_naligned;
// Allocate aligned taps
d_aligned_taps = (gr_complex**)malloc(d_naligned*sizeof(gr_complex**));
@@ -332,7 +346,7 @@ namespace gr {
d_align = volk_get_alignment();
d_naligned = d_align / sizeof(gr_complex);
- d_buffer = NULL;
+ d_buffer_ptr = NULL;
d_aligned_taps = NULL;
set_taps(taps);
@@ -342,9 +356,9 @@ namespace gr {
fir_filter_with_buffer_ccf::~fir_filter_with_buffer_ccf()
{
- if(d_buffer != NULL) {
- fft::free(d_buffer);
- d_buffer = NULL;
+ if(d_buffer_ptr != NULL) {
+ fft::free(d_buffer_ptr);
+ d_buffer_ptr = NULL;
}
// Free aligned taps
@@ -363,9 +377,9 @@ namespace gr {
void
fir_filter_with_buffer_ccf::set_taps(const std::vector<float> &taps)
{
- if(d_buffer != NULL) {
- fft::free(d_buffer);
- d_buffer = NULL;
+ if(d_buffer_ptr != NULL) {
+ fft::free(d_buffer_ptr);
+ d_buffer_ptr = NULL;
}
// Free the taps if already allocated
@@ -381,8 +395,15 @@ namespace gr {
d_taps = taps;
std::reverse(d_taps.begin(), d_taps.end());
- d_buffer = fft::malloc_complex(2*d_ntaps);
- memset(d_buffer, 0, 2*d_ntaps*sizeof(gr_complex));
+ // We allocate enough to be able to look back and forth
+ // d_naligned beyond the buffer boundaries and make sure these
+ // are zeroed out (or they may be nan, which will cause
+ // problems). We then set d_buffer to the position in the
+ // d_buffer_ptr such that we only touch the internally
+ // allocated space.
+ d_buffer_ptr = fft::malloc_complex(2*(d_ntaps + d_naligned));
+ memset(d_buffer_ptr, 0, 2*(d_ntaps + d_naligned)*sizeof(gr_complex));
+ d_buffer = d_buffer_ptr + d_naligned;
// Allocate aligned taps
d_aligned_taps = (float**)malloc(d_naligned*sizeof(float**));
diff --git a/gr-filter/lib/qa_fir_filter_with_buffer.cc b/gr-filter/lib/qa_fir_filter_with_buffer.cc
index f8af9ea0b..6a1744b0a 100644
--- a/gr-filter/lib/qa_fir_filter_with_buffer.cc
+++ b/gr-filter/lib/qa_fir_filter_with_buffer.cc
@@ -39,8 +39,6 @@ namespace gr {
#define MAX_DATA (16383)
#define ERR_DELTA (1e-5)
-#define NELEM(x) (sizeof(x) / sizeof(x[0]))
-
static float
uniform()
{
@@ -58,8 +56,8 @@ namespace gr {
random_complex(gr_complex *buf, unsigned n)
{
for(unsigned i = 0; i < n; i++) {
- float re = rint(uniform () * MAX_DATA);
- float im = rint(uniform () * MAX_DATA);
+ float re = rint(uniform() * MAX_DATA);
+ float im = rint(uniform() * MAX_DATA);
buf[i] = gr_complex(re, im);
}
}
@@ -148,7 +146,7 @@ namespace gr {
new kernel::fir_filter_with_buffer_fff(f1_taps);
// zero the output, then do the filtering
- memset(actual_output, 0, sizeof(actual_output));
+ memset(actual_output, 0, OUTPUT_LEN*sizeof(o_type));
f1->filterNdec(actual_output, input, ol/decimate, decimate);
// check results
@@ -263,7 +261,7 @@ namespace gr {
new kernel::fir_filter_with_buffer_ccc(f1_taps);
// zero the output, then do the filtering
- memset(actual_output, 0, sizeof(actual_output));
+ memset(actual_output, 0, OUTPUT_LEN*sizeof(o_type));
f1->filterNdec(actual_output, input, ol/decimate, decimate);
// check results
diff --git a/gr-filter/lib/qa_mmse_fir_interpolator_cc.cc b/gr-filter/lib/qa_mmse_fir_interpolator_cc.cc
index 02e0b32fe..268b8801c 100644
--- a/gr-filter/lib/qa_mmse_fir_interpolator_cc.cc
+++ b/gr-filter/lib/qa_mmse_fir_interpolator_cc.cc
@@ -27,6 +27,7 @@
#include <cppunit/TestAssert.h>
#include <qa_mmse_fir_interpolator_cc.h>
#include <filter/mmse_fir_interpolator_cc.h>
+#include <fft/fft.h>
#include <cstdio>
#include <cmath>
#include <stdexcept>
@@ -35,8 +36,6 @@
namespace gr {
namespace filter {
-#define NELEM(x) (sizeof(x) / sizeof(x[0]))
-
static float
test_fcn_sin(double index)
{
@@ -62,9 +61,9 @@ namespace gr {
qa_mmse_fir_interpolator_cc::t1()
{
static const unsigned N = 100;
- __GR_ATTR_ALIGNED(8) gr_complex input[N + 10];
+ gr_complex *input = fft::malloc_complex(N + 10);
- for(unsigned i = 0; i < NELEM(input); i++)
+ for(unsigned i = 0; i < N+10; i++)
input[i] = test_fcn((double) i);
mmse_fir_interpolator_cc intr;
@@ -79,6 +78,7 @@ namespace gr {
// printf ("%9.6f %9.6f %9.6f\n", expected, actual, expected - actual);
}
}
+ fft::free(input);
}
/*
diff --git a/gr-filter/lib/qa_mmse_fir_interpolator_ff.cc b/gr-filter/lib/qa_mmse_fir_interpolator_ff.cc
index 128b638b9..54387fd9b 100644
--- a/gr-filter/lib/qa_mmse_fir_interpolator_ff.cc
+++ b/gr-filter/lib/qa_mmse_fir_interpolator_ff.cc
@@ -27,14 +27,13 @@
#include <cppunit/TestAssert.h>
#include <qa_mmse_fir_interpolator_ff.h>
#include <filter/mmse_fir_interpolator_ff.h>
+#include <fft/fft.h>
#include <cstdio>
#include <cmath>
namespace gr {
namespace filter {
-#define NELEM(x) (sizeof(x) / sizeof(x[0]))
-
static float
test_fcn(double index)
{
@@ -45,10 +44,12 @@ namespace gr {
void
qa_mmse_fir_interpolator_ff::t1()
{
+ // use aligned malloc and make sure that everything in this
+ // buffer is properly initialized.
static const unsigned N = 100;
- float input[N + 10];
+ float *input = fft::malloc_float(N + 10);
- for(unsigned i = 0; i < NELEM(input); i++)
+ for(unsigned i = 0; i < N+10; i++)
input[i] = test_fcn((double) i);
mmse_fir_interpolator_ff intr;
@@ -63,6 +64,7 @@ namespace gr {
// printf ("%9.6f %9.6f %9.6f\n", expected, actual, expected - actual);
}
}
+ fft::free(input);
}
} /* namespace filter */
diff --git a/gr-filter/python/qa_pfb_channelizer.py b/gr-filter/python/qa_pfb_channelizer.py
index 3d35c46e4..c0ed8327d 100755
--- a/gr-filter/python/qa_pfb_channelizer.py
+++ b/gr-filter/python/qa_pfb_channelizer.py
@@ -70,10 +70,10 @@ class test_pfb_channelizer(gr_unittest.TestCase):
# Adjusted phase rotations for data
p0 = 0
- p1 = 1.6335486
- p2 = -3.01609
- p3 = 3.01609
- p4 = -1.6335486
+ p1 = math.pi*0.51998885
+ p2 = -math.pi*0.96002233
+ p3 = math.pi*0.96002233
+ p4 = -math.pi*0.51998885
# Create known data as complex sinusoids at the different baseband freqs
# the different channel numbering is due to channelizer output order.