Main Content

comm.PreambleDetector

Detect preamble in data

Description

The comm.PreambleDetector System object™ detects a preamble in an input data sequence. A preamble is a set of symbols or bits used in packet-based communication systems to indicate the start of a packet. The preamble detector object finds the location corresponding to the end of the preamble.

To detect a preamble in an input data sequence:

  1. Create the comm.PreambleDetector object and set its properties.

  2. Call the object with arguments, as if it were a function.

To learn more about how System objects work, see What Are System Objects?

Creation

Description

example

prbdet = comm.PreambleDetector creates a preamble detector object using the default properties.

prbdet = comm.PreambleDetector(Name=Value) specifies additional properties using name-value arguments. For example, comm.PreambleDetector(Input="Bit",Detections="First") creates a preamble detector that expects a binary input signal and selects the first preamble detected.

example

prbdet = comm.PreambleDetector(prb,Name=Value) creates the object setting the Preamble property to prb in addition to those properties that you specify using name-value arguments.

Properties

expand all

Unless otherwise indicated, properties are nontunable, which means you cannot change their values after calling the object. Objects lock when you call them, and the release function unlocks them.

If a property is tunable, you can change its value at any time.

For more information on changing property values, see System Design in MATLAB Using System Objects.

Type of input data, specified as 'Symbol' or 'Bit'.

  • For binary inputs, set this property to 'Bit'. Binary data can be of data type double, single, Boolean, int8, or uint8 data types.

  • For all other inputs, set this property to 'Symbol'. Symbol data can be of data type double or single.

Preamble sequence, specified as a column vector. The object uses this sequence to detect the presence of the preamble in the input data.

  • If you set the Input property to 'Bit', the preamble must be a binary sequence.

  • If you set the Input property to 'Symbol', the preamble can be any real or complex sequence.

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

Detection threshold, specified as a nonnegative scalar. When the computed detection metric is greater than or equal to Threshold, the preamble is detected.

Tunable: Yes

Dependencies

This property is available when you set the Input property to 'Symbol'.

Number of preambles to detect, specified as 'All' or 'First'.

  • 'All' — Detects all the preambles in the input data sequence.

  • 'First' — Detects only the first preamble in the input data sequence.

Usage

Description

example

idx = prbdet(X) returns the location of the end of the preamble in data sequence x.

example

[idx,detmet] = prbdet(X) also returns the detection metric, detmet. This syntax is available when you set the Input property to 'Symbol'.

Input Arguments

expand all

Data sequence, specified as a scalar or row vector.

This object accepts variable-size inputs. After the object is locked, you can change the size of each input channel, but you cannot change the number of channels. For more information, see Variable-Size Signal Support with System Objects.

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

Output Arguments

expand all

Index of the end of the preamble, returned as a scalar or column vector. When you set the Detections property to:

  • "All" — The index of all preambles in the input data sequence are returned.

  • "First" — The index of the first preamble in the input data sequence is returned.

Detection metric, returned as a scalar or row vector with the same dimensions and data type as X.

The output, detmet, is determined by one of these algorithms:

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

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

Dependencies

This output can be returned when you set the Input property to 'Symbol'.

Object Functions

To use an object function, specify the System object as the first input argument. For example, to release system resources of a System object named obj, use this syntax:

release(obj)

expand all

stepRun System object algorithm
releaseRelease resources and allow changes to System object property values and input characteristics
resetReset internal states of System object

Examples

collapse all

Specify a six-bit preamble.

prb = [1 0 0 1 0 1]';

Create a preamble detector object that uses preamble prb and takes bit inputs.

prbdet = comm.PreambleDetector(prb,Input='Bit');

Generate a binary data sequence that contains two preambles and uses random bits to represent the data fields.

pkt = [prb; randi([0 1],10,1); prb; randi([0 1],10,1)];

