patch_mavec.diff
| gnuradio-core/src/python/gnuradio/gr/qa_moving_average_vXX.py (revision 0) | ||
|---|---|---|
| 1 |
#!/usr/bin/env python |
|
| 2 |
# |
|
| 3 |
# Copyright 2007 Free Software Foundation, Inc. |
|
| 4 |
# |
|
| 5 |
# This file is part of GNU Radio |
|
| 6 |
# |
|
| 7 |
# GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
# it under the terms of the GNU General Public License as published by |
|
| 9 |
# the Free Software Foundation; either version 3, or (at your option) |
|
| 10 |
# any later version. |
|
| 11 |
# |
|
| 12 |
# GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
# GNU General Public License for more details. |
|
| 16 |
# |
|
| 17 |
# You should have received a copy of the GNU General Public License |
|
| 18 |
# along with GNU Radio; see the file COPYING. If not, write to |
|
| 19 |
# the Free Software Foundation, Inc., 51 Franklin Street, |
|
| 20 |
# Boston, MA 02110-1301, USA. |
|
| 21 |
# |
|
| 22 | ||
| 23 |
from gnuradio import gr, gr_unittest |
|
| 24 | ||
| 25 |
class test_moving_average_vector (gr_unittest.TestCase): |
|
| 26 | ||
| 27 |
def setUp (self): |
|
| 28 |
self.tb = gr.top_block () |
|
| 29 | ||
| 30 | ||
| 31 |
def tearDown (self): |
|
| 32 |
self.tb = None |
|
| 33 | ||
| 34 | ||
| 35 |
def test_001(self): |
|
| 36 |
src_data = (1,1,0, 2,2,0, 3,3,0, 4,4,0, 5,5,0) |
|
| 37 |
vlen = 3 |
|
| 38 |
MAlen = 3 |
|
| 39 |
expected_result = (1.0/3,1.0/3,0, 1,1,0, 2,2,0, 3,3,0, 4,4,0) |
|
| 40 | ||
| 41 |
src = gr.vector_source_f(src_data, False, vlen) |
|
| 42 |
MA = gr.moving_average_vff(MAlen, vlen, 1.0/3) |
|
| 43 |
dst = gr.vector_sink_f(vlen) |
|
| 44 | ||
| 45 |
self.tb.connect(src, MA, dst) |
|
| 46 |
self.tb.run() |
|
| 47 |
result_data = dst.data() |
|
| 48 |
self.assertFloatTuplesAlmostEqual(expected_result, result_data) |
|
| 49 | ||
| 50 | ||
| 51 |
if __name__ == '__main__': |
|
| 52 |
gr_unittest.main () |
|
| 53 | ||
| gnuradio-core/src/python/gnuradio/gr/Makefile.am (working copy) | ||
|---|---|---|
| 95 | 95 |
qa_unpack_k_bits.py \ |
| 96 | 96 |
qa_repeat.py \ |
| 97 | 97 |
qa_scrambler.py \ |
| 98 |
qa_vector_sink_source.py |
|
| 98 |
qa_vector_sink_source.py \ |
|
| 99 |
qa_moving_average_vXX.py |
|
| gnuradio-core/src/lib/gengen/gr_moving_average_vXX.i.t (revision 0) | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2008 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 3, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License |
|
| 18 |
* along with GNU Radio; see the file COPYING. If not, write to |
|
| 19 |
* the Free Software Foundation, Inc., 51 Franklin Street, |
|
| 20 |
* Boston, MA 02110-1301, USA. |
|
| 21 |
*/ |
|
| 22 | ||
| 23 |
// @WARNING@ |
|
| 24 | ||
| 25 |
GR_SWIG_BLOCK_MAGIC(gr,@BASE_NAME@); |
|
| 26 | ||
| 27 |
@SPTR_NAME@ gr_make_@BASE_NAME@ (int length, int vlen, @O_TYPE@ scale, int max_iter=4096); |
|
| 28 | ||
| 29 |
class @NAME@ : public gr_sync_block |
|
| 30 |
{
|
|
| 31 |
private: |
|
| 32 |
@NAME@ (); |
|
| 33 |
}; |
|
| gnuradio-core/src/lib/gengen/gr_moving_average_vXX.cc.t (revision 0) | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2008 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 3, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License |
|
| 18 |
* along with GNU Radio; see the file COPYING. If not, write to |
|
| 19 |
* the Free Software Foundation, Inc., 51 Franklin Street, |
|
| 20 |
* Boston, MA 02110-1301, USA. |
|
| 21 |
*/ |
|
| 22 | ||
| 23 |
// @WARNING@ |
|
| 24 | ||
| 25 |
#ifdef HAVE_CONFIG_H |
|
| 26 |
#include "config.h" |
|
| 27 |
#endif |
|
| 28 | ||
| 29 |
#include <@NAME@.h> |
|
| 30 |
#include <gr_io_signature.h> |
|
| 31 |
#include <vector> |
|
| 32 | ||
| 33 |
@SPTR_NAME@ |
|
| 34 |
gr_make_@BASE_NAME@ (int length, int vlen, @O_TYPE@ scale, int max_iter) |
|
| 35 |
{
|
|
| 36 |
return @SPTR_NAME@ (new @NAME@ (length, vlen, scale, max_iter)); |
|
| 37 |
} |
|
| 38 | ||
| 39 |
@NAME@::@NAME@ (int length, int vlen, @O_TYPE@ scale, int max_iter) |
|
| 40 |
: gr_sync_block ("@BASE_NAME@",
|
|
| 41 |
gr_make_io_signature (1, 1, sizeof (@I_TYPE@) * vlen), |
|
| 42 |
gr_make_io_signature (1, 1, sizeof (@O_TYPE@) * vlen)), |
|
| 43 |
d_length(length), |
|
| 44 |
d_vlen(vlen), |
|
| 45 |
d_scale(scale), |
|
| 46 |
d_max_iter(max_iter) |
|
| 47 |
{
|
|
| 48 |
set_history(length); |
|
| 49 |
} |
|
| 50 | ||
| 51 |
@NAME@::~@NAME@ () |
|
| 52 |
{
|
|
| 53 |
} |
|
| 54 | ||
| 55 |
int |
|
| 56 |
@NAME@::work (int noutput_items, |
|
| 57 |
gr_vector_const_void_star &input_items, |
|
| 58 |
gr_vector_void_star &output_items) |
|
| 59 |
{
|
|
| 60 |
const @I_TYPE@ *in = (const @I_TYPE@ *) input_items[0]; |
|
| 61 |
@O_TYPE@ *out = (@O_TYPE@ *) output_items[0]; |
|
| 62 | ||
| 63 |
std::vector<@I_TYPE@> sum(d_vlen, 0); |
|
| 64 |
int num_iter = (noutput_items>d_max_iter) ? d_max_iter : noutput_items; |
|
| 65 | ||
| 66 |
for (int i = 0; i < d_length-1 ; i++) {
|
|
| 67 |
const @I_TYPE@ *in_vec = &in[i * d_vlen]; |
|
| 68 |
for (int k = 0; k < d_vlen; k++) {
|
|
| 69 |
sum[k] += in_vec[k]; |
|
| 70 |
} |
|
| 71 |
} |
|
| 72 | ||
| 73 |
for (int i = 0; i < num_iter; i++) {
|
|
| 74 |
const @I_TYPE@ *in_vec_old = &in[i * d_vlen]; |
|
| 75 |
const @I_TYPE@ *in_vec_new = &in[(i+d_length-1) * d_vlen]; |
|
| 76 |
@O_TYPE@ *out_vec = &out[i * d_vlen]; |
|
| 77 |
for (int k = 0; k < d_vlen; k++) {
|
|
| 78 |
sum[k] += in_vec_new[k]; |
|
| 79 |
out_vec[k] = sum[k] * d_scale; |
|
| 80 |
sum[k] -= in_vec_old[k]; |
|
| 81 |
} |
|
| 82 |
} |
|
| 83 | ||
| 84 |
return num_iter; |
|
| 85 |
} |
|
| gnuradio-core/src/lib/gengen/Makefile.gen (working copy) | ||
|---|---|---|
| 46 | 46 |
gr_moving_average_ff.h \ |
| 47 | 47 |
gr_moving_average_ii.h \ |
| 48 | 48 |
gr_moving_average_ss.h \ |
| 49 |
gr_moving_average_vcc.h \ |
|
| 50 |
gr_moving_average_vff.h \ |
|
| 51 |
gr_moving_average_vii.h \ |
|
| 52 |
gr_moving_average_vss.h \ |
|
| 49 | 53 |
gr_multiply_cc.h \ |
| 50 | 54 |
gr_multiply_const_cc.h \ |
| 51 | 55 |
gr_multiply_const_ff.h \ |
| ... | ... | |
| 156 | 160 |
gr_moving_average_ff.i \ |
| 157 | 161 |
gr_moving_average_ii.i \ |
| 158 | 162 |
gr_moving_average_ss.i \ |
| 163 |
gr_moving_average_vcc.i \ |
|
| 164 |
gr_moving_average_vff.i \ |
|
| 165 |
gr_moving_average_vii.i \ |
|
| 166 |
gr_moving_average_vss.i \ |
|
| 159 | 167 |
gr_multiply_cc.i \ |
| 160 | 168 |
gr_multiply_const_cc.i \ |
| 161 | 169 |
gr_multiply_const_ff.i \ |
| ... | ... | |
| 266 | 274 |
gr_moving_average_ff.cc \ |
| 267 | 275 |
gr_moving_average_ii.cc \ |
| 268 | 276 |
gr_moving_average_ss.cc \ |
| 277 |
gr_moving_average_vcc.cc \ |
|
| 278 |
gr_moving_average_vff.cc \ |
|
| 279 |
gr_moving_average_vii.cc \ |
|
| 280 |
gr_moving_average_vss.cc \ |
|
| 269 | 281 |
gr_multiply_cc.cc \ |
| 270 | 282 |
gr_multiply_const_cc.cc \ |
| 271 | 283 |
gr_multiply_const_ff.cc \ |
| gnuradio-core/src/lib/gengen/gr_moving_average_vXX.h.t (revision 0) | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2008 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 3, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License |
|
| 18 |
* along with GNU Radio; see the file COPYING. If not, write to |
|
| 19 |
* the Free Software Foundation, Inc., 51 Franklin Street, |
|
| 20 |
* Boston, MA 02110-1301, USA. |
|
| 21 |
*/ |
|
| 22 | ||
| 23 |
// @WARNING@ |
|
| 24 | ||
| 25 |
#ifndef @GUARD_NAME@ |
|
| 26 |
#define @GUARD_NAME@ |
|
| 27 | ||
| 28 |
#include <gr_sync_block.h> |
|
| 29 | ||
| 30 |
class @NAME@; |
|
| 31 | ||
| 32 |
typedef boost::shared_ptr<@NAME@> @SPTR_NAME@; |
|
| 33 | ||
| 34 |
@SPTR_NAME@ gr_make_@BASE_NAME@ (int length, int vlen, @O_TYPE@ scale, int max_iter = 4096); |
|
| 35 | ||
| 36 |
/*! |
|
| 37 |
* \brief output is the moving sum of the last N samples, scaled by the \p scale factor. |
|
| 38 |
* |
|
| 39 |
* The moving average of the vectors is calculated per element. |
|
| 40 |
* |
|
| 41 |
* \p max_iter limits how long we go without flushing the accumulator. This is necessary |
|
| 42 |
* to avoid numerical instability for float and complex. |
|
| 43 |
* |
|
| 44 |
* \ingroup filter |
|
| 45 |
*/ |
|
| 46 |
class @NAME@ : public gr_sync_block |
|
| 47 |
{
|
|
| 48 |
private: |
|
| 49 |
friend @SPTR_NAME@ gr_make_@BASE_NAME@(int length, int vlen, @O_TYPE@ scale, int max_iter); |
|
| 50 | ||
| 51 |
@NAME@ (int length, int vlen, @O_TYPE@ scale, int max_iter = 4096); |
|
| 52 | ||
| 53 |
int d_length; |
|
| 54 |
int d_vlen; |
|
| 55 |
@O_TYPE@ d_scale; |
|
| 56 |
int d_max_iter; |
|
| 57 | ||
| 58 |
public: |
|
| 59 |
~@NAME@ (); |
|
| 60 | ||
| 61 |
int work (int noutput_items, |
|
| 62 |
gr_vector_const_void_star &input_items, |
|
| 63 |
gr_vector_void_star &output_items); |
|
| 64 |
}; |
|
| 65 | ||
| 66 |
#endif /* @GUARD_NAME@ */ |
|
| gnuradio-core/src/lib/gengen/generate_common.py (working copy) | ||
|---|---|---|
| 53 | 53 |
'gr_multiply_const_vXX', |
| 54 | 54 |
'gr_integrate_XX', |
| 55 | 55 |
'gr_moving_average_XX', |
| 56 |
'gr_moving_average_vXX' |
|
| 56 | 57 |
] |
| 57 | 58 | |
| 58 | 59 |
# other blocks |
| gnuradio-core/src/lib/gengen/Makefile.am (working copy) | ||
|---|---|---|
| 115 | 115 |
gr_not_XX.i.t \ |
| 116 | 116 |
gr_moving_average_XX.cc.t \ |
| 117 | 117 |
gr_moving_average_XX.h.t \ |
| 118 |
gr_moving_average_XX.i.t |
|
| 118 |
gr_moving_average_XX.i.t \ |
|
| 119 |
gr_moving_average_vXX.cc.t \ |
|
| 120 |
gr_moving_average_vXX.h.t \ |
|
| 121 |
gr_moving_average_vXX.i.t |
|
| 119 | 122 | |
| 120 | 123 |
include Makefile.gen |
| 121 | 124 | |