Documentation

comm.PNSequence

Generate a pseudo-noise (PN) sequence

Description

The PNSequence object generates a sequence of pseudorandom binary numbers using a linear-feedback shift register (LFSR). This block implements LFSR using a simple shift register generator (SSRG, or Fibonacci) configuration. You can use a pseudonoise sequence in a pseudorandom scrambler and descrambler. You can also use one in a direct-sequence spread-spectrum system.

To generate a PN sequence:

1. Define and set up your PN sequence object. See Construction.

2. Call step to generate a PN sequence according to the properties of comm.PNSequence. The behavior of step is specific to each object in the toolbox.

Note

Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj) and y = obj() perform equivalent operations.

Construction

H = comm.PNSequence creates a pseudo-noise (PN) sequence generator System object, H. This object generates a sequence of pseudorandom binary numbers using a linear-feedback shift register (LFSR).

H = comm.PNSequence(Name,Value) creates a PN sequence generator object, H, with each specified property set to the specified value. You can specify additional name-value pair arguments in any order as (Name1,Value1,...,NameN,ValueN).

Properties

Polynomial

Generator polynomial

Specify the polynomial that determines the shift register's feedback connections. The default is 'z^6 + z + 1'. You can specify the generator polynomial as a character vector or as a numeric, binary vector that lists the coefficients of the polynomial in descending order of powers. The first and last elements must equal 1, and the length of this vector must be n+1. The value n indicates the degree of the generator polynomial. Lastly, you can specify the generator polynomial as a numeric vector containing the exponents of z for the nonzero terms of the polynomial in descending order of powers. The last entry must be 0. For example, [1 0 0 0 0 0 1 0 1] and [8 2 0] represent the same polynomial, $g\left(z\right)={z}^{8}+{z}^{2}+1$. The PN sequence has a period of $N={2}^{n}-1$ (applies only to maximal length sequences).

InitialConditionsSource

Source of initial conditions

Specify the source of the initial conditions that determines the start of the PN sequence as one of Property | Input port. The default is Property. When you set this property to Property, the initial conditions can be specified as a scalar or binary vector using the InitialConditions property. When you set this property to Input port, you specify the initial conditions as an input to the step method. The object accepts a binary scalar or a binary vector input. The length of the input must equal the degree of the generator polynomial that the Polynomial property specifies.

InitialConditions

Initial conditions of shift register

Specify the initial values of the shift register as a binary, numeric scalar or a binary, numeric vector. The default is [0 0 0 0 0 1]. Set the vector length equal to the degree of the generator polynomial. If you set this property to a vector, each element of the vector corresponds to the initial value of the corresponding cell in the shift register. If you set this property to a scalar, the initial conditions of all the cells of the shift register are the specified scalar value. The scalar, or at least one element of the specified vector, must be nonzero for the object to generate a nonzero sequence.

Source of mask to shift PN sequence

Specify the source of the mask that determines the shift of the PN sequence as one of Property | Input port. The default is Property. When you set this property to Property, the mask can be specified as a scalar or binary vector using the Mask property. When you set this property to Input port, the mask, which is an input to the step method, can only be specified as a binary vector. This vector must have a length equal to the degree of the generator polynomial specified in the Polynomial property.

Mask to shift PN sequence

Specify the mask that determines how the PN sequence is shifted from its starting point as a numeric, integer scalar or as a binary vector. The default is 0.

When you set this property to an integer scalar, the value is the length of the shift. A scalar shift can be positive or negative. When the PN sequence has a period of $N={2}^{n}-1$, where n is the degree of the generator polynomial that you specify in the Polynomial property, the object wraps shift values that are negative or greater than N.

When you set this property to a binary vector, its length must equal the degree of the generator polynomial specified in the Polynomial property. The mask vector that represents $m\left(z\right)={z}^{D}$ modulo g(z), where g(z) is the generator polynomial, and the mask vector corresponds to a shift of D. For example, for a generator polynomial of degree of 4, the mask vector corresponding to D = 2 is [0 1 0 0], which represents the polynomial $m\left(z\right)={z}^{2}$.

You can calculate the mask vector using the shift2mask function. This property applies when you set the MaskSource property to Property.

VariableSizeOutput

Enable variable-size outputs

