# Kasami Sequence Generator

Generate Kasami sequence from set of Kasami sequences

## Library

Sequence Generators sublibrary of Comm Sources

## Description

The Kasami Sequence Generator block generates a sequence from the set of Kasami sequences. The Kasami sequences are a set of sequences that have good cross-correlation properties.

This block can output sequences that vary in length during simulation. For more information about variable-size signals, see Variable-Size Signal Basics in the Simulink® documentation.

### Kasami Sequences

There are two sets of Kasami sequences: the small set and the large set. The large set contains all the sequences in the small set. Only the small set is optimal in the sense of matching Welch's lower bound for correlation functions.

Kasami sequences have period N = 2n - 1, where n is a nonnegative, even integer. Let u be a binary sequence of length N, and let w be the sequence obtained by decimating u by 2n/2 +1. The small set of Kasami sequences is defined by the following formulas, in which T denotes the left shift operator, m is the shift parameter for w, and $\oplus$ denotes addition modulo 2.

Small Set of Kasami Sequences for n Even

${K}_{s}\left(u,n,m\right)=\left\{\begin{array}{ll}u\hfill & m=-1\hfill \\ u\oplus {T}^{m}w\hfill & m=0,...,{2}^{n/2}-2\hfill \end{array}$

Note that the small set contains 2n/2 sequences.

For mod(n, 4) = 2, the large set of Kasami sequences is defined as follows. Let v be the sequence formed by decimating the sequence u by 2n/2 + 1+ 1. The large set is defined by the following table, in which k and m are the shift parameters for the sequences v and w, respectively.

Large Set of Kasami Sequences for mod(n, 4) = 2

The sequences described in the first three rows of the preceding figure correspond to the Gold sequences for mod(n, 4) = 2. See the reference page for the Gold Sequence Generator block for a description of Gold sequences. However, the Kasami sequences form a larger set than the Gold sequences.

The correlation functions for the sequences takes on the values

{-t(n), -s(n), -1, s(n) -2 , t(n) - 2}

where

### Block Parameters

The Generator polynomial parameter specifies the generator polynomial, which determines the connections in the shift register that generates the sequence u. You can specify the Generator polynomial parameter using these formats:

• A polynomial string that includes the number `1`, for example, ```'z^4 + z + 1'```.

• A vector that lists the coefficients of the polynomial in descending order of powers. The first and last entries must be 1. Note that the length of this vector is one more than 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`.

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

The Initial states parameter specifies the initial states of the shift register that generates the sequence u. Initial States is a binary scalar or row vector of length equal to the degree of the Generator polynomial. If you choose a binary scalar, the block expands the scalar to a row vector of length equal to the degree of the Generator polynomial, all of whose entries equal the scalar.

The Sequence index parameter specifies the shifts of the sequences v and w used to generate the output sequence. You can specify the parameter in either of two ways:

• To generate sequences from the small set, for n is even, you can specify the Sequence index as an integer m. The range of m is [-1, ..., 2n/2 - 2]. The following table describes the output sequences corresponding to Sequence index `m`:

Sequence IndexRange of IndicesOutput Sequence
`-1`m = -1 u
`m`m = 0, ... , 2n/2 - 2

$u\oplus {T}^{m}w$

• To generate sequences from the large set, for mod (n, 4) = 2, where n is the degree of the Generator polynomial, you can specify Sequence index as an integer vector [k m]. In this case, the output sequence is from the large set. The range for k is [-2, ..., 2n - 2], and the range for m is [-1, ..., 2n/2 - 2]. The following table describes the output sequences corresponding to Sequence index [k m]:

Sequence Index [k m]Range of IndicesOutput Sequence
`[-2 -1]`k = -2, m = -1 u
`[-1 -1]`k = -1, m = -1 v
`[k -1]`

k = 0, 1, ... , 2n - 2

m = -1

$u\oplus {T}^{k}v$

`[-2 m]`

k = -2

m = 0, 1, ..., 2n/2 - 2

$u\oplus {T}^{m}w$

`[-1 m]`

k = -1

m = 0, ... , 2n/2 - 2

$v\oplus {T}^{m}w$

`[k m]`

k = 0, ... , 2n - 2

m = 0, ... , 2n/2 - 2

$u\oplus {T}^{k}v\oplus {T}^{m}w$

You can shift the starting point of the Kasami sequence with the Shift parameter, which is an integer representing the length of the shift.

You can use an external signal to reset the values of the internal shift register to the initial state by selecting Reset on nonzero input. This creates an input port for the external signal in the Kasami Sequence Generator block. The way the block resets the internal shift register depends on whether its output signal and the reset signal are sample-based or frame-based. See Example: Resetting a Signal for an example.

### Polynomials for Generating Kasami Sequences

The following table lists some of the polynomials that you can use to generate the Kasami set of sequences.

nNPolynomialSet
4 15 [4 1 0] Small
6 63 [6 1 0] Large
8 255 [8 4 3 2 0] Small
10 1023 [10 3 0] Large
12 4095 [12 6 4 1 0] Small

## Dialog Box

Generator polynomial

String or binary vector specifying the generator polynomial for the sequence u.

Initial states

Binary scalar or row vector of length equal to the degree of the Generator polynomial, which specifies the initial states of the shift register that generates the sequence u.

Sequence index

Integer or vector specifying the shifts of the sequences v and w used to generate the output sequence.

Shift

Integer scalar that determines the offset of the Kasami sequence from the initial time.

Output variable-size signals

Select this if you want the output sequences to vary in length during simulation. The default selection outputs fixed-length signals.

Maximum output size source

Specify how the block defines maximum output size for a signal.

• When you select `Dialog parameter`, the value you enter in the Maximum output size parameter specifies the maximum size of the output. When you make this selection, the `oSiz` input port specifies the current size of the output signal and the block output inherits sample time from the input signal. The input value must be less than or equal to the Maximum output size parameter.

• When you select ```Inherit from reference port```, the block output inherits sample time, maximum size, and current size from the variable-sized signal at the Ref input port.

This parameter only appears when you select Output variable-size signals. The default selection is ```Dialog parameter```.

Maximum output size

Specify a two-element row vector denoting the maximum output size for the block. The second element of the vector must be 1. For example, [10 1] gives a 10-by-1 maximum sized output signal. This parameter only appears when you select Output variable-size signals.

Sample time

The time between each sample of a column of the output signal.

Samples per frame

The number of samples per frame in one channel of the output signal.

 Note:   The time between output updates is equal to the product of Samples per frame and Sample time. For example, if Sample time and Samples per frame equal one, the block outputs a sample every second. If Samples per frame is increased to 10, then a 10-by-1 vector is output every 10 seconds. This ensures that the equivalent output rate is not dependent on the Samples per frame parameter.
Reset on nonzero input

When selected, you can specify an input signal that resets the internal shift registers to the original values of the Initial states.

Output data type

The output type of the block can be specified as a `boolean` or `double`. By default, the block sets this to `double`.

## Example

### Kasami Spreading with Two Users and Multipath

This model considers Kasami spreading for a combined two-user transmission in a multipath environment.

Open the model here: kasami_sequence_block_example

```modelname = 'kasami_sequence_block_example'; open_system(modelname); sim(modelname);```

You can see very good user separation over multiple paths with the gains of combining. This can be attributed to the "good" correlation properties of Kasami sequences, which provide a balance between the ideal cross-correlation properties of orthogonal codes and the ideal auto-correlation properties of PN sequences. See the relevant examples on the Hadamard Code Generator and PN Sequence Generator reference pages.

To experiment with this model further, try selecting other path delays to see how the performance varies for the same code. Also try different codes with the same delays.

`close_system(modelname, 0);`

## Reference

[1] Peterson and Weldon, Error Correcting Codes, 2nd Ed., MIT Press, Cambridge, MA, 1972.

[2] Proakis, John G., Digital Communications, Third edition, New York, McGraw Hill, 1995.

[3] Sarwate, D. V. and Pursley, M.B., "Crosscorrelation Properties of Pseudorandom and Related Sequences," Proc. IEEE, Vol. 68, No. 5, May 1980, pp. 583-619.