xwr.rsp
¶
Radar Signal Processing for batched 4D spectrum.
Image Axis Order
Elevation and azimuth axes are in "image order": increasing index is down and to the right, respectively.
Byte order: when do I sample_swap?
If you are using the xwr stack, use the default sample_swap=False,
which corresponds to MSB_LSB_IQ, the only
option supported by the source-available TI firmware. If processing data
collected using other systems (in particular, mmWave studio, which has its
own closed-source firmware which supports MSB_LSB_QI), you may need to
set sample_swap=True if this option was enabled.
To use the RSP:
-
Pick your backend. Currently, we support numpy, jax, and pytorch.
-
Select the appropriate radar model.
-
Import the RSP class matching your backend and radar:
Tip
Use
xwr.rsp.RSPas the type for a generic RSP, andRSP[np.ndarray],RSP[jax.Array],RSP[torch.Tensor], etc for a RSP with a specific backend. -
If point cloud processing is desired, use the matching
CFARclass for your backend.Note
We currently provide implementations of
CA-CFARandCFAR-CASOfor each backend.
xwr.rsp.SignalCube
module-attribute
¶
SignalCube = (
Float[TArray, "batch doppler tx rx range"]
| Float[TArray, "batch doppler range"]
| Float[TArray, "batch doppler el az range"]
)
Accepted detector input. A virtual array cube, an angle spectrum, or an already-combined range-doppler image.
xwr.rsp.CACFAR
¶
Cell-averaging CFAR.
┌─────────────────┐ ▲ guard[0]+train[0]
│ ┌───────┐ │ │
│ │ ┌─┐ │ │ ▼
│ │ └─┘ │ │ ▲ guard[0]
│ └───────┘ │ ▼
└─────────────────┘
guard[1] ◄──► ◄───────► guard[1]+train[1]
Implementation notes:
- The noise floor is the mean of the training cells in the 2D ring.
traincan be0on at most one axis.- A cell is detected when its integrated power exceeds
snr_thresh * noise.
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
tuple[int, int]
|
guard cells on each side of the cell under test, for (range, doppler). |
(2, 2)
|
train
|
tuple[int, int]
|
training cells on each side of the guard region, for (range, doppler). |
(2, 2)
|
snr_thresh
|
float
|
detection threshold, as a linear power ratio (not dB). |
5.0
|
discard_range
|
tuple[int, int]
|
range bins (close, far) to discard around DC. |
(10, 20)
|
Source code in src/xwr/rsp/spectrum.py
xwr.rsp.CASOCFAR
¶
Cell-averaging Smallest of CFAR.
Info
Instead of the 2D kernel used in CACFAR, CASO uses a
separate 1D kernel for the range and doppler axes, and reports a
detection only where both axes fire.
┌─┐ ▲ train[0]
│ │ │
├─┤ ▼
┌───┬─┼─┼─┬───┐
└───┴─┼─┼─┴───┘ ▲ guard[0]
├─┤ ▼
│ │
└─┘
guard[1] ◄─► ◄───► train[1]
Implementation notes:
- On each axis, CASO takes the minimum of the two one-sided means, so
a strong target on one side cannot inflate the noise floor and mask a
weaker target on the other. As such,
trainmust be>= 1on both axes. - An axis fires where its integrated power exceeds that axis's
snr_thresh * noise. Both axes must fire for a detection to be reported.
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
tuple[int, int]
|
guard cells on each side of the cell under test, for (range, doppler). |
(8, 0)
|
train
|
tuple[int, int]
|
training cells on each side of the guard region, for (range, doppler). |
(8, 4)
|
snr_thresh
|
tuple[float, float]
|
detection threshold for (range, doppler), as a linear power ratio (not dB). |
(5.0, 3.0)
|
discard_range
|
tuple[int, int]
|
range bins (close, far) to discard around DC. |
(10, 20)
|
Source code in src/xwr/rsp/spectrum.py
xwr.rsp.CFAR
¶
Abstract, backend-agnostic CFAR base class.
The following implementations are available:
| Detector | Noise estimate |
|---|---|
CACFAR |
2D cell-averaging ring |
CASOCFAR |
Separate "smallest of" tests on the range and doppler axes |
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
guard
|
tuple[int, int]
|
guard cells on each side of the cell under test, for (range, doppler). |
required |
train
|
tuple[int, int]
|
training cells on each side of the guard region, for (range, doppler). |
required |
discard_range
|
tuple[int, int]
|
range bins (close, far) to discard around DC. |
(10, 20)
|
Source code in src/xwr/rsp/spectrum.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
__call__
¶
__call__(signal_cube: SignalCube) -> Detection[TArray]
Run 2D CFAR detection.
Note
The channel axes (the transmit and receive antennas of the virtual array, or the elevation and azimuth bins of an angle spectrum) are combined non-coherently, so their relative order does not matter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
signal_cube
|
SignalCube
|
batch of post range doppler FFT radar cubes in amplitude, or a range-doppler image which is already combined across the virtual array. |
required |
Returns:
| Type | Description |
|---|---|
Detection[TArray]
|
The detection mask, the range-doppler spectrum it was computed from, and the signal to noise ratio. |
Source code in src/xwr/rsp/spectrum.py
xwr.rsp.DensePoints
dataclass
¶
Bases: Generic[TArray]
A dense radar point cloud, and the points in it which are valid.
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Attributes:
| Name | Type | Description |
|---|---|---|
mask |
Bool[TArray, 'batch range doppler']
|
mask of valid points, i.e. the CFAR detection mask combined with
the angular bounds set by |
points |
Float32[TArray, 'batch range doppler 4']
|
all possible radar points, where the trailing axis holds
|
Source code in src/xwr/rsp/aoa.py
xwr.rsp.Detection
dataclass
¶
Bases: Generic[TArray]
Detected objects, and the statistics they were detected from.
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Attributes:
| Name | Type | Description |
|---|---|---|
mask |
Bool[TArray, 'batch range doppler']
|
cfar detected object mask. |
signal |
Float[TArray, 'batch range doppler']
|
non-coherently integrated power across the channel axes, i.e. the range-doppler spectrum used for detection. |
snr |
Float[TArray, 'batch range doppler']
|
signal to noise ratio, as a linear power ratio. |
Source code in src/xwr/rsp/spectrum.py
xwr.rsp.PointCloud
¶
Get radar point cloud from post FFT cube.
To convert azimuth-elevation bin indices to azimuth-elevation angles, we use the property that the azimuth bin indices correspond to the sin of the angle
where the corrected antenna spacing is calculated byInfo
The antenna design frequency here refers to the grid alignment of the antenna array, which are typically 0.5 wavelengths apart at some nominal design frequency. Thus, you must correct by a corresponding scale factor when the chirp center frequency differs.
Implementation notes:
- With the default range and dopplerresolutions of
1.0, the point cloud is in range/doppler bins instead of meters and meters/second. - Radars have little resolving power close to the array plane in angle,
and suffer from high noise at the edge of the main lobe. Reject these
points with
angle_fov.
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
range_res
|
float
|
range resolution, i.e. meters per range bin; see
|
1.0
|
doppler_res
|
float
|
doppler resolution, i.e. meters/second per doppler bin;
see |
1.0
|
angle_fov
|
tuple[float, float]
|
(elevation, azimuth) field of view in degrees, where points outside +/-elevation and +/-azimuth are rejected. |
(20.0, 80.0)
|
antenna_spacing
|
float
|
antenna spacing in terms of wavelength (default 0.5 for a half-wavelength grid). |
0.5
|
Source code in src/xwr/rsp/aoa.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
__call__
abstractmethod
¶
__call__(
cube: Float32[TArray, "batch doppler el az range"],
mask: Bool[TArray, "batch range doppler"],
) -> DensePoints[TArray]
Get point cloud from radar cube and detection mask.
Note
The returned point cloud is dense: every range-doppler bin
yields a point, and the caller is expected to gather the valid
ones using the returned mask (e.g. pc[pc_mask]).
Implementation notes:
- Return points are multiplied by
range_resanddoppler_resto convert from bins to meters and meters/second, respectively. - Points position compute as
x = r cos(-az) cos(el),y = r sin(-az) cos(el), andz = r sin(el)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cube
|
Float32[TArray, 'batch doppler el az range']
|
batch of post fft spectrum amplitudes. |
required |
mask
|
Bool[TArray, 'batch range doppler']
|
CFAR detection mask. |
required |
Returns:
| Type | Description |
|---|---|
DensePoints[TArray]
|
The dense point cloud, and the mask of points in it which are
valid; see |
Source code in src/xwr/rsp/aoa.py
aoa
abstractmethod
¶
Angle of arrival estimation.
Takes the argmax over the (elevation, azimuth) angle spectrum of each range-doppler bin, yielding bin indices into the angle axes rather than angles.
Warning
This assumes at most one scatterer per range-doppler cell; if two targets share a range and velocity, only the stronger is reported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cube
|
Float32[TArray, 'batch range doppler el az']
|
batch of post fft spectrum amplitudes, with the angle axes trailing. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ang |
Int[TArray, 'batch range doppler 2']
|
detect angle index for every range doppler bin, as
|
Source code in src/xwr/rsp/aoa.py
xwr.rsp.RSP
¶
Abstract, backend-agnostic Radar Signal Processing base class.
Info
This class documents the public interface for all radar signal processing (RSP) classes, except where otherwise noted.
Type Parameters
TArray: Generic backend, e.g.,np.ndarray, jaxjax.Array, or torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
window
|
bool | Mapping[Literal['range', 'doppler', 'azimuth', 'elevation'], bool]
|
whether to apply a hanning window. If |
False
|
size
|
Mapping[Literal['range', 'doppler', 'azimuth', 'elevation'], int]
|
target size for each axis after zero-padding, specified by axis. If an axis is not spacified, it is not padded. |
{}
|
sample_swap
|
bool
|
if |
False
|
Source code in src/xwr/rsp/generic.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
__call__
¶
__call__(
x: Complex64[TArray, "#batch doppler tx rx _range"]
| Float32[TArray, "#batch doppler tx rx _range"]
| Int16[TArray, "#batch doppler tx rx _range"],
) -> Complex64[TArray, "#batch doppler2 el az _range"]
Process time signal data to compute elevation-azimuth spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Complex64[TArray, '#batch doppler tx rx _range'] | Float32[TArray, '#batch doppler tx rx _range'] | Int16[TArray, '#batch doppler tx rx _range']
|
IQ data in complex or interleaved int16 IQ format, or in-phase-only data in float32 format. |
required |
Returns:
| Type | Description |
|---|---|
Complex64[TArray, '#batch doppler2 el az _range']
|
Computed doppler-elevation-azimuth-range spectrum. |
Source code in src/xwr/rsp/generic.py
doppler_range
¶
doppler_range(
x: Complex64[TArray, "#batch doppler tx rx range"]
| Float32[TArray, "#batch doppler tx rx range"],
) -> Complex64[TArray, "#batch doppler2 tx rx range2"]
Calculate range-doppler spectrum from time signal data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Complex64[TArray, '#batch doppler tx rx range'] | Float32[TArray, '#batch doppler tx rx range']
|
IQ (complex64) or in-phase-only (float32) data. |
required |
Returns:
| Type | Description |
|---|---|
Complex64[TArray, '#batch doppler2 tx rx range2']
|
Computed range-doppler spectrum, with windowing if specified. |
Source code in src/xwr/rsp/generic.py
elevation_azimuth
¶
elevation_azimuth(
rd: Complex64[TArray, "#batch doppler tx rx range"],
) -> Complex64[TArray, "#batch doppler el az range"]
Calculate elevation-azimuth spectrum from range-doppler spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rd
|
Complex64[TArray, '#batch doppler tx rx range']
|
range-doppler spectrum. |
required |
Returns:
| Type | Description |
|---|---|
Complex64[TArray, '#batch doppler el az range']
|
Computed elevation-azimuth spectrum, with windowing and padding if specified. |
Source code in src/xwr/rsp/generic.py
fft
abstractmethod
¶
fft(
array: Complex64[TArray, ...] | Float32[TArray, ...],
axes: tuple[int, ...],
size: tuple[int, ...] | None = None,
shift: tuple[int, ...] | None = None,
) -> Complex64[TArray, ...]
Compute FFT on the specified axes of the array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
Complex64[TArray, ...] | Float32[TArray, ...]
|
Input array. |
required |
size
|
tuple[int, ...] | None
|
Target size for each axis after FFT (or |
None
|
axes
|
tuple[int, ...]
|
Axes along which to compute the FFT. |
required |
shift
|
tuple[int, ...] | None
|
Axes to shift after FFT, if any. |
None
|
Returns:
| Type | Description |
|---|---|
Complex64[TArray, ...]
|
FFT of the input array along the specified axes. If the input
array is real-valued, the output is the non-negative frequency
terms of the FFT along the specified axes (with length
|
Source code in src/xwr/rsp/generic.py
hann
abstractmethod
staticmethod
¶
hann(
x: Complex64[TArray, ...] | Float32[TArray, ...], axis: int
) -> Complex64[TArray, ...] | Float32[TArray, ...]
Apply a Hann window to the specified axis of the time signal data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Complex64[TArray, ...] | Float32[TArray, ...]
|
time signal data. |
required |
axis
|
int
|
Axis along which to apply the Hann window. |
required |
Returns:
| Type | Description |
|---|---|
Complex64[TArray, ...] | Float32[TArray, ...]
|
Time signal data with the Hann window applied along the specified axis. |
Source code in src/xwr/rsp/generic.py
mimo_virtual_array
abstractmethod
¶
mimo_virtual_array(
rd: Complex64[TArray, "#batch doppler tx rx range"],
) -> Complex64[TArray, "#batch doppler elevation azimuth range"]
Set up MIMO virtual array from range-doppler spectrum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rd
|
Complex64[TArray, '#batch doppler tx rx range']
|
complex range-doppler spectrum. |
required |
Returns:
| Type | Description |
|---|---|
Complex64[TArray, '#batch doppler elevation azimuth range']
|
Computed MIMO virtual array, in elevation-azimuth order. |
Source code in src/xwr/rsp/generic.py
xwr.rsp.iq_from_iiqq
¶
iq_from_iiqq(
iiqq: Int16[TArray, "... n"] | Complex64[TArray, "... _n"],
sample_swap: bool = False,
) -> Complex64[TArray, "... n2"]
Un-interleave IIQQ data.
Info
The default sample_swap = False corresponds to the
MSB_LSB_IQ byte order used by xwr.
In this case, MSB_LSB_IQ means that I is the MSB and Q is the LSB.
However, the data stream is little-endian, which means Q actually comes
before I, leading to the actual physical layout being QQII and so on.
Type Parameters
TArray: This function is multi-backend, and supports numpynp.ndarray, jaxjax.Array, and torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iiqq
|
Int16[TArray, '... n'] | Complex64[TArray, '... _n']
|
interleaved IIQQ data; see |
required |
sample_swap
|
bool
|
if |
False
|
Returns:
| Type | Description |
|---|---|
Complex64[TArray, '... n2']
|
Complex IQ data. |
Source code in src/xwr/rsp/generic.py
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |
xwr.rsp.iqiq_from_iiqq
¶
iqiq_from_iiqq(
iiqq: Int16[TArray, "... n"], sample_swap: bool = False
) -> Int16[TArray, "... n/2 2"]
Un-interleave IIQQ data.
Type Parameters
TArray: This function is multi-backend, and supports numpynp.ndarray, jaxjax.Array, and torchTensor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
iiqq
|
Int16[TArray, '... n']
|
interleaved IIQQ data; see |
required |
sample_swap
|
bool
|
if |
False
|
Returns:
| Type | Description |
|---|---|
Int16[TArray, '... n/2 2']
|
IQ data in an uninterleaved format with a trailing I/Q axis. |