Set this property to true to enable an additional input to the step method. The default is false. When you set this property to true, the enabled input specifies the output size of the PN sequence used for the step. The input value must be less than or equal to the value of the MaximumOutputSize property.

When you set this property to false, the SamplesPerFrame property specifies the number of output samples.

MaximumOutputSize

Maximum output size

Specify the maximum output size of the PN sequence as a positive integer 2-element row vector. The second element of the vector must be 1. The default is [10 1].

This property applies when you set the VariableSizeOutput property to true.

SamplesPerFrame

Number of samples output per frame

Number of samples output per frame by the PN sequence object, specified as positive integer. The default is 1. If you set this property to a value of M, then the object outputs M samples of a PN sequence that has a period of $N={2}^{n}-1$. The value n represents the degree of the generator polynomial that you specify in the Polynomial property. If you set the BitPackedOutput property to false, the samples are bits from the PN sequence. If you set the BitPackedOutput property to true, then the output corresponds to SamplesPerFrame groups of bit-packed samples.

ResetInputPort

Enable generator reset input

Set this property to true to enable an additional input to the step method. The default is false. This input resets the states of the PN sequence generator to the initial conditions specified in the InitialConditions property.

BitPackedOutput

Option to output bit-packed words

Option to output bit-packed words, specified as false or true. Set this property to true to enable bit-packed outputs. The first bit from the left in the bit-packed word is considered the most significant bit. The default is false.

When BitPackedOutput is true, the object outputs a column vector of length M, which contains integer representations of bit words of length P. M is the number of samples per frame specified in the SamplesPerFrame property. P is the size of the bit-packed words specified in the NumPackedBits property.

NumPackedBits

Number of bits per bit-packed word

Specify the number of bits to pack into each output data word as a numeric, integer scalar value from 1 to 32. The default is 8.

Dependencies

This property applies when you set the BitPackedOutput property to true.

SignedOutput

Output signed bit-packed words

Set this property to true to obtain signed, bit-packed, output words. The default is false. In this case, a 1 in the most significant bit (sign bit) indicates a negative value. The property indicates negative numbers in a two's complement format.

Dependencies

This property applies when you set the BitPackedOutput property to true.

OutputDataType

Data type of output

Specify the output data type as one of these:

• When BitPackedOutput property is false, OutputDataType can be 'double', 'logical', or 'Smallest unsigned integer'.

• When BitPackedOutput property is true, OutputDataType can be 'double' or 'Smallest integer'.

The default is double.

Note

You must have a Fixed-Point Designer™ user license to use this property in 'Smallest unsigned integer' or 'Smallest integer' mode.

Dependencies

The valid settings for output data type depends on the setting of BitPackedOutput.

Methods

 reset Reset states of PN sequence generator object step Generate a pseudo-noise (PN) sequence
Common to All System Objects
release

Allow System object property value changes

Examples

expand all

Generate a 14-sample frame of a maximal length PN sequence given generator polynomial, ${x}^{3}+{x}^{2}+1$.

Generate PN sequence data by using the comm.PNSequence object. The sequence repeats itself as it contains 14 samples while the maximal sequence length is only 7 samples (${2}^{3}-1$).

pnSequence = comm.PNSequence('Polynomial',[3 2 0], ...
'SamplesPerFrame',14,'InitialConditions',[0 0 1]);
x1 = pnSequence();
[x1(1:7) x1(8:14)]
ans = 7×2

1     1
0     0
0     0
1     1
1     1
1     1
0     0

Create another maximal length sequence based on the generator polynomial, ${x}^{4}+x+1$. As it is a fourth order polynomial, the sequence repeats itself after 15 samples (${2}^{4}-1$).

pnSequence2 = comm.PNSequence('Polynomial','x^4+x+1', ...
'InitialConditions',[0 0 0 1],'SamplesPerFrame',30);
x2 = pnSequence2();
[x2(1:15) x2(16:30)]
ans = 15×2

1     1
0     0
0     0
0     0
1     1
0     0
0     0
1     1
1     1
0     0
⋮

Algorithms

This object implements the algorithm, inputs, and outputs described on the PN Sequence Generator block reference page. The object properties correspond to the block parameters, except:

• The object does not have a property to select frame based outputs.

• The object does not have a property that corresponds to the Sample time parameter.