# 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 object implements LFSR using a simple shift register generator (SSRG, or Fibonacci) configuration. Pseudo-noise sequences are typically used for pseudorandom scrambling and in direct-sequence spread-spectrum systems.

To generate a PN sequence:

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

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

## Creation

### Description

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

pnSequence = comm.PNSequence(Name,Value) sets properties using one or more name-value pairs. Enclose each property name in quotes.

## 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.

Generator polynomial that determines the feedback connections of the shift register , specified as one of these:

• A polynomial character vector that includes the number 1.

• A binary row vector that represents the coefficients of the generator polynomial in order of descending power. The first and last entries must be 1. The length of this vector is N + 1, where N is the degree of the generator polynomial.

• A vector containing the exponents of z for the nonzero terms of the polynomial in descending order of powers. The last entry must be 0.

Example: 'z^8 + z^2 + 1', [1 0 0 0 0 0 1 0 1], and [8 2 0] represent the same polynomial, p(z) = z8 + z2 + 1.

Data Types: double | char

Source of the initial conditions that determines the start of the PN sequence, specified as one of these:

• 'Property' — Specify PN sequence generator initial conditions as a binary scalar or binary vector using the InitialConditions property.

• 'Input port' — Specify PN sequence generator initial conditions by using an additional input argument, when calling the object. The object accepts a binary scalar or binary vector input. The length of the input must equal the degree of the generator polynomial that the Polynomial property specifies.

Data Types: char

Initial conditions of shift register when the simulation starts, specified as a binary scalar or binary vector.

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. The length of the vector must equal the degree of the generator polynomial. 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.

#### Dependencies

This property is available when InitialConditionsSource is set to 'Property'.

Data Types: double

Source of the mask that determines the shift of the PN sequence, specified as one of these:

• 'Property' — Specify the mask as an integer scalar or binary vector using the Mask property.

• 'Input port' — Specify the mask by using an additional input argument, when calling the object. The mask can only be specified as a binary vector, whose length must equal the degree of the generator polynomial that the Polynomial property specifies.

Data Types: char

Mask that determines how the PN sequence is shifted from its starting point, specified as an integer scalar or a binary vector.

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 = 2n – 1, where n is the degree of the generator polynomial that the Polynomial property specifies, 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 that the Polynomial specifies. For more information, see Shifting PN Sequence Starting Point.

#### Dependencies

This property is available when MaskSource is set to 'Property'.

Set this property to true to enable variable-size outputs by using an additional input argument when calling the object. The enabled input specifies the output size of the PN sequence. 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.

Maximum output size, specified as a positive integer two-element row vector that denotes the maximum output size of the PN sequence. The second element of the vector must be 1.

Example: [10 1] gives a 10-by-1 maximum sized output signal.

#### Dependencies

This property is available when VariableSizeOutput is set to true.

Number of samples output per frame by the PN sequence object, specified as a positive integer. 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 = 2n – 1, where n represents the degree of the generator polynomial that the Polynomial specifies.

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.

Set this property to true to enable PN sequence generator reset by using an additional input argument when calling the object. This input resets the states of the PN sequence generator to the initial conditions specified in the InitialConditions property. For more information, see Resetting a Signal.

#### Dependencies

This property is available when InitialConditionsSource is set to 'Property'.

Option to output bit-packed words, specified as false or true. Set this property to true to enable bit-packed outputs.

When BitPackedOutput is true, the object outputs a column vector of length M, which contains most-significant-bit (MSB) first 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.

Note

The first bit from the left in the bit-packed word contains the most significant bit for the integer representation.

Number of bits packed into each output data word, specified as an integer in the range [1, 32].

#### Dependencies

This property is available when BitPackedOutput is set to true.

Set this property to true to obtain signed, bit-packed, output words. 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 is available when BitPackedOutput is set to true.

Output data type, specified as one of these:

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

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

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 OutputDataType depends on the setting of BitPackedOutput.

## Usage

### Description

example

outSequence = pnSequence() outputs a frame of the PN sequence. Specify the frame length with the SamplesPerFrame property. The PN sequence has a period of N = 2n – 1, where n is the degree of the generator polynomial that you specify in the Polynomial property.

You can combine optional input arguments when you set their enabling properties. Optional inputs must be listed in the same order as the order of the enabling properties.

outSequence = pnSequence(initCond) provides an additional input with values specifying the initial conditions of the linear-feedback shift register.

This syntax applies when you set the InitialConditionsSource property of the object to 'Input port'.

outSequence = pnSequence(maskVec) provides an additional input specifying the mask vector that determines how the PN sequence is shifted from its starting point.

This syntax applies when you set the MaskSource property of the object to 'Input port'.

outSequence = pnSequence(outputSize) provides an additional input specifying the output size of the PN sequence.

This syntax applies when you set the VariableSizeOutput property of the object to true.

outSequence = pnSequence(reset) provides an additional input indicating whether to reset the PN sequence generator.

