Discussion in 'C Programming' started by ranjeet, Jan 12, 2005.

1. ### ranjeetGuest

Dear All

I want your suggestion on below implementation so that i can have the most
optimised solution for the below

Lets assume I have the data to encode at the transmitter and decode at the
reciver.

suppose we have high range of data varing from -infity to + infinity

what i decide is that i take the certain range of the above and do the
encoding into the 5 bit.

like the below operation :

00000 -12
00001 -4
00010 0
00011 4
00100 8
00101 12
00110 16
00111 18
01000 20
01001 22
01010 24
01011 26
01100 28
01101 30
01110 32
01111 34
10000 36
10001 38
10010 40
10011 42
10100 44
10101 46
10110 48
10111 50
11000 52
11001 54
11010 56
11011 58
11100 60
11101 62
11110 64
11111 66

the value all below -12 will be taken as 000000
the value all belo -4 will be take as 00001

and so on.........

Now my question is that how to implement this in best fashion????
keeping in all the computation and the memory used into the
system.

My approach that I will enocde the data simple by checking the
values (if it lies with in the range then I will take the above
corresponding Index.)

then I will search the same index (at the decoder end) by making the
look up table in which i will search the corresponding index and
get the data from it.

means if i get the index ( 00101) means 5 then i will
decode this index as the 12.

Now Is this the correct way or what are the issue I have to consider
while facing such problem ( that wheather we have to maintain the
table or just put the values into the memeory and make the search)

Which search algo is the best one while searching the above index values
in the above case. ??

Regards
Ranjeet

ranjeet, Jan 12, 2005

2. ### -berlin.deGuest

ranjeet <> wrote:
> I want your suggestion on below implementation so that i can have the most
> optimised solution for the below

That's question about an algorithm, not one about C. It would be on-
topic e.g. in comp.programming but not here.

<OT>
> Lets assume I have the data to encode at the transmitter and decode at the
> reciver.
> suppose we have high range of data varing from -infity to + infinity

Then you're going to have problems using a computer;-)

> what i decide is that i take the certain range of the above and do the
> encoding into the 5 bit.
> like the below operation :

> 00000 -12
> 00001 -4
> 00010 0
> 00011 4
> 00100 8

....
> 11011 58
> 11100 60
> 11101 62
> 11110 64
> 11111 66

> the value all below -12 will be taken as 000000
> the value all belo -4 will be take as 00001

Using a look-up table is probably the fastest solution and with that
range of data memory consumption normally shouldn't be an issue.

static unsigned char encode_table[ 79 ] = { 1, 1, ...};

unsigned char encode( long int data ) {
if ( ( data += 13 ) < 0 )
return 0;
else if ( data >= 79 )
return 31;
return encode_table[ data ];
}

static long int decode_table[ 32 ] = { -12, -4,... };

long int decode( unsigned char encoded_data ) {
return decode_table[ encoded_data ];
}

Setting up the look-up tables is left as an exercise to the reader;-)

> Now Is this the correct way or what are the issue I have to consider
> while facing such problem ( that wheather we have to maintain the
> table or just put the values into the memeory and make the search)

That sentence doesn't seem to make sense. The table is going to be in
memory and I have no idea what kind of "search" you're talking above.
</OT>
Regards, Jens
--
\ Jens Thoms Toerring ___ -berlin.de
\__________________________ http://www.toerring.de

-berlin.de, Jan 12, 2005

3. ### Ben MidgleyGuest

"ranjeet" <> wrote in message
news:...
> Dear All
>
> I want your suggestion on below implementation so that i can have the

most
> optimised solution for the below
>
> Lets assume I have the data to encode at the transmitter and decode at

the
> reciver.
>
> suppose we have high range of data varing from -infity to + infinity
>
> what i decide is that i take the certain range of the above and do the
> encoding into the 5 bit.
>
> like the below operation :
>
> 00000 -12
> 00001 -4
> 00010 0
> 00011 4
> 00100 8
> 00101 12
> 00110 16
> 00111 18
> 01000 20
> 01001 22
> 01010 24
> 01011 26
> 01100 28
> 01101 30
> 01110 32
> 01111 34
> 10000 36
> 10001 38
> 10010 40
> 10011 42
> 10100 44
> 10101 46
> 10110 48
> 10111 50
> 11000 52
> 11001 54
> 11010 56
> 11011 58
> 11100 60
> 11101 62
> 11110 64
> 11111 66
>
> the value all below -12 will be taken as 000000
> the value all belo -4 will be take as 00001
>
> and so on.........
>
> Now my question is that how to implement this in best fashion????
> keeping in all the computation and the memory used into the
> system.
>
> My approach that I will enocde the data simple by checking the
> values (if it lies with in the range then I will take the above
> corresponding Index.)
>
> then I will search the same index (at the decoder end) by making the
> look up table in which i will search the corresponding index and
> get the data from it.
>
> means if i get the index ( 00101) means 5 then i will
> decode this index as the 12.
>
> Now Is this the correct way or what are the issue I have to consider
> while facing such problem ( that wheather we have to maintain the
> table or just put the values into the memeory and make the search)
>
> Which search algo is the best one while searching the above index values
> in the above case. ??
>

There are many studies for to search efficiency, to the best of my
understanding : if your dataset really is huge "suppose we have high range
of data varing from -infity to + infinity" then binary search is the only
way to travel, but this does mean you will need a sorted list, sorted by
data at the transmit side and sorted by encoded data at the recieve side. If
your data set is smaller, such as the sample size you have provided then the
overhead of binary searches are not worth the effort. The other issue is
that if your data set is massive then you need to look at the memory usage,
everything is quicker in RAM but you cant necessarily load it all into RAM.

If you have a clear idea of how large your data set is then this will
determin the search required, unless of course you can establish a
relationship between data and encoded data which can be described by an
expression....

> Regards
> Ranjeet

Ben Midgley, Jan 12, 2005