You are here : matlab → Signal Processing → uencode
# uencode() - Signal Processing

### Syntax

### Example

### Output / Return Value

### Limitations

### Alternatives / See Also

### Reference

y = uencode(u,n) quantizes the entries in a multidimensional array of floating-point numbers u and encodes them as integers using 2n-level quantization. n must be an integer between 2 and 32 (inclusive). Inputs can be real or complex, double- or single-precision. The output y and the input u are arrays of the same size. The elements of the output y are unsigned integers with magnitudes in the range [0, 2n-1]. Elements of the input u outside of the range [-1,1] are treated as overflows and are saturated. For entries in the input u that are less than -1, the value of the output of uencode is 0. For entries in the input u that are greater than 1, the value of the output of uencode is 2n-1. y = uencode(u,n,v) allows the input u to have entries with floating-point values in the range [-v,v] before saturating them (the default value for v is 1). Elements of the input u outside of the range [-v,v] are treated as overflows and are saturated:For input entries less than -v, the value of the output of uencode is 0. For input entries greater than v, the value of the output of uencode is 2n-1. y = uencode(u,n,v,'SignFlag') maps entries in a multidimensional array of floating-point numbers u whose entries have values in the range [-v,v] to an integer output y. Input entries outside this range are saturated. The integer type of the output depends on the string 'SignFlag' and the number of quantization levels 2n. The string 'SignFlag' can be one of the following:'signed': Outputs are signed integers with magnitudes in the range [-2n/2, (2n/2) - 1].'unsigned' (default): Outputs are unsigned integers with magnitudes in the range [0, 2n-1].The output data types are optimized for the number of bits as shown in the table below. nUnsigned IntegerSigned Integer 2 to 8uint8int8 9 to 16uint16int16 17 to 32uint32int32

y = uencode(u,n)y = uencode(u,n,v)y = uencode(u,n,v,'SignFlag')

Map Floating-Point Scalars to IntegersOpen This Example Map floating-point scalars in [-1, 1] to uint8 (unsigned) integers. Produce a staircase plot. The horizontal axis ranges from -1 to 1 and the vertical axis from 0 to 7 (i.e., ). u = -1:0.01:1; y = uencode(u,3); plot(u,y,'.') Look at saturation effects when you underspecify the peak value for the input.u = -2:0.5:2; y = uencode(u,5,1) y = 0 0 0 8 16 24 31 31 31 Specify you want signed output.u = -2:0.5:2; y = uencode(u,5,2,'signed') y = -16 -12 -8 -4 0 4 8 12 15