Main Content

Preamble Detector

Detect preamble in data packet

  • Preamble Detector block

Libraries:
Communications Toolbox / Synchronization

Description

The Preamble Detector block detects the end of preambles in data packets. A preamble is a set of symbols or bits used in packet-based communications systems to indicate the start of a packet. Packets consist of preamble data and user data. The length of the user data portion of the packet can vary during a simulation run.

This icon shows the block with all ports enabled:

Examples

expand all

The detect_binary_preamble model creates a 40-bit packet consisting of two 6-bit preamble sequences and two 14-bit random data sequences. Detect the preamble locations by using the Preamble Detector block.

Run the model. The values 6 and 26 output by the Preamble Detector block indicate the index of the last symbol of expected preamble detections. Occasionally, the random sequence generated by one of the Bernoulli Binary Generator blocks will duplicate the preamble pattern. When this happens additional preamble detections are reported. A longer preamble would reduce the frequency of such false alarms.

Preamble index locations found:

ans =

     6
    26

The detect_complex_preamble.slx model creates a 100 symbol packet by generating a preamble of 16 QPSK-modulated symbols and prepending it to a random sequence of 84 QPSK-modulated symbols. The packet passes through a noisy channel and is input to a Preamble Detector block. The preamble locations and the detection metric outputs are displayed by a Time Scope block.

Run the model with the detection threshold set to 3.

There are many preamble locations shown for each 1 s frame because the detection metric exceeds the threshold multiple times in each frame. Increasing the detection threshold will reduce the number false preamble detections. Ideally, there should only be a single location shown for each frame because there is only one preamble. Looking at the detection metric plot, suggests that a threshold of 15 will result in the selection of the peak detection metric and correct preamble location.

Change the detection threshold from 3 to 15. Rerun the model. The preamble location index is 16 in each frame, which indicates the end of the preamble.

Ports

Input

expand all

Input data of symbols or bits, specified as a scalar, a column vector, or it can be empty. The input data can contain multiple packets. This port is unnamed on the block.

Data Types: single | double | Boolean | int8 | uint8
Complex Number Support: Yes

Output

expand all

Index of the last preamble symbol, returned as a scalar or a column vector, or empty of the same data type as the input data.

  • When the Detections parameter is set to All, Idx outputs the index corresponding to the last element of each detected preamble.

  • When the Detections parameter is set to First, Idx outputs the index corresponding to the last element of the first detected preamble.

This port is unnamed until the DtMt port is enabled.

Detection metric, returned as a scalar or column vector of the same dimensions and data type as the input data packet, In.

  • If either the preamble or input data is complex, the detection metric is the absolute value of the cross-correlation of the preamble and the input data.

  • If both the preamble and input data are real, the detection metric is the cross-correlation of the preamble and the input data.

Dependencies

To enable this port, set the Input parameter to Symbol, and select the Output detection metric parameter.

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.

Input type, specified as Symbol or Bit.

  • For binary inputs, set this parameter to Bit.

  • For all other inputs, set this parameter to Symbol.

For information on execution speed, see Tips.

Preamble sequence, specified as a column vector.

  • If the Input parameter is set to Bit, the preamble must be binary.

  • If the Input parameter is set to Symbol, the preamble can be any real or complex sequence.

Detection threshold, specified as a nonnegative scalar. When the detection metric is greater than or equal to the threshold, the block detects the preamble and updates Idx.

Tunable: Yes

Dependencies

To enable this parameter, set the Input parameter to Symbol.

Select this parameter to output the detection metric and enable the DtMt output port.

Dependencies

To enable this parameter, set the Input parameter to Symbol.

Detections returned, specified as All or First. Specifying All returns all detected preambles. Specifying First returns only the first detected preamble.

Tunable: Yes

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 Interpreted Execution vs. Code Generation (Simulink).

Block Characteristics

Data Types

Boolean | double | integer | single

Multidimensional Signals

no

Variable-Size Signals

yes

Tips

  • For faster execution of the Preamble Detector block, set the Simulate using parameter to:

    • Code generation when the Input parameter is set to Symbol

    • Interpreted execution when the Input parameter is set to Bit

Algorithms

Bit Inputs

When the input data is composed of bits, the preamble detector uses an exact pattern match.

Symbol Inputs

When the input data is composed of symbols, the preamble detector uses a cross-correlation algorithm. A finite impulse response (FIR) filter, in which the coefficients are specified from the preamble, computes the cross-correlation between the input data and the preamble. When a sequence of input samples matches the preamble, the filter output reaches its peak. The index of the peak corresponds to the end of the preamble sequence in the input data. For more information about the FIR filter algorithm, see Discrete FIR Filter (Simulink).

The cross-correlation values that are greater than or equal to the specified detection threshold are reported as peaks.

  • If the detection threshold is too low, the algorithm detects false peaks, or, in the extreme case, as many peaks as there are input samples.

  • If the detection threshold is too high, the algorithm misses detecting peaks, or, in the extreme case, it detects no peaks at all.

Consequently, the selection of the detection threshold is critical.

Extended Capabilities

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

Version History

Introduced in R2016b