Digital Signal Processing Reference
In-Depth Information
EXAMPLE 11.12
Givena16-bit datumlc¼2050 (decimal), convert it to a 5-bit linear PCMcode using the information inProgram11.1.
Solution:
a. Encoding:
tmp ¼ 2050 (decimal) ¼ 0x0802 (hex) ¼ 0000 1000 0000 0010 (binary)
After shifting 11 bits, tmp ¼ 0x0001 (hex)
PCMcode ¼ tmp&mask[5-1]¼0x0001&0x000f¼0x0001 (hex) // Get magnitude bits
if lc >0{
PCMcode ¼ PCMcode j sign[5-1] // Add positive sign bit
} // This line is not executed since lc < 0
PCMcode ¼ 00001 (binary)
b. Decoding:
dec ¼ PCMcode & mask[4] ¼ 0x0001&0x000f¼0x0001 (hex)
tmp ¼ PCMcode&sign[4] ¼ 0x0001&0x0010¼0x0000 (hex) (the number is negative)
dec ¼ dec<<11¼0x0800
dec ¼dec j rec[4]¼0x0800 j 0x0400¼0x0C00 (hex)¼3072 (decimal)
lc ¼3072 (recovered decimal)
As expected, the recovered PCM code is different from the original code, since a PCM is the lossy coding scheme.
The same procedure can be followed for coding a positive decimal number.
C Program 11.1. Encoding and decoding using the TMS320C6713 DSK.
int PCMcode;
/* Sign-magnitude format: s magnitude bits, see Section 11.1 , in Chapter 11 */
/* convert a16-bit PCM code a5-bit PCMcode,and recover the5-bitPCM code to the16-bit PCM code */
// See the following example:
/* Convert a 16-bit sign-magnitude code 5-bit PCM code 16-bit recovered sign-magnitude code */
/* sADCDEFGHIJKLMNO sABCDE sABCD10000000000 */
/* Note that audio input/output data are in 2 ' s complement form */
/* For encoder, convert the 2 ' s complement input to the sign-magnitude form before
quantization */
/* For decoder, convert the sign-magnitude form to the 2
s complement output before DAC */
'
int nofbits
¼
5; // specify the number of quantization bits
int sign[16]
{0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x100,0x200,0x400,0x800,0x1000,0x2000,0x4000,0x8000}; // add sign bit (MSB)
int mask[16]
¼
{0x0,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,
0xff,0x1ff,0x3ff,0x7ff,0xfff,0x1fff,0x3fff,0x7fff}; // mask for obtaining
magnitude bits
int rec[16] ¼ {0x4000,0x2000,0x1000,0x0800,
0x0400,0x0200,0x0100,0x0080,
0x0040,0x0020,0x0010,0x0008,
0x0004,0x0002,0x0001,0x0000};// the midpoint of the quantization interval
interrupt void c_int11()
{
¼
int lc; /*left channel input */
int rc; /*right channel input */
int lcnew; /*left channel output */
Search WWH ::




Custom Search