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.
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,
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.
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
// 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;