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

Returns the Walsh code/sequence of length \(N\).

Parameters:
length: int

The length \(N\) of the Walsh code/sequence. Must be a power of 2.

index: int

The index \(i\) in \([0, N)\) of the Walsh code. Indicates how many transitions there are in the code.

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

The output format of the Walsh code/sequence.

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

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

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

Returns:

The Walsh code/sequence of length \(N\) and index \(i\).

References

Examples

Create a Walsh code and sequence of length 16. The code index 4 indicates that there are 4 transitions in the code.

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

In [2]: sdr.walsh_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.walsh_code(16, 4, output="field")
Out[3]: GF([0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0], 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

Walsh sequences have zero cross correlation when time aligned.

In [6]: seq1 = sdr.walsh_code(32, 4, output="bipolar"); \
   ...: seq2 = sdr.walsh_code(32, 10, output="bipolar"); \
   ...: seq3 = sdr.walsh_code(32, 15, output="bipolar");
   ...: 

In [7]: plt.figure(); \
   ...: sdr.plot.time_domain(seq1 + 3, label="Index 4"); \
   ...: sdr.plot.time_domain(seq2 + 0, label="Index 10"); \
   ...: sdr.plot.time_domain(seq3 - 3, label="Index 15")
   ...: 
../../_images/sdr_walsh_code_1.png

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

In [8]: lag = np.arange(-seq1.size + 1, seq1.size); \
   ...: xcorr12 = np.correlate(seq1, seq2, mode="full"); \
   ...: xcorr13 = np.correlate(seq1, seq3, mode="full"); \
   ...: xcorr23 = np.correlate(seq2, seq3, mode="full");
   ...: 

In [9]: plt.figure(); \
   ...: sdr.plot.time_domain(lag, np.abs(xcorr12), label="4 and 10"); \
   ...: sdr.plot.time_domain(lag, np.abs(xcorr13), label="4 and 15"); \
   ...: sdr.plot.time_domain(lag, np.abs(xcorr23), label="10 and 15"); \
   ...: plt.xlabel("Lag"); \
   ...: plt.title("Cross correlation of length-32 Walsh sequences");
   ...: 
../../_images/sdr_walsh_code_2.png

Walsh sequence autocorrelation sidelobes are not uniform as a function of sequence index. In fact, the sidelobes can be quite high.

In [10]: lag = np.arange(-seq1.size + 1, seq1.size); \
   ....: acorr1 = np.correlate(seq1, seq1, mode="full"); \
   ....: acorr2 = np.correlate(seq2, seq2, mode="full"); \
   ....: acorr3 = np.correlate(seq3, seq3, mode="full");
   ....: 

In [11]: plt.figure(); \
   ....: sdr.plot.time_domain(lag, np.abs(acorr1), label="Index 4"); \
   ....: sdr.plot.time_domain(lag, np.abs(acorr2), label="Index 10"); \
   ....: sdr.plot.time_domain(lag, np.abs(acorr3), label="Index 15"); \
   ....: plt.xlabel("Lag"); \
   ....: plt.title("Autocorrelation of length-32 Walsh sequences");
   ....: 
../../_images/sdr_walsh_code_3.png