Gnuradio c++ code structure question

Hi everyone,

I am trying to develop a frame based structure for gnuradio block on
c++.
The frame size will be 2048 point and i will calculate the normalized
amplitude for every frame i.e.

ma = sum(every 2048 points)/2048;
normalized amplitude = all 2048 points / ma;

i wrote a code that gives me the desired result under “work” function;

int
gr_gama_maks_ff::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];
float ma = 0.0;
float acn[noutput_items], an[noutput_items];
int C = 2048;
int a = 0;
int count = 0;

for (int i = 0; i < noutput_items; i++){
ma = 0.0;
for (int m = aC; m < aC+C ; m++) {
ma += in[m]/C;
}

an[i] = in[i]/ma;
acn[i] = an[i]-1;
out[i] = acn[i]*d_k;

if ((i+1) % C == 0) {
a = a + 1;
}
}

As you see i didn’t keep a 2048 point array, i just find the sum of
2048 points and then use it for the output (an[i]= in[i]/ma). But i
couldn’t figure out how this happens. I mean the while index “i = 1”
in the first for loop, i can reach the i+2047th sample in the second
for loop.

Is there a buffer for every block in gnuradio. If yes what is the size
of the buffer?

I hope i would explain it clear.

Mehmet.

Hi Mehmet,

you’ve omitted some crucial parts of your code.
I’m guessing you’ve made your block a gr_sync_block.

It’s easiest if your input items are vectors. In that case, your input
buffer (input_items) will contain noutput_items * 2048 float values.
Then, just process your data on whole blocks.

The operation you describe seems pretty simple. You can probably set it
up with a couple of existing blocks without having to write any code at
all, although your method is surely more efficient (in terms of CPU
load, not development time).

MB

On Mon, Mar 07, 2011 at 03:56:04PM +0200, mehmet kabasakal wrote:

float acn[noutput_items], an[noutput_items];
an[i] = in[i]/ma;
As you see i didn’t keep a 2048 point array, i just find the sum of
Mehmet.


Discuss-gnuradio mailing list
[email protected]
Discuss-gnuradio Info Page


Karlsruhe Institute of Technology (KIT)
Communications Engineering Lab (CEL)

Dipl.-Ing. Martin B.
Research Associate

Kaiserstraße 12
Building 05.01
76131 Karlsruhe

Phone: +49 721 608-43790
Fax: +49 721 608-46071
www.cel.kit.edu

KIT – University of the State of Baden-Württemberg and
National Laboratory of the Helmholtz Association

Hi Martin,

As you guess, i use gr_sync_block.
But i don’t use vector input items, i mean the input of the block is
streaming points.
Do i still have noutput_items * 2048 buffer size?

Mehmet.

2011/3/7, Martin B. [email protected]: