Deconstruct data frames
Simulink Real-Time / Utilities
The Bit Unpacking block extracts data frames. Its input port is typically connected to an output port of a Receive block or Digital Input block.
The block has one input port, which represents the data frame entity from which the signals are extracted and leaving the block at its output ports. The number of output ports and the data type of each output port depend on the settings in the block dialog box.
Bit Unpack Four Bytes
This example shows how to configure a Bit Upacking block to:
Receive a 32-bit word as input by using input port data type
Unpack four 8-bit words (bytes) from the input data by using a bit pattern.
Send four 8-bit words as output by using the output data type
After configuring the block parameters, the Bit Upacking block appears as shown.
Bit Patterns — Select bit pattern
Specify bit patterns. The data type must be a MATLAB® cell array vector. The number of elements in the cell array define the number of input ports shown by this block instance. The cell array elements must be of type double array and define the position of each bit of the incoming value (data typed input port) in the outgoing double value (data frame). From a data type perspective, the block behaves like a Sink block. The Input port (packed) data types specify the data type of the input port.
Input port (packed) data types — Packed data type
uint32 (default) |
From the list, select an input port (packed) data type.
Input port (packed) dimension — Packed data dimension
Specify the dimensions of the input port (packed). Enter this value as a vector.
Specify the size of the port by using a format compatible with the MATLAB
Output port (unpacked) data types (cell array) — Unpacked data type
The output ports (packed) can be of an arbitrary data type. The number of elements in the cell array define the number of output ports shown by this block instance. The data types are:
Output port (unpacked) dimension (cell array) — Unpacked data dimension
Specify the dimensions of each output port (unpacked). Enter this value as a cell array of vector sizes.
Sign extend — Enable sign extension
on (default) |
Select this check box to enable sign extension. If you select this check box and
unpack the data frame into a signed type (
int32), the block performs sign
extension. For example, if the bit pattern is
[0:4], and the data
int8, you are extracting 5 bits into an 8-bit wide signed
type. In this case, bits 5, 6, and 7 are the same as bit 4, resulting in sign extension.
This functionality enables you to pack and unpack negative numbers without losing
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
Introduced in R2006a