Main Content

Bernoulli Binary Generator

Generate Bernoulli-distributed random binary numbers

  • Bernoulli Binary Generator block

Libraries:
Communications Toolbox / Comm Sources / Random Data Sources

Description

The Bernoulli Binary Generator block generates random binary numbers using a Bernoulli distribution. Use this block to generate random data bits to simulate digital communication systems and obtain performance metrics such as bit error rate. The Bernoulli distribution with parameter p produces zero with probability p and one with probability 1-p. The Bernoulli distribution has mean value 1-p and variance p(1-p). The Probability of zero parameter specifies p and can be any real number in range [0, 1].

The output signal can be a column or row vector, two-dimensional matrix, or scalar. The number of rows in the output signal corresponds to the number of samples in one frame and is set by the Samples per frame parameter. The number of columns in the output signal corresponds to the number of channels and is set by the number of elements in the Probability of zero parameter. For more details, see Sources and Sinks.

Examples

expand all

The doc_bernoulli_gen_example model generates binary data, applies BPSK modulation, and displays the output.

Run the model.

Limitations

  • To use this block in a For Each Subsystem (Simulink) you must set Source of initial seed to Auto and the model to Normal or Accelerator simulation mode. This ensures that each run will generate independent noise samples.

Ports

Output

expand all

Output data signal, returned as a scalar, vector, or matrix.

Data Types: double

Parameters

expand all

To edit block parameters interactively, use the Property Inspector. From the Simulink® Toolstrip, on the Simulation tab, in the Prepare gallery, select Property Inspector.

Probability of zero must be in the range of [0, 1]. The number of elements in the Probability of zero parameter corresponds to the number of independent channels output from the block. The Bernoulli distribution with parameter p produces zero with probability p and one with probability 1-p.

Source of the initial seed for the random number generator, specified as either:

  • Auto –– The block uses the global random number stream. If you use the parsim (Simulink) function, see Tips.

  • Parameter –– The block sets the random number generator seed to Initial seed.

For more information, see Managing the Global Stream Using RandStream and Random Number Generators.

Initial seed value for the random number generator, specified as a nonnegative integer. If this parameter is a constant, then the resulting sequence is repeatable.

Tunable: Yes

Dependencies

To enable this parameter, set the Source of initial seed to Parameter.

Positive scalars specify the time in seconds between each sample of the output signal. If you set the sample time to -1, the output signal inherits the sample time from downstream. For information on the relationship between the Sample time and Samples per frame parameters, see Sample Timing.

Samples per frame in one channel of the output signal, specified as a positive integer. For information on the relationship between Sample time and Samples per frame, see Sample Timing.

Output data type, specified as double, single, uint8, uint16, uint32, or boolean.

Type of simulation to run, specified as Code generation or Interpreted execution.

  • Code generation — Simulate the model by using generated C code. The first time you run a simulation, Simulink generates C code for the block. The model reuses the C code for subsequent simulations unless the model changes. This option requires additional startup time, but the speed of the subsequent simulations is faster than with the Interpreted execution option.

  • Interpreted execution — Simulate the model by using the MATLAB® interpreter. This option shortens startup time, but the speed of subsequent simulations is slower than with the Code generation option. In this mode, you can debug the source code of the block.

For more information, see Simulation Modes (Simulink).

Block Characteristics

Data Types

Boolean | double | integer | single

Multidimensional Signals

no

Variable-Size Signals

no

More About

expand all

Tips

Set Source of initial seed to Parameter and make sure that all blocks have different Initial seed values when running simulations in parallel using the parsim (Simulink) function, such as for Monte Carlo simulation runs.

Otherwise, the different workers may generate the same random numbers (leading to misleading results) for these model configurations:

  • If the model is in rapid accelerator mode.

  • If this block has Simulate using set to Code generation and Source of initial seed set to Auto.

For more information, see Choosing a Simulation Mode (Simulink).

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced before R2006a

expand all