How history() works in GR

Hello

I am trying to define a customised block and I would like to understand
better how the history works.

I have opened the source of gr_moving_average_XX and I saw the following
statement in the constructor:

@NAME@::@NAME@ (int length, @O_TYPE@ scale, int max_iter)
: gr_sync_block (“@BASE_NAME@”,
gr_make_io_signature (1, 1, sizeof (@I_TYPE@)),
gr_make_io_signature (1, 1, sizeof (@O_TYPE@))),
d_length(length),
d_scale(scale),
d_max_iter(max_iter),
d_new_length(length),
d_new_scale(scale),
d_updated(false)
{
set_history(length);
}

So it seems to me that GR allocates a history buffer with “length” size.
But, later in the gr_moving_average_XX code I see the following cycle:

for (int i = 0; i < num_iter; i++) {
sum += in[i+d_length-1];
out[i] = sum * d_scale;
sum -= in[i];
}

…which seems to show that there is at least a buffering of “length +
num_iter” input items somewhere, and num_iter
is >0 for sure.
This has confused me a bit on how history is implemented.

Thanks for any explanation.

Alberto

Supera i limiti: raddoppia la velocità da 10 a 20 Mega! Risparmia con
Tutto Incluso: telefono + adsl 20 mega a soli 29,95 € al mese per due
anni!SCONTO DI 240
EURO!http://abbonati.tiscali.it/telefono-adsl/prodotti/tc/tuttoincluso/?WT.mc_id=01fw

On Mon, Feb 28, 2011 at 02:24:29PM +0100, Alberto T. wrote:

d_length(length),
But, later in the gr_moving_average_XX code I see the following cycle:

for (int i = 0; i < num_iter; i++) {
sum += in[i+d_length-1];
out[i] = sum * d_scale;
sum -= in[i];
}

…which seems to show that there is at least a buffering of “length + num_iter”
input items somewhere, and num_iter
is >0 for sure.
This has confused me a bit on how history is implemented.

Hi Alberto,

ignore the max_iter variable–it is for numerical stability and has
nothing to do with the history. Perhaps you should check other blocks
for examples.

If you set the history to ‘N’, this means you always have the last (N-1)
input values kept in your buffer. Take an FIR filter as example: Say it
has order N. Then you need the current sample plus the previous (N-1)
samples to calculate your output sample. So, you set history to N.

Some more notes on history():

  • The first N-1 input values are set to zero
  • The buffer input_items points to the oldest sample. Thus, if you have
    M input_items, the total buffer length (i.e. the max index) is N+M-1.

Hope this helps…
Cheers
MB

[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