discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Discuss-gnuradio] Need help to understand code of sync:decimator block


From: kunal sankhe
Subject: [Discuss-gnuradio] Need help to understand code of sync:decimator block
Date: Sat, 8 Mar 2014 13:19:24 +0530

Hello,


I am using GNU Radio version 3.6.5 and trying to write a block to calculate average of 5 samples. I want to produce one average output corresponding to 5 input samples. I am using set_history(5) to remember previous data. I used gr_modtool script of type decimator to create file.

eg. for Vector source {1,2,3,4,5,6,7,8,9,10}, it should generate average {3,8}. Instead I am getting {.2, .6}.

My requirement is to produce output, it should take 5 inputs. Please suggest me where I need to do modification.

In function gr_sync_decimator("average",
              gr_make_io_signature(1, 1, sizeof(float)),
              gr_make_io_signature(1, 1, sizeof(float)), 5)

what role value 5 will play?


Below is code snapshot.


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <gr_io_signature.h>
#include "average_impl.h"

namespace gr {
  namespace howto {

    average::sptr
    average::make()
    {
      return gnuradio::get_initial_sptr
        (new average_impl());
    }

    /*
     * The private constructor
     */
    average_impl::average_impl()
      : gr_sync_decimator("average",
              gr_make_io_signature(1, 1, sizeof(float)),
              gr_make_io_signature(1, 1, sizeof(float)), 5)
    {
    set_history(5);
    }

    /*
     * Our virtual destructor.
     */
    average_impl::~average_impl()
    {
    }

    int
    average_impl::work(int noutput_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];
    in +=4;   
  
    for(int i=0; i<noutput_items; i++){
    out[i]=(in[i]+in[i-1]+in[i-2]+in[i-3]+in[i-4])/5;
    }
      
        return noutput_items;
    }

  } /* namespace howto */
} /* namespace gr */



Thanks and regards,
Kunal Sankhe

reply via email to

[Prev in Thread] Current Thread [Next in Thread]