Locate the indices of the two preambles. The indices correspond to the end of the preambles. The detector correctly identifies indices 6 and 22 as the end of the two preambles inserted in the sequence. If the random sequence generated for the data field duplicates the preamble pattern, an additional preamble detection would be reported. A longer preamble would reduce the frequency of such false alarms.

idx = prbdet(pkt)
idx = 2×1

     6
    22

Create a preamble and apply QPSK modulation.

p1 = [0 1 2 3 3 2 1 0]';
p = [p1; p1];
prb = pskmod(p,4,pi/4,'gray');

Create a comm.PreambleDetector object using preamble prb.

prbdet = comm.PreambleDetector(prb)
prbdet = 
  comm.PreambleDetector with properties:

         Input: 'Symbol'
      Preamble: [16x1 double]
     Threshold: 3
    Detections: 'All'

Generate a sequence of random symbols. The first sequence represents the last 20 symbols from a previous packet. The second sequence represents the symbols from the current packet.

d1 = randi([0 3],20,1);
d2 = randi([0 3],100,1);

Modulate the two sequences.

x1 = pskmod(d1,4,pi/4,'gray');
x2 = pskmod(d2,4,pi/4,'gray');

Create a sequence of modulated symbols consisting of the remnant of the previous packet, the preamble, and the current packet.

y = [x1; prb; x2];

Add white Gaussian noise.

z = awgn(y,10);

Determine the preamble index and the detection metric.

[idx,detmet] = prbdet(z);

Calculate the number of elements in idx. Because the number of elements is greater than one, the detection threshold is too low.

numel(idx)
ans = 81

Display the five largest detection metrics.

detmetSort = sort(detmet,'descend');
detmetSort(1:5)
ans = 5×1

   17.4372
   14.2811
   12.0468
    8.4345
    8.3604

Increase the threshold and determine the preamble index. The result of 36 corresponds to the sum of the preamble length (16) and the remaining samples in the previous packet (20). This result indicates that the preamble has been successfully detected.

prbdet.Threshold = 15;
idx = prbdet(z)
idx = 36

Using a preamble sequence with good correlation properties, find the last sample of the preamble for a transmitted data frame in a stream of delayed received data.

Define the preamble with a length of 17 by using the ninth root of the Zadoff-Chu sequence. Generate a transmission signal by concatenating several samples from a random signal, the preamble, and a random signal of 100 samples.

M = 16;  % 16-QAM modulation
preamble = zadoffChuSeq(9,17);
x = randi([0 M-1],100,1);
xmod = qammod(x,M,UnitAverage=true);
txsig = [xmod(23:30); preamble; xmod];

Create a variable fractional delay System object. Introduce a variable fractional delay of 82.3 samples. To return the full frame when executing the variable fractional delay object, add zero padding at the end of the transmitted signal. Add AWGN to the transmitted signal.

vfd = dsp.VariableFractionalDelay; 
samplesToDelay = 82.3;
txsigdelayed = ...
    vfd([txsig; zeros(ceil(samplesToDelay),1)],samplesToDelay);
SNR = 40;
rxsig = awgn(txsigdelayed,SNR);

Create a preamble detector System object, specifying the preamble, the threshold level, and output of the index for the first detection. For the conditions in the example, setting the threshold to 60% of the total magnitude of the preamble samples finds the correct index for the preamble. Run the preamble detection object, returning the preamble index and detection metric.

thr = 0.6*sum(abs(preamble).^2);
preambleDet = comm.PreambleDetector( ...
    Preamble=preamble, ...
    Threshold=thr, ...
    Detections='First');
[idx,detmet] = preambleDet(rxsig);
idx
idx = 107

The detection metric is the absolute value of the cross-correlation of the preamble and the input signal. The cross-correlation peak should align with the returned preamble index. To confirm that the returned index has identified the preamble, plot the returned cross-correlation values and compare the returned index value to the peak in the cross-correlation values.

plot(detmet)

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

Version History

Introduced in R2016b