Thanks, but I'm trying to get weighted average specifically. I've looked at
the code for moving_average... it's close to what I need, but its 1:1 in/out
ratio, but I need N:1 ratio. That's the part I'm particular unclear about.

On Sat, Mar 28, 2009 at 9:27 AM, Karthik <karthik1...@gmail.com> wrote:

> 2009/3/27 Mikhail Tadjikov <mtadji...@ucla.edu>
>
> Hello,
>>
>>  I'm trying to build several signal processing blocks for a project that
>> I'm doing using USRP2.  I was going through the examples and sample code
>> along with browsing the source code and I can't seem to find exactly what I
>> need. I'm trying to do an average of a vector of length N:
>>
>> Input vector size N
>> Output vector size 1
>> I'm doing it for floats.
>>
>> ------------------------------
>> #ifndef INCLUDED_CORES_WEIGHTED_AVG_FF_H
>> #define INCLUDED_CORES_WEIGHTED_AVG_FF_H
>> #include <gr_sync_block.h>
>> class cores_weighted_avg_ff;
>>
>> typedef boost::shared_ptr<cores_weighted_avg_ff>
>> cores_weighted_avg_ff_sptr;
>> cores_weighted_avg_ff_sptr cores_make_weighted_avg_ff (unsigned int vlen);
>>
>> class cores_weighted_avg_ff : public gr_sync_block
>> {
>> private:
>>    friend cores_weighted_avg_ff_sptr cores_make_weighted_avg_ff (unsigned
>> int vlen);
>>   cores_weighted_avg_ff (unsigned int vlen);      // private constructor
>>   unsigned int d_vlen;
>>
>>  public:
>>   int general_work (int noutput_items,
>>                         gr_vector_int &ninput_items,
>>                         gr_vector_const_void_star &input_items,
>>                         gr_vector_void_star &output_items);
>> };
>> #endif
>>
>> ----------------------------------------------------------------------------------------------------------
>> and source
>>
>> -------------------------------------------------------------------------------------------
>> #ifdef HAVE_CONFIG_H
>> #include "config.h"
>> #endif
>> #include <cores_weighted_avg_ff.h>
>> #include <gr_io_signature.h>
>>
>> cores_weighted_avg_ff_sptr
>> cores_make_weighted_avg_ff (unsigned int vlen)
>> {  return cores_weighted_avg_ff_sptr (new cores_weighted_avg_ff (vlen));}
>>
>> cores_weighted_avg_ff::cores_weighted_avg_ff (unsigned int vlen)
>>   : gr_decimator_block ("weighed_avg_ff",
>>                    gr_make_io_signature (1, 1, sizeof (float) * vlen),
>>                    gr_make_io_signature (1, 1, sizeof (float))),
>>     d_vlen(vlen)
>> {
>> }
>> int
>> cores_weighted_avg_ff::int general_work (int noutput_items,
>>                         gr_vector_int &ninput_items,
>>                         gr_vector_const_void_star &input_items,
>>                         gr_vector_void_star &output_items);
>> {
>>       const float *in = (const float *) input_items[0];
>>       float *out = (float *) output_items[0];
>>       int noi = noutput_items * d_vlen;
>>
>>       for (int i = 0; i < noi; i++){
>>         out += in[i]*i;
>>       }
>>       out /= d_vlen;
>>       consume(noutput_items,d_vlen)
>>
>>       return noutput_items;
>> }
>>
>> ------------------------------------------------------------------------------------------------
>>
>> I'm not sure if the code is correct what I want to do (input is more than
>> welcome), when I compile this code I get a weird error:
>> cores_weighted_avg_ff.h: In function ‘PyObject*
>> _wrap_weighted_avg_ff(PyObject*, PyObject*)’:
>> cores_weighted_avg_ff.h:63: error: too few arguments to function
>> ‘cores_weighted_avg_ff_sptr cores_make_weighted_avg_ff(unsigned int)’
>> cores.cc:4326: error: at this point in file
>> make[4]: *** [cores.lo] Error 1
>>
>> Any help would be greatly appreciated.
>
>
> With gr_sync_block you only need to write work() and not general_work().
> The example at the end of this tutorial will be helpful
> http://www.gnu.org/software/gnuradio/doc/howto-write-a-block.html. Also,
> there is a "#endif" sitting in the middle of your code, it might be a typo.
>
> btw, if you are trying to get moving averages, there is a block already
> available gr_moving_averages()
>
> Karthik
>
>
>


-- 
Mikhail Tadjikov
Graduate Student
UCLA Department of
Electrical Engineering
_______________________________________________
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
http://lists.gnu.org/mailman/listinfo/discuss-gnuradio

Reply via email to