This syntax applies when you set InitialConditionsSource to 'Property' and ResetInputPort to true.

Using these syntaxes, you can combine optional input arguments when you set their enabling properties. Optional inputs must be listed in the same order as the order of the enabling properties.

### Input Arguments

expand all

Initial conditions of the shift register when the simulation starts, specified as a binary scalar or binary vector. When you set initCond to a binary vector, the length of the vector must equal the degree of the Polynomial property. The scalar, or at least one element of initCond, must be nonzero for the object to generate a nonzero sequence.

Example: outSequence = pnSequence([1 1 0]) corresponds to possible initial register states for a PN sequence generator specified by a generator polynomial of degree 3.

Data Types: double

Mask that determines how the PN sequence is shifted from its starting point, specified as a binary vector. The length of the vector must equal the degree of the Polynomial property.

Output size of the PN sequence, specified as a scalar or two-element row vector. When you set outputSize to a two-element row vector, the second element must be equal to 1.

When you specify reset as a scalar, the object resets to the initial conditions specified in the InitialConditions property and generates a new output frame.

When you specify reset as a column vector, the length of the vector must equal the number of samples per frame specified in SamplesPerFrame. A column vector input allows multiple resets within an output frame. A non-zero value at the ith element of the vector will cause a reset at the ith element of the generated PN sequence.

### Output Arguments

expand all

PN sequence generated by the object, returned as a column vector.

## 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

 step Run System object algorithm release Release resources and allow changes to System object property values and input characteristics reset Reset internal states of System object

## Examples

collapse 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
⋮

The comm.PNSequence system object implements a linear-feedback shift register (LFSR) using a simple shift register generator (SSRG, or Fibonacci configuration). This configuration differs from the modular shift register generator (MSRG, or Galois configuration) by a phase difference, that can be determined empirically from the system object.

This phase difference can be specified as the Mask parameter for the comm.PNSequence system object to generate the equivalent MSRG configuration output. The block diagram represents the implementation of a 5-bit LFSR in the Galois (MSRG) configuration.

Load the file GaloisLFSR. The file contains the following variables that define the properties and output PN sequence of the 5-bit Galois LFSR:

• polyVec: Generator polynomial

• polySize: Degree of the generator polynomial

• initStates: Initial conditions of the shift register

• pn_msrg: Output PN sequence of maximal length, from the 5-bit Galois LFSR

Generate PN sequence data by using the comm.PNSequence object with the same set of properties used to implement the 5-bit Galois LFSR. Compare this PN sequence with the output of the 5-bit Galois LFSR. The two sequences differ by a phase shift.

pnSequence = comm.PNSequence('Polynomial',polyVec,'InitialConditions',initStates,...

pn = pnSequence();

isequal(pn,pn_msrg)
ans = logical
0

Compute the phase shift between the two configurations. Set the value of the Mask property based on this phase shift.

for i = 1:length(pn)
exp_pn = [pn(i:end);pn(1:(i-1))];
if isequal(exp_pn,pn_msrg)
break
end
end

Generate PN sequence data by using the comm.PNSequence system object with the modified Mask property value. Compare this sequence with the output of the 5-bit Galois LFSR. The two sequences are now equal.

pnSequence_mod = comm.PNSequence('Polynomial',polyVec,'InitialConditions',initStates,...

pn_mod = pnSequence_mod();

isequal(pn_mod,pn_msrg)
ans = logical
1

This figure defines a PN sequence generator with a generator polynomial $p\left(z\right)={z}^{6}+z+1$. You can set up the PN sequence generator by typing the following at the MATLAB command line.

h1 = comm.PNSequence('Polynomial', [1 0 0 0 0 1 1], 'InitialConditions', [1 1 0 1 0 1]);
h2 = comm.PNSequence('Polynomial', [1 0 0 0 0 1 1], 'Mask', 22);
mask2shift ([1 0 0 0 0 1 1],[1 1 0 1 0 1])
ans = 22

Alternatively you can input the polynomial exponents of z for the nonzero terms of the polynomial in descending order of powers.

h = comm.PNSequence('Polynomial', [6 1 0], 'InitialConditions', [1 1 0 1 0 1])
h =
comm.PNSequence with properties:

Polynomial: [6 1 0]
InitialConditionsSource: 'Property'
InitialConditions: [1 1 0 1 0 1]
VariableSizeOutput: false
SamplesPerFrame: 1
ResetInputPort: false
BitPackedOutput: false
OutputDataType: 'double'

expand all

## References

[1] Proakis, John G. Digital Communications. 3rd ed. New York: McGraw Hill, 1995.

[2] Lee, J. S., and L. E. Miller. CDMA Systems Engineering Handbook. Boston and London. Artech House, 1998.

[3] Golomb, S.W. Shift Register Sequences. Laguna Hills. Aegean Park Press, 1967.

## Extended Capabilities

### Blocks

Introduced in R2012a