8-bit to 12-bit scaling
TC
Posts: 1,019
in Propeller 1
Hello all,
I am trying to find an elegant and simple way to scale a 8-bit value, to a 12-bit value. I made up a simple spreadsheet to help me figure out what would work, but I cant figure out what will work. On my spreadsheet I converted the 8-bit value, to a percentage, then took that percentage and scaled it up to a 12-bit value.
Would someone have a simple way to take a 8-bit value, and up scale it to a 12-bit value?
I did figure out that I need to shift the bits to the left 4 places, but that is as far as I have been able to figure out.
Thanks TC
I am trying to find an elegant and simple way to scale a 8-bit value, to a 12-bit value. I made up a simple spreadsheet to help me figure out what would work, but I cant figure out what will work. On my spreadsheet I converted the 8-bit value, to a percentage, then took that percentage and scaled it up to a 12-bit value.
X = ("8-bit value"/255)*100 "12-bit value" = (X / 100)*4095
Would someone have a simple way to take a 8-bit value, and up scale it to a 12-bit value?
I did figure out that I need to shift the bits to the left 4 places, but that is as far as I have been able to figure out.
Thanks TC
Comments
ie: Top most bits are repeated at the bottom. If you wanted, say, 8 bits to 24 bits, it's X = (value << 16) OR (value << 8 ) OR value
X := value * 16
(spin)
X = value * 16 ;
(C)
Of course if you want FF to map to FFF, you'll need something like
X = value * 0xfff / 0xff ;
X := value * $FFF / $FF
depending on language.
@evanh - the "AND 15" is redundant since it is an 8-bit value and there are no extra bits to mask off.
@Mark_T - shifting bits is always way more efficient as the Prop natively supports that whereas multiplication is much slower. Besides, I think bit shift is clearer for bit ops.
Yep, that's always a nice bonus if it's an option. Simply sum 'em all together and, voilà, extra depth for the cost of blurring.
constants of low bit-count is usually good enough as there is considerable scope for adjusting filter coefficients
unless the stage has exceptionally high Q or high pass-band flatness is needed. FIR is much more expensive to calculate
as coefficients have to be more precise and there are many more of them (but fewer issues of stability).
I forget who, someone has posted a clever tool for Prop FIR code generation that commons up intermediate results
of the multiplies between coefficients in an FIR filter, which trades space for speed.
-Phil
Tracy and Mark: The objective here is to gain extra bit depth. Don't do any dividing or shifting.
Sum of 16 consecutive samples gives 4 bits extra depth, job done.