Main Content

Fixed-Point Integer To Bit and Bit To Integer Conversion (Audio Scrambling and Descrambling Example)

This example illustrates how to use the Bit to Integer Converter and Integer to Bit Converter blocks with fixed-point signals in Simulink®.

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

Open Model

model = "ex_int_to_bit_bit_to_int";
open_system(model);
sim(model);

Structure

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, which randomizes the bits in a controllable way, thereby scrambling the signal. The LFSR Scrambler implementation uses the Scrambler block. From the LFSR, the scrambled audio bits pass to the 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 a channel. The channel sends the samples to the descrambler subsystem. For illustrative purposes, this example uses a noiseless channel. In an actual system, a channel may introduce noise. Removing such noise requires a more sophisticated design.

In the audio descrambler 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) descrambler, which randomizes the bits in a controllable way, reversing the scrambling process. This LFSR descrambler implementation uses the Communications Toolbox™ 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. Therefore, 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 a frame size (or number of samples per frame) of 1024. For more information on fixed-point signals, please refer to Fixed-Point Numbers in the Simulink® documentation.

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 the Model

You must run the example before you can listen to any of the audio signals. To run the example, click Run. You can hear the audio signals by clicking the yellow audio icons in the model.