-
sdr.gold_code(length: int, index: int =
0
, poly1: PolyLike | None =None
, poly2: PolyLike | None =None
, verify: bool =True
, output: 'binary' ='binary'
) ndarray[Any, dtype[int64]] -
sdr.gold_code(length: int, index: int =
0
, poly1: PolyLike | None =None
, poly2: PolyLike | None =None
, verify: bool =True
, output: 'field' ='binary'
) FieldArray -
sdr.gold_code(length: int, index: int =
0
, poly1: PolyLike | None =None
, poly2: PolyLike | None =None
, verify: bool =True
, output: 'bipolar' ='binary'
) ndarray[Any, dtype[float64]] Generates the Gold code/sequence of length \(n = 2^m - 1\).
- Parameters:¶
- length: int¶
The length \(n = 2^m - 1\) of the Gold code/sequence.
- index: int =
0
¶ The index \(i\) in \([-2, n)\) of the Gold code.
- poly1: PolyLike | None =
None
¶ The primitive polynomial of degree \(m\) over \(\mathrm{GF}(2)\) for the first \(m\)-sequence. If
None
, a preferred pair is found usingsdr.preferred_pairs()
.- poly2: PolyLike | None =
None
¶ The primitive polynomial of degree \(m\) over \(\mathrm{GF}(2)\) for the second \(m\)-sequence. If
None
, a preferred pair is found usingsdr.preferred_pairs()
.- verify: bool =
True
¶ Indicates whether to verify that the provided polynomials are a preferred pair using
sdr.is_preferred_pair()
.- output: 'binary' =
'binary'
¶ - output: 'field' =
'binary'
- output: 'bipolar' =
'binary'
The output format of the Gold code/sequence.
"binary"
(default): The Gold code with binary values of 0 and 1."field"
: The Gold code as a Galois field array over \(\mathrm{GF}(2)\)."bipolar"
: The Gold sequence with bipolar values of 1 and -1.
- Returns:¶
The Gold code/sequence of length \(n = 2^m - 1\) and index \(i\).
See also
Notes
Gold codes are generated by combining two preferred pair \(m\)-sequences, \(u\) and \(v\), using the formula
\[\begin{split} c = \begin{cases} u & \text{if $i = -2$} \\ v & \text{if $i = -1$} \\ u \oplus T^i v & \text{otherwise} , \end{cases} \end{split}\]where \(i\) is the code index, \(\oplus\) is addition in \(\mathrm{GF}(2)\) (or the XOR operation), and \(T^i\) is a left shift by \(i\) positions.
Gold codes are PN sequence with good auto-correlation and cross-correlation properties. The Gold code set contains \(2^m + 1\) sequences of length \(2^m - 1\). The correlation sides are guaranteed to be less than or equal to \(t(m)\).
\[\begin{split} t(m) = \begin{cases} 2^{(m+1)/2} + 1 & \text{if $m$ is odd} \\ 2^{(m+2)/2} + 1 & \text{if $m$ is even} \end{cases} \end{split}\]There are no preferred pairs with degree \(m\) divisible by 4. Therefore, there are no Gold codes with degree \(m\) divisible by 4.
References
John Proakis, Digital Communications, Chapter 12.2-5: Generation of PN Sequences.
Examples
Create a Gold code and sequence of length 7.
In [1]: sdr.gold_code(7, 1) Out[1]: array([1, 0, 1, 0, 1, 1, 0]) In [2]: sdr.gold_code(7, 1, output="bipolar") Out[2]: array([-1., 1., -1., 1., -1., -1., 1.]) In [3]: sdr.gold_code(7, 1, output="field") Out[3]: GF([1, 0, 1, 0, 1, 1, 0], order=2)
Create several Gold codes of length 63.
In [4]: x1 = sdr.gold_code(63, 0, output="bipolar"); \ ...: x2 = sdr.gold_code(63, 1, output="bipolar"); \ ...: x3 = sdr.gold_code(63, 2, output="bipolar"); ...: In [5]: plt.figure(); \ ...: sdr.plot.time_domain(x1 + 3); \ ...: sdr.plot.time_domain(x2 + 0); \ ...: sdr.plot.time_domain(x3 - 3) ...:
Examine the auto-correlation of the Gold sequences.
In [6]: plt.figure(); \ ...: sdr.plot.correlation(x1, x1, mode="circular"); \ ...: sdr.plot.correlation(x2, x2, mode="circular"); \ ...: sdr.plot.correlation(x3, x3, mode="circular"); \ ...: plt.ylim(0, 63); ...:
Examine the cross-correlation of the Gold sequences.
In [7]: plt.figure(); \ ...: sdr.plot.correlation(x1, x2, mode="circular"); \ ...: sdr.plot.correlation(x1, x3, mode="circular"); \ ...: sdr.plot.correlation(x2, x3, mode="circular"); \ ...: plt.ylim(0, 63); ...: