sdr.hadamard_code(length: int, index: int, output: 'binary' = 'binary') ndarray[Any, dtype[int64]]
sdr.hadamard_code(length: int, index: int, output: 'field') FieldArray
sdr.hadamard_code(length: int, index: int, output: 'bipolar') ndarray[Any, dtype[float64]]

Generates the Hadamard code/sequence of length \(n = 2^m\).

Parameters:
length: int

The length \(n = 2^m\) of the Hadamard code/sequence.

index: int

The index \(i\) in \([0, n)\) of the Hadamard code.

output: 'binary' = 'binary'
output: 'field'
output: 'bipolar'

The output format of the Hadamard code/sequence.

  • "binary" (default): The Hadamard code with binary values of 0 and 1.

  • "field": The Hadamard code as a Galois field array over \(\mathrm{GF}(2)\).

  • "bipolar": The Hadamard sequence with bipolar values of 1 and -1.

Returns:

The Hadamard code/sequence of length \(n = 2^m\) and index \(i\).

References

Examples

Create a Hadamard code and sequence of length 16.

In [1]: sdr.hadamard_code(16, 4)
Out[1]: array([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1])

In [2]: sdr.hadamard_code(16, 4, output="bipolar")
Out[2]: 
array([ 1.,  1.,  1.,  1., -1., -1., -1., -1.,  1.,  1.,  1.,  1., -1.,
       -1., -1., -1.])

In [3]: sdr.hadamard_code(16, 4, output="field")
Out[3]: GF([0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1], order=2)

The Hadamard and Walsh code sets are equivalent, however they are indexed differently.

In [4]: np.array_equal(sdr.hadamard_code(16, 3), sdr.walsh_code(16, 8))
Out[4]: True

In [5]: np.array_equal(sdr.hadamard_code(16, 11), sdr.walsh_code(16, 9))
Out[5]: True

Hadamard sequences have zero cross-correlation when time aligned.

In [6]: x1 = sdr.hadamard_code(32, 30, output="bipolar"); \
   ...: x2 = sdr.hadamard_code(32, 18, output="bipolar"); \
   ...: x3 = sdr.hadamard_code(32, 27, output="bipolar");
   ...: 

In [7]: plt.figure(); \
   ...: sdr.plot.time_domain(x1 + 3); \
   ...: sdr.plot.time_domain(x2 + 0); \
   ...: sdr.plot.time_domain(x3 - 3)
   ...: 
../../_images/sdr_hadamard_code_1.png

Hadamard sequence auto-correlation sidelobes are not uniform as a function of sequence index. In fact, the sidelobes can be quite high.

In [8]: 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, 32);
   ...: 
../../_images/sdr_hadamard_code_2.png

Hadamard sequences have zero cross-correlation when time aligned. However, the sidelobes can be quite large when time misaligned. Because of this, Hadamard sequences for spreading codes are useful only when precise time information is known.

In [9]: 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, 32);
   ...: 
../../_images/sdr_hadamard_code_3.png