DSPRelated.com
Forums

How to Convert 8-bit data to 10-bit data?

Started by Unknown May 12, 2005
Hi,

I have the following question.

How to convert an 8-bit data to 10-bit data ?

The following C program uses 8-bit data. (Basically FIR filter)

/*********************************************************/
#define MAX 6
typedef unsigned char uint_8


uint_8 fir()
{

   uint_8 buffer[MAX], out;

   out =( (buffer[0] + buffer[5]) +
          ((buffer[1] + buffer[4]) * 2) +
          ((buffer[2] + buffer[3]) * 3 )
         ) / 16

   return out;

}

/*********************************************************/


The whole program needs to be converted to 10-bit data.
Pls let me know how to do it....

Thanks
Sandeep

Hi,

Pls use signed char in the above program

i.e., typedef signed char t_int8

use t_int8 in place of uint_8....

SORRY FOR THE CONFUSION.

Thanks
Sandeep

sandeep_mc81@yahoo.com wrote:
> > Hi, > > Pls use signed char in the above program > > i.e., typedef signed char t_int8 > > use t_int8 in place of uint_8.... > > SORRY FOR THE CONFUSION.
Your function appears to return a value calculated from the bytes of an uninitialized array. What is it really supposed to do? comp.lang.c doesn't know what an FIR filter is. -- pete
sandeep_mc81@yahoo.com writes:

> Hi, > > I have the following question. > > How to convert an 8-bit data to 10-bit data ? > > The following C program uses 8-bit data. (Basically FIR filter) > > /*********************************************************/ > #define MAX 6 > typedef unsigned char uint_8 > > > uint_8 fir() > { > > uint_8 buffer[MAX], out; > > out =( (buffer[0] + buffer[5]) + > ((buffer[1] + buffer[4]) * 2) + > ((buffer[2] + buffer[3]) * 3 ) > ) / 16 > > return out; > > } > > /*********************************************************/ > > > The whole program needs to be converted to 10-bit data. > Pls let me know how to do it....
Change int_8 to int_16. Put the 10 bits in the lower 10 bits of the 16-bit integers, sign-extended. Make the function return int_16. -- Randy Yates Sony Ericsson Mobile Communications Research Triangle Park, NC, USA randy.yates@sonyericsson.com, 919-472-1124
There is a big difference in how one can interpret this requirement.
As Randy pointed out, you can simply change the variable type, this
will keep your samples (where ever they are as Pete pointed out) the
same but allow you room for overflow.  Is this what you need the extra
bits for?

Or, do you mean how do you take 8-bit data and convert it to 10-bit
data, using all of the bits.  In that case, you'll have to change the
type and shift your data <<2.

QN