A question about general_work() function

Hello Everyone

I have got a problem which arised from my project. Here is what I want
to
do: I am trying to implement a Viterbi algorithm. Suppose “in” is the
input
stream, I want to use in[0], in[1]…in[6], seven elements to
initialize
the Viterbi algorithm. Then from in[7], I start to use Viterbi algorithm
to
do tracking. Now the problem comes, in the “general_work()” function, I
did
something like this:

int general_work(arg1, arg2, arg3, arg4) {
for (int i = 0; i < 7; i++) {
use in[i] to intialize the Viterbi algorithm;
}
for (int i = 8; i < ninput_terms; i++) {
use each in[i] to do Viterbi algorithm tracking;
out[n] = something
}
}

However, the results told me this is a wrong way. Because the
initialization
part (the for i=0, i<7, i++ part) would be executed for many many times.
It
appeared to me that the scheduler would try to call the general_work
function for many times and each time it calls it, everything in the
function would be executed from the beginning to the end. For example,
if I
write a line

printf(“can you see me?\n”);

and put it in front of the first ‘for’ iteration, I can see the printed
output many times. This thing totally disturbed what I wish to do. Am I
understood?

Could anyone provide any help or insights? Thanks in advance.

Best Regards
Dawei

Are you sure you get enough input items for the general_work? try to
print ninput_items and see what the result is. It might be that you
get always less than the 7 items you need to initialize the algorithm.

Thomas

It varies from time to time, but I am pretty sure it’s larger than 7.
It’s
at least 100. Dawei

Hi,
I dont know how the Viterbi algorithm works, but do you want to (a)
initialize the first 7 samples for only the first chunk of samples you
get, or (b) for every chunk of samples you get? What you have
implemented is option (b), and it seems only natural that the
initialization code would be called multiple times.

If you’re looking for option (a) you would need a flag that you set
the first time general_work is called. This flag state must persist
across multiple calls to general_work, so it would be a member
variable of your signal processing block.

class my_block : public gr_block
{
private:
long d_init;

};

//ctor
my_block::my_block (…) : gr_block (“my_block”, …)
{
d_init = 0;

}

my_block::general_work(…)
{
if( !d_init )
{
for (int i = 0; i < 7; i++) {
use in[i] to intialize the Viterbi algorithm;
}
for (int i = 7; i < ninput_terms; i++) {
use each in[i] to do Viterbi algorithm tracking;
out[n] = something
}
d_init = 1;
}
else
{
for (int i = 0; i < ninput_terms; i++) {
use each in[i] to do Viterbi algorithm tracking;
out[n] = something
}
}
}

From what I have read about the Viterbi algorithm, I am assuming this
algorithm is to be initialized only once, or at least once per
transmission, which means you are looking for option (a) (or a more
complex variation thereof.)

Kunal

On Tue, Oct 10, 2006 at 09:26:35AM -0700, Thomas S. wrote:

Are you sure you get enough input items for the general_work? try to
print ninput_items and see what the result is. It might be that you
get always less than the 7 items you need to initialize the algorithm.

Thomas

Also, why do you think you should be using general_work instead of
work?

Eric

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs