Main Content

PN Sequence Generator

Generate pseudonoise sequence

  • PN Sequence Generator block

Libraries:
Communications Toolbox / Comm Sources / Sequence Generators
Communications Toolbox HDL Support / Comm Sources

Description

The PN Sequence Generator block generates a sequence of pseudorandom binary numbers using a linear-feedback shift register (LFSR). Pseudonoise sequences are typically used for pseudorandom scrambling, and in direct-sequence spread-spectrum systems. For more information, see More About.

These icons shows the block with all ports enabled.

Examples

expand all

This example shows that sequences output from the PN Sequence Generator block can be modeled using a linear feedback shift register (LFSR) built with primitive Simulink® blocks.

The cm_ex__pnseq_vs_prim_sl model generates the generator polynomial, p(z)=z^6+z+1, using the PN Sequence Generator block and by modeling a LFSR using primitive Simulink blocks. The Initial states and Output mask vector (or scalar shift value) parameters of the PN Sequence Generator block are interpreted in the LFSR model schematic. The PreLoadFcn callback function is used to initialize runtime parameters. To view the callback functions from the Simulink Toolstrip, on the Modeling tab, in the Design gallery, click Property Inspector.

The scope output shows that the two implementations produce matching PN sequences.

Using the PN Sequence Generator block allows you to easily generate PN sequences of large periods. To experiment further, open the model. Modify settings to see how the performance varies for different path delays or adjust the PN sequence generator parameters. You can experiment with different initial states, by changing the value of Initial states prior to running the simulation. For all values, the two generated sequences are the same.

Digital communications systems commonly use additive scrambling and descrambling to randomize input data to aid in timing synchronization and meeting power spectral requirements. The Scrambler block supports multiplicative scrambling but does not support additive scrambling. To perform additive scrambling, you can use the PN Sequence Generator block. This example implements the additive scrambling specified in IEEE 802.11™ [1] by scrambling input data with an output sequence generated by the PN Sequence Generator block. For a MATLAB® example with a similar workflow, see the Additive Scrambling of Input Data example on the comm.PNSequence reference page.

This figure shows an additive scrambler, that uses the generator polynomial $x^7+x^4+1$, as specified in Figure 17-7 of IEEE 802.11™ Section 17.3.5.5 [1].

Compare the shift register specified in 802.11 with the shift register implemented using a PN Sequence Generator block and observe the two shift register schematics are mirror images of each other. Therefore, when configuring the PN Sequence Generator block to implement an additive scrambler, you must reverse values for the generator polynomial, the initial states, and the mask output. To take the output of the register from the leading end, specify a shift value of 7.

For more information about the 802.11 scrambler, see [1] and the wlanScramble (WLAN Toolbox) reference page.

The cm_additive_scrambling model scrambles and compares the generated scrambling sequence and a frame of data scrambled according to the 802.11 specified additive scrambler by using these two additive scrambler implementations:

  • A shift register comprised of discrete Delay (Simulink) blocks and Logical Operator (Simulink) blocks configured as XOR operators.

  • The PN Sequence Generator block and XOR operator.

To compare the additive scrambler implementations, the cm_additive_scrambling model uses:

  • A Bernoulli Binary Generator block to provide an input signal to scramble.

  • A PN Sequence Generator block configured to use $x^7+x^3+1$ for the generator polynomial, [1 1 1 1 1 1 1] for the initial shift register state, and 7 for the output scrambling shift value.

  • A Logical Operator (Simulink) block configured as an XOR operator to apply the scramble sequence to the input data.

  • An Error Rate Calculation block to verify the scrambled data output from the discrete block shift register and the PN sequence versions of the additive scrambler match.

  • The PreLoadFcn callback function to create a workspace variable containing the 127-bit scrambler output sequence specified in section 17.3.5.5 of the IEEE 802.11 standard. A Relational Operator (Simulink) configured for an == operation compares the 127-bit scrambler sequence as output from the Signal From Workspace block to the PN Sequence block output.

Simulate Additive Scrambling

Run the model and display the results of the error rate calculation for the scrambled input sequence and equal comparison for the scrambler sequence.

Number of errors in scrambled output comparison is 0.
Number of mismatches comparing PN sequence output to IEEE 802.11 scrambler sequence 0.

References

[1] IEEE Std 802.11™-2020 (Revision of IEEE Std 802.11-2016). "Part 11: Wireless LAN Medium Access Control (MAC) and Physical Layer (PHY) Specifications." IEEE Standard for Information technology - Telecommunications and information exchange between systems. Local and metropolitan area networks - Specific requirements.

This model simulates pseudo-random spreading for a single-user system in a multipath transmission environment. This is similar to a mobile channel environment where the signals are received over multiple paths. Each path can have different amplitudes and delays. The receiver combines the independent paths coherently by using diversity reception to realize gains from the multipath transmissions received. The modeled system does not simulate fading effects and the receiver gets perfect knowledge of the number of paths and their respective delays.

The model uses random binary data, which is BPSK modulated (real), spread by PN sequences, and then transmitted over a multipath AWGN channel. The receiver consists of a despreader, a diversity combiner, and a BPSK demodulator. The receiver achieves gains from diversity combining due to the ideal auto-correlation properties of the PN sequences used when spreading the data.

To experiment further, open the model. Modify the settings to see how the performance varies for different path delays or adjust the PN sequence generator parameters.

This model simulates pseudo-random spreading for two users in a multipath transmission environment. This is similar to a mobile channel environment where the signals are received over multiple paths. Each path can have different amplitudes and delays. The receiver combines the independent paths coherently using diversity reception to realize gains from the multipath transmissions received. The modeled system does not simulate fading effects and the receiver gets perfect knowledge of the number of paths and their respective delays.

The model uses random binary data, which is BPSK modulated (real), spread by PN sequences, and then transmitted over a multipath AWGN channel. The receiver consists of a despreader, a diversity combiner, and a BPSK demodulator.

Using the same transmission data, the model calculates the performance for two-user transmissions through identically configured, multipath AWGN channels.

Because the transmissions for the individual users were spread using different PN sequences, the error rate computed for the users are different. Due to the higher cross-correlation properties of the nonorthogonal PN sequences used to spread the data, BER performance is degraded in a multipath environment. Sequences with high orthogonality, such as Hadamard and Kasami, are a better choice for multipath environments. For a multipath example that uses Hadamard code sequences when spreading user data, see Orthogonal Spreading for Multiuser System in Single-Path Channel. For a multipath example that uses Kasami code sequences when spreading user data, see Kasami Spreading for Multiuser System in Multipath Channel.

To experiment further, open the model. Modify the settings to see how the performance varies for different path delays or with different PN sequences for the individual users.

Ports

Input

expand all

Output mask to delay the PN sequence from initial time, specified as a binary vector with N elements. N is the degree of the generator polynomial.

Dependencies

To enable this port, set Output mask source to Input port.

Data Types: double | uint8 | ufix1

Output size for variable-size output signals, specified as an integer. For information about variable-size signals, see Variable-Size Signal Basics (Simulink).

Dependencies

To enable this port, select Output variable-size signals and set Maximum output size source to Dialog parameter.

Data Types: double

Reference input, specified as a column vector that determines the maximum and current output sequence length. The Ref input must be a variable-size signal. For information about variable-size signals, see Variable-Size Signal Basics (Simulink).

Dependencies

To enable this port, select Output variable-size signals and set Maximum output size source to Inherit from reference input.

Data Types: double

Reset sequence generator, specified as 0 or 1. For more information, see Reset Behavior.

Dependencies

To enable this port, select Reset on nonzero input.

Data Types: Boolean

Output

expand all

PN sequence, returned as a binary vector. The data type of the output is specified by Output data type.

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.

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

  • Character vector or string scalar of a polynomial whose constant term is 1. For more information, see Representation of Polynomials in Communications Toolbox.

  • Binary-valued row vector that represents the coefficients of the polynomial in order of descending powers. The length of this vector must be N + 1, where N is the degree of the polynomial. The first and last entries must be 1, indicating the leading term with degree N and a constant term of 1.

  • Integer-valued row vector of elements that represent the exponents for the nonzero terms of the polynomial in order of descending powers. The last entry must be 0, indicating a constant term of 1.

For more information, see Simple Shift Register Generator and Polynomial Order and Shift Register Orientation.

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) = z 8 + z 2 + 1.

Initial shift register states of the PN sequence generator when the simulation starts, specified as a binary-valued row vector. The length of the vector must equal the degree of the generator polynomial specified by the Generator polynomial. For more information, see Simple Shift Register Generator and Polynomial Order and Shift Register Orientation.

Note

For the block to generate a nonzero sequence, the Initial states vector must contain at least one nonzero element.

Output mask source that indicates how the output mask information is given to the block, specified as one of these:

  • Dialog parameter to use the Output mask vector (or scalar shift value) parameter setting.

  • Input port to add and use the Mask input port.

Output mask vector or scalar shift value, specified as an integer scalar or binary row vector of length N, where N is the degree of the generator polynomial. This parameter determines the delay of the PN sequence from the initial time. For more information, see Shifting PN Sequence Starting Point.

Dependencies

To enable this parameter, set Output mask source to Dialog parameter.

Select this parameter to enable variable-length output sequences during simulation. When you clear this parameter, the block outputs fixed-length sequences. When you select this parameter, the block can output variable-length sequences. For information about variable-size signals, see Variable-Size Signal Basics (Simulink).

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.

Example: 1 specifies a sample time of 1 second.

Dependencies

To enable this parameter, clear Output variable-size signals.

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.

Dependencies

To enable this parameter, clear Output variable-size signals.

Select how to specify the maximum sequence output size.

  • Dialog parameter — Select this value to configure the block to use the Maximum output size parameter setting as the maximum permitted output sequence length. The oSiz input port specifies the current size of the output signal, and the block output inherits the sample time from the input signal. The input value of oSiz must be less than or equal to the Maximum output size parameter.

  • Inherit from reference port — Select this value to enable the Ref input port and configure the block to inherit the sample time, maximum size, and current output size from the variable-sized signal at the Ref input port. These set the maximum permitted output sequence length.

Dependencies

To enable this parameter, select Output variable-size signals.

Specify the maximum output size for the block. n is a positive scalar.

Example: [10 1] specifies a 10-by-1 maximum size for the output signal.

Dependencies

To enable this parameter, select Output variable-size signals and set Maximum output size source to Dialog parameter.

Select this parameter to add the Rst input port. For more information, see Reset Behavior.

Select this parameter to make the Number of packed bits and Interpret bit-packed values as signed parameters available.

When this parameter is selected, the block generates (M×P) bits. M is the number of samples per frame specified in the Samples per frame parameter. P is the size of the bit-packed words specified in the Number of packed bits parameter. Each group of P bits is packed into an integer, resulting in an integer-valued output vector containing M elements. The data type of the output is specified by Output data type.

Note

For the integer representation, the top-most bit in each group of P bits is considered the MSB, while the bottom-most bit is the LSB.

Number of packed bits, specified as an integer in the range [1, 32].

Dependencies

To enable this parameter, select Enable bit-packed outputs.

Interpret bit-packed values as signed integer data values when selected or unsigned integer data values when cleared. When selected, a 1 in the most significant bit (sign bit) indicates a negative value.

Dependencies

To enable this parameter, select Enable bit-packed outputs.

Output data type, specified as double, boolean, or Smallest unsigned integer.

  • When Enable bit-packed outputs is cleared, the output data type can be specified as a double, boolean, or Smallest unsigned integer. When the Output data type parameter is set to Smallest unsigned integer, the output data type is selected based on the settings used in the Hardware Implementation pane of the Configuration Parameters dialog box of the model. If ASIC/FPGA is selected in the Hardware Implementation pane, the output data type ufix(1) = ideal minimum one-bit size. For all other selections, it is an unsigned integer with the smallest available word length large enough to fit one bit, usually corresponding to the size of a char (for example, uint8).

  • When Enable bit-packed outputs is selected, the output data type can be specified as double or Smallest unsigned integer. When the Output data type parameter is set to Smallest unsigned integer, the output data type is selected based on the Interpret bit-packed values as signed and Number of packed bits parameters, and the settings used in the Hardware Implementation pane of the Configuration Parameters dialog box of the model. If ASIC/FPGA is selected in the Hardware Implementation pane, the output data type is the ideal minimum n-bit size, such as sfix(n) or ufix(n), based on the Interpret bit-packed values as signed parameter. For all other selections, it is a signed or unsigned integer with the smallest available word length large enough to fit n bits.

Block Characteristics

Data Types

Boolean | double | fixed point

Multidimensional Signals

no

Variable-Size Signals

yes

More About

expand all

References

[1] Proakis, John G. Digital Communications. 5th ed. New York: McGraw Hill, 2007.

[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

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

Version History

Introduced before R2006a

expand all