Friday, October 12, 2012

Understanding a Singal Processing Block in GNU Radio : d_output_multiple & d_relative_rate

Now we know that the GNU Radio scheduler is responsible for invoking general_work() and forecast() functions

The forecast() function allows us to signal to the scheduler to invoke our general_work() only when a sufficient number input elements are in the input buffer

Till now we haven't seen any such mechanism to control the number of outputs being produced

the argument noutput_items in the forecast() function, which is specified by the scheduler, contains the number of output items on each of the output stream

We cannot directly set this value as it is under the scheduler's control but there is a variable d_output_multiple which tells the scheduler that the value of noutput_items must be an integer multiple of d_output_multiple

In other words the scheduler only invokes forecast() and general_work() when noutput_items is an integer multiple of d_output_multiple

default value of d_output_multiple is 1

Say we want to generate outputs only in a 64 elements chunk, by setting d_output_multiple to 64 we can achieve this, but note that we can also get multiples of 64 i.e. 128, 256 etc

The to set the value of d_output_multiple we have set_output_multiple() function the definition of which can be found in gnuradio/gnuradio-core/src/lib/runtime as follows :

gr_block::set_output_multiple (int multiple)
  if (multiple < 1)
    throw std::invalid_argument ("gr_block::set_output_multiple");

  d_output_multiple_set = true;
  d_output_multiple = multiple;

There is always 2 way communication with the scheduler. The d_relative_rate is the way we tell the scheduler the approximate ratio of the output rate to the input rate at which we expect our signal processing algorithm to operate.

The key purpose of the d_relative_rate is to allow the scheduler ti optimize its use memory and timings of invocation of general_work()

For many blocks the value of d_relative_rate is 1 but for decimators it is less than 1 and for interpolators it is  greater than 1

The function definition used to set the value of d_relative_rate can be found in as follows :

gr_block::set_relative_rate (double relative_rate)
  if (relative_rate < 0.0)
    throw std::invalid_argument ("gr_block::set_relative_rate");

  d_relative_rate = relative_rate;

Reference :

No comments:

Post a Comment