Main Content

Fixed-Point Integer to Bit and Bit to Integer Conversion in Simulink

Use the Bit to Integer Converter (Simulink) and Integer to Bit Converter (Simulink) blocks in an example with fixed-point signals that performs audio scrambling and descrambling in Simulink®.

Explore Model

This example uses a simplified audio scrambler configuration and a 16-bit, fixed-point digital audio source for the recorded speech. The left-side of the model represents the audio scrambler subsystem and the right-side represents the descrambler subsystem.

In the audio scrambler subsystem, the Integer to Bit Converter block unpacks each 16-bit audio sample into a binary, 1-bit signal. The binary signal passes to a linear feedback shift register (LFSR) scrambler by using a Scrambler block. After the signal passes through the channel the signal is descrambled using the same LFSR operation. The scrambling operation randomly distributes any errors introduced by the channel in a controllable way.

From the LFSR, the scrambled audio bits pass to a Bit to Integer Converter block. This block packs the scrambled 1-bit samples into 16-bit audio samples. The audio samples pass to the Data Type Conversion (Simulink) block, which converts the integer-based audio samples back into fixed-point samples.

The fixed-point samples pass from the scrambler subsystem to the channel. In an actual system, the channel introduces noise that requires additional receiver components to recover to original signal. In this example a noiseless channel is used for illustrative purposes. The channel sends the samples to the descrambler subsystem.

In the audio descrambler subsystem, the Integer to Bit Converter block unpacks each 16-bit audio sample into a binary, 1-bit signal. To reverse the scrambling process, the binary signal passes to an LFSR descrambler. The LFSR descrambler implementation uses a Descrambler block. From the LFSR, the descrambled audio bits pass to the Bit to Integer Converter block. This block packs the descrambled 1-bit samples into 16-bit audio samples. The audio samples pass to the Data Type Conversion block, which converts the integer-based audio samples back into fixed-point samples.

In Simulink, the sfix16_En15 data type represents a signed (s) fixed-point (fix) signal with word length 16 and fraction length 15. This model represents audio signals using the sfix16_En15 data type, except when converting to and from 1-bit binary signals. All 1-bit signals are represented by ufix1, as seen at the output of the Integer to Bit Converter block. The audio source has 1024 samples per frame. For more information on fixed-point signals, see Fixed-Point Numbers (Simulink).

Describe Converter Block Settings

In the audio scrambler and descrambler subsystems, the Integer to Bit Converter block settings are:

  • Number of bits per integer: 16

  • Treat input values as: Signed

  • Output bit order: MSB first

  • Output data type: Inherit via internal rule

In the audio scrambler and descrambler subsystems, the Bit to Integer Converter block settings are:

  • Number of bits per integer: 16

  • Input bit order: MSB first

  • After bit packing, treat resulting integer values as: Signed

  • Output data type: Inherit via internal rule

Run Model

You can listen to the original audio signal, the scrambled audio signal, and the descrambled audio signal by running the model in Simulink. Select the Open model button. When the model opens, select Run, and then to hear the audio signals click the 'Play Audio:' icons in the model.

See Also

|