24. Null Steering and LMS¶
Beamforming and Direction of Arrival reproduced PySDR’s three scans: conventional, MVDR and MUSIC. PySDR’s DOA chapter has two more ways to choose an array’s weights. Null steering points the beam at the signal of interest and places nulls at given angles, without looking at the received signal. LMS (Widrow’s least mean squares) learns the weights sample by sample from a known part of the signal of interest. This chapter does both in C++, with the array size as a template parameter as before. The null steering runs at compile time, and doing it there turns up a problem with PySDR’s procedure. The LMS port reproduces PySDR’s example to rounding, and the second half of the chapter asks what PySDR’s step size means.
The code is in code/include/cppsdr/adaptive.hpp and code/tests/test_adaptive.cpp. figure-generating-scripts/lms_reference.py runs PySDR’s LMS example.
Null Steering, One Null at a Time¶
PySDR’s recipe starts with the conventional beam \(w\) towards the signal of interest. For each null direction with steering vector \(a\), it applies the “sidelobe-canceler equation”:
In words, it subtracts from \(w\) its component along \(a\). Afterwards \(a^H w = 0\), so the array has no response in that direction. The example uses 8 elements, the beam at 30°, and nulls at −60°, −30°, 0° and 60°. In C++ the whole procedure is constexpr (steering_ct computes the steering vector with the book’s constexpr sine and cosine), so the compiler can check the nulls:
constexpr std::array<double, 4> nulls{-60 * deg, -30 * deg, 0 * deg, 60 * deg};
constexpr auto w_seq = doa::null_steer_sequential<8>(30 * deg, nulls);
static_assert(relative(w_seq, 60 * deg) < 1e-28, "sequential: the last null is exact ...");
static_assert(relative(w_seq, -60 * deg) > 1e-5 && relative(w_seq, -30 * deg) > 1e-3 && relative(w_seq, 0 * deg) > 5e-4,
"... but the first three are left at about -45, -29 and -30 dB");
Only the last null is a null. Each update removes the component along its own null direction but adds a little along the earlier ones, because the steering vectors of different angles are not orthogonal. The responses relative to the beam are:
null at |
PySDR, one at a time |
all at once |
|---|---|---|
−60° |
−44.8 dB |
−321 dB |
−30° |
−28.9 dB |
−330 dB |
0° |
−30.2 dB |
−327 dB |
60° |
−318 dB |
−318 dB |
PySDR’s plot ends at −40 dB, so the shallow nulls still show as dips. The text says that with too few elements “you either don’t have nulls/beam exactly where you intend, or it may not be able to fit the criteria at all due to a lack of degrees of freedom”. Eight elements have seven degrees of freedom, enough for four exact nulls. The shortfall here comes from the order of the updates.
The fix is to remove the component of \(w\) in the span of all null directions at once. An orthonormal basis \(q_1, \dots, q_K\) of the null steering vectors, from modified Gram-Schmidt, makes that a sum of independent projections:
template <std::size_t M, std::size_t K>
constexpr cvec<M> null_steer(double theta_soi, std::array<double, K> const& nulls, double d = 0.5)
{
static_assert(K < M, "an M-element array has M - 1 degrees of freedom for nulls");
std::array<cvec<M>, K> q{};
for (std::size_t i = 0; i < K; ++i) {
q[i] = steering_ct<M>(nulls[i], d);
for (std::size_t j = 0; j < i; ++j) { // remove the directions already in the basis
const cd c = inner(q[j], q[i]);
for (std::size_t k = 0; k < M; ++k) q[i][k] -= c * q[j][k];
}
const double len = cx::sqrt(inner(q[i], q[i]).real());
for (auto& x : q[i]) x /= len;
}
cvec<M> w = steering_ct<M>(theta_soi, d);
for (std::size_t j = 0; j < K; ++j) { // and project them out of the beam
const cd c = inner(q[j], w);
for (std::size_t k = 0; k < M; ++k) w[k] -= c * q[j][k];
}
return w;
}
The result is orthogonal to every null steering vector, so every null is exact; the test asserts all four below \(10^{-28}\) at compile time. It is also the weight vector closest to the conventional beam that has these nulls. The array-size check that PySDR’s text mentions becomes a static_assert: asking an 8-element array for 8 nulls does not compile.
LMS, Sample by Sample¶
PySDR’s LMS example receives a repeating 127-chip Gold code (the signal of interest, from 20°) and two tones (from 60° and −50°) on 8 elements. The noise has amplitude 0.5. With the beamformer output \(y = w^H x\) and the known chip \(d\), each sample applies
which steps along the negative gradient of the squared error \(|d - w^H x|^2\), with \(\mu = 0.5 \times 10^{-5}\). In C++ the state is one fixed-size vector:
template <std::size_t M>
class lms {
public:
explicit lms(double mu) : mu_(mu) {}
cd step(cvec<M> const& x, cd desired)
{
const cd e = desired - inner(w_, x);
const cd g = mu_ * std::conj(e);
for (std::size_t k = 0; k < M; ++k) w_[k] += g * x[k];
return e;
}
...
private:
double mu_;
cvec<M> w_{};
};
PySDR draws its noise with np.random.randn, so the reference script replaces only that line. It uses the book’s normal generator from Noise, Random Numbers and Statistics, written out in NumPy: std::mt19937_64 and Marsaglia’s polar method. The C++ test can then regenerate the identical 100 000 × 8 input instead of reading 13 MB from a file. The test first checks that the two generators agree bit for bit. After 100 000 samples, the weights equal PySDR’s to \(2.8 \times 10^{-16}\) (relative), and the squared errors at seven points along the way to \(4.9 \times 10^{-16}\).
What the Step Size Means¶
How fast LMS converges depends on the eigenvalues \(\lambda_i\) of the covariance matrix \(R\) of the input. Each eigen-direction of the weight error decays like \((1 - \mu\lambda_i)^n\), with time constant \(1/(\mu\lambda_i)\) samples, and LMS is stable only for \(\mu < 2/\lambda_\text{max}\). In PySDR’s scene the true \(R\) has three large eigenvalues, 6.57, 8.16 and 10.76, one for each signal, and five noise eigenvalues of 0.5. So:
PySDR’s \(\mu\) is 37 000 times below the stability limit of 0.186;
the signal directions converge with time constants of 18 600 to 30 400 samples;
the noise directions converge with 400 000. They start at zero, which is where the optimum has them, since \(p = E[x\,d^*]\) lies in the signal directions, so they do not matter here.
The output SINR, the power of the signal of interest over interference plus noise after the weights, shows the convergence. It can be computed exactly for any weight vector because the scene’s statistics are known (doa::scene). The best possible value is \(s^H R_\text{in}^{-1} s = 11.98\) dB.
weights |
output SINR |
|---|---|
LMS, \(\mu = 0.5 \times 10^{-5}\), after 1 000 samples |
9.27 dB |
LMS, after 10 000 samples |
11.27 dB |
LMS, after 100 000 samples |
11.97 dB |
NLMS, \(\tilde\mu = 0.05\), after 1 000 samples |
11.87 dB |
\(R^{-1}p\) from the first 32 snapshots |
10.84 dB |
\(R^{-1}p\) from the first 64 snapshots |
11.48 dB |
\(R^{-1}p\) from the first 256 snapshots |
11.77 dB |
The normalized LMS divides the step by the energy of the current snapshot, \(\mu = \tilde\mu / \|x\|^2\), so the step no longer depends on how strong the input is. With \(\tilde\mu = 0.05\) it is within 0.11 dB of the optimum after 1 000 samples, where PySDR’s fixed step is 2.7 dB short.
The last three rows are the block solution LMS converges to, solved directly. They estimate \(R\) and \(p = E[x\,d^*]\) from the first \(K\) snapshots and their known chips, then solve \(Rw = p\) with the Cholesky factorization of Beamforming and Direction of Arrival (sample-matrix inversion). 64 snapshots come within half a dB, which LMS with PySDR’s step size takes between 10 000 and 100 000 samples to reach. The price is an \(M \times M\) factorization per update, \(O(M^3)\) instead of LMS’s \(O(M)\) per sample. For the 8 to 16 elements of an SDR array that is cheap. These numbers come from one noise realization, so the values for small \(K\) would scatter from run to run.
Key Takeaways¶
PySDR’s null steering applies the sidelobe-canceler update once per null. Only the last null comes out exact; on PySDR’s example the others stay at −29 to −45 dB. Projecting out the span of all null directions at once (Gram-Schmidt) makes every null exact, and in C++ the compiler can check that.
Null steering is a pure function of the geometry, so it can be
constexpr, and “at most \(M-1\) nulls” can be astatic_assert.PySDR’s LMS example is reproduced to \(3 \times 10^{-16}\). Sharing a noise generator between the Python reference and the C++ test replaces 13 MB of test data with a seed.
The LMS step size sets the time constants \(1/(\mu\lambda_i)\). PySDR’s step is 37 000 times below the stability limit and needs 10 000 to 100 000 samples. Normalized LMS, or solving \(R^{-1}p\) from 64 snapshots, gets within half a dB much sooner.