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.
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.