How to use forecast()?

Hello everybody,

I’m working on building a block that accepts many inputs (say n) and has
one
output. For a single output item to be generated, 100 samples from each
input port should be taken. How can I use forecast() and general_work()
to
serve my purpose? I read somewhere that we never call or modify the
parameters explicitly, the scheduler does this instead. But how does the
scheduler know that I need 100 samples exactly.

Any help is highly appreciated.

View this message in context:
http://old.nabble.com/How-to-use-forecast()--tp28705301p28705301.html
Sent from the GnuRadio mailing list archive at Nabble.com.

On Sun, May 30, 2010 at 01:33:17PM -0700, Zohair wrote:

Any help is highly appreciated.
No need to use general_work or forecast.

Derive from gr_sync_decimator. There are many examples in
gnuradio-core/src/lib/general.

Eric

if you still wanna use forecast and general_work then this is how you do
it

void your_block::forecast(int noutput_items,gr_vector_int
&ninput_items_required){

ninput_items_required[0]=100 * noutput_items;
ninput_items_required[1]=100 * noutput_items;

}

the scheduler will choose the number for noutput_items and it will make
sure
that you have the required items on your input streams by calling
forecast.
Suppose your output items are a multiple of a specific item e.g. if you
always want 100 items produced each time your general_work() is called
then
you have to tell the scheduler that the noutput_items must be a multiple
of
100. Call set_output_miltiple() to let the scheduler know this. This is
how
it’s done,

dsss_spreading_b::dsss_spreading_b(unsigned int
length_PN):gr_block(“spreading_b”,
gr_make_io_signature(2,2,sizeof(unsigned char)),
gr_make_io_signature(1,1,sizeof(unsigned char))),
d_length_PN(length_PN)
{
set_output_multiple(d_length_PN);
}

for example the above constructor shows a block that has 2 input streams
and
one output stream and it calls set_output_multilple which has an integer
parameter d_length_PN passed. The scheduler will make sure that the
noutput_items that it selects will be a multiple of d_length_PN…

if d_length_PN=100 …then scheduler will choose n*100 output_items …
where n in an integer.

Look into the examples or the blocks in the gnuradio. Read the comments
in
gr_block.h file. This will give you all the information.

Good luck.

Eric and Mir,
Thanks for the important infomation provided. I will try both of them
and
reply to you.

Zohair

View this message in context:
http://old.nabble.com/How-to-use-forecast()--tp28705301p28728321.html
Sent from the GnuRadio mailing list archive at Nabble.com.

Hi Eric,
I have a similar issue as the one described above and I have read some
of
the examples in the directory provided but they seem to be different
from
what I want to implement. I want to collect L samples from N channels
and
store them in a buffer, do processing and output a vector of length N. I
wrote the following code but it doesn’t seem to be working properly.
Some of
them use loops from i=0 to noutput_items*vlen while others use from 0 to
noutput_items. Also some of them don’t use the function memcpy.

I am using gr_sync_decimator with set_decimation(L) is written in the
block
constructor.

int my_package::work(…) {

        gr_complexd *out =(gr_complexd *) output_items[0];
        const gr_complex *in[N];

        for (unsigned int i = 0; i<N; i++)
            in[i] = (const gr_complex *) input_items[i];

        for (int i = 0; i <noutput_items; i++){
            for(unsigned int k=0; k<N; k++)
   memcpy(&inbuffer[k][0],&in[k][i*L],L*sizeof(gr_complex)); 

//inbuffer is
NxL matrix

            //Signal processing of inbuffer and storing the result 

in a
vector
// out_vector of length vect_lengx;

            memcpy(out, &out_vector.at(0),

vect_lengx*sizeof(gr_complexd));
out+=vect_lengx;

        }//end for

return noutput_items;

}

Can you help me with this please?

Thanks a lot.

Sammour

View this message in context:
http://old.nabble.com/How-to-use-forecast()--tp28705301p29356450.html
Sent from the GnuRadio mailing list archive at Nabble.com.

This is my block’s constructor:

my_package::my_package(int num_input_ports, int L_samples)
: gr_sync_decimator(
“package”,

    gr_make_io_signature(2, 5, sizeof(gr_complex)),

    gr_make_io_signature(1, 1 , 

num_input_portsnum_input_portssizeof(gr_complexd)),

    L_samples) {


// global variables
N=num_input_ports;

vect_lengx=N*N;

L=L_samples;

set_decimation(L);

}

Best regards,

Sam

On Sat, Aug 07, 2010 at 01:07:20AM +0100, Samy S. wrote:

set_decimation(L);    

}

This should probably be:

my_package::my_package(int num_input_ports, int L_samples)
: gr_sync_decimator(
“package”,
gr_make_io_signature(num_input_ports, num_input_ports,
sizeof(gr_complex)),
gr_make_io_signature(1, 1 ,
num_input_portsnum_input_portssizeof(gr_complexd)),
L_samples) {

 // global variables
 N=num_input_ports;

 // Is this is the length of the output vector?
 vect_lengx=N*N;

 L=L_samples;

 // No need to call this.  You passed it to gr_sync_decimator's 

constructor
//set_decimation(L);
}

More below…

On Fri, Aug 06, 2010 at 06:32:32AM -0700, Sammour wrote:

Hi Eric,
I have a similar issue as the one described above and I have read some of
the examples in the directory provided but they seem to be different from
what I want to implement. I want to collect L samples from N channels and
store them in a buffer, do processing and output a vector of
length N.

N or NN? I’m assuming it’s NN given what you’ve said above.

I wrote the following code but it doesn’t seem to be working properly. Some of
them use loops from i=0 to noutput_items*vlen while others use from 0 to
noutput_items. Also some of them don’t use the function memcpy.

I am using gr_sync_decimator with set_decimation(L) is written in the block
constructor.

int my_package::work(…)
{
gr_complexd *out =(gr_complexd *) output_items[0];

for (int i = 0; i <noutput_items; i++){
gr_complex inbuffer[N][L]; // temp buffer for input matrix

for(unsigned int k=0; k<N; k++)
  memcpy(&inbuffer[k][0],
   ((const gr_complex *)input_items[k])[i*L],
   L*sizeof(gr_complex));   //inbuffer is NxL matrix

// Call signal processing code,
// have it write N*N gr_complexd's directly into output buffer
sig_proc(inbuffer, out);

out += N*N;

}

return noutput_items;
}

On Fri, Aug 06, 2010 at 06:32:32AM -0700, Sammour wrote:

I am using gr_sync_decimator with set_decimation(L) is written in the block
constructor.

gr_sync_decimator with decimation == L correct, given what you’ve
described.

Can you please show the beginning of your constructor, where you pass
the
arguments to gr_sync_decimator’s constructor?

Eric