sgnts.transforms.correlate
¶
AdaptiveCorrelate
dataclass
¶
Bases: Correlate
flowchart TD
sgnts.transforms.correlate.AdaptiveCorrelate[AdaptiveCorrelate]
sgnts.transforms.correlate.Correlate[Correlate]
sgnts.base.base.TSTransform[TSTransform]
sgnts.base.base.TimeSeriesMixin[TimeSeriesMixin]
sgnts.transforms.correlate.Correlate --> sgnts.transforms.correlate.AdaptiveCorrelate
sgnts.base.base.TSTransform --> sgnts.transforms.correlate.Correlate
sgnts.base.base.TimeSeriesMixin --> sgnts.base.base.TSTransform
click sgnts.transforms.correlate.AdaptiveCorrelate href "" "sgnts.transforms.correlate.AdaptiveCorrelate"
click sgnts.transforms.correlate.Correlate href "" "sgnts.transforms.correlate.Correlate"
click sgnts.base.base.TSTransform href "" "sgnts.base.base.TSTransform"
click sgnts.base.base.TimeSeriesMixin href "" "sgnts.base.base.TimeSeriesMixin"
Adaptive Correlate filter performs a correlation over a time-dependent set of filters. When the filters are updated, the correlation is performed over both the existing filters and the new filters, then combined using a window function.
Notes
Update frequency:
Only 2 sets of filters are supported at this time. This is equivalent
to requiring that filters can only be updated once per stride. Attempting
to pass more than one update per stride will raise an error.
Update duration:
The filter update is performed across the entire stride. There is not
presently support for more time-domain control of start/stop times for
the blending of filters.
Startup behavior (no explicit initial conditions):
This element no longer accepts explicit initial PSD or initial filters.
On startup, it will emit gap buffers (no data) until a filter bank is
received on the dedicated filters sink pad (filter_sink_name). The first
received filter set becomes the current filters. Subsequent updates are
blended over a stride as described below.
Thread safety:
Marked thread_safe = True. With
Pipeline.run(threaded=N) the pad callbacks for this
element are dispatched onto worker threads.
Pad layout: 2 sink pads (data + filter) + 1 source pad. The
two sink pads' ``pull`` callbacks CAN run concurrently in
the same wave — this is the per-pad concurrency to reason
about. ``internal`` runs alone (single ``InternalPad``).
Where the GIL-releasing work lives: ``internal()`` calls
``scipy.signal.correlate`` (and
``scipy.signal.windows.cosine`` during filter adaptation),
both of which release the GIL — significant speedup
expected when multiple correlation branches run in parallel.
Per-pad concurrency analysis:
- ``pull`` on the **data sink pad**: inherited
``TimeSeriesMixin.pull`` only — writes per-pad-keyed
``inbufs``/``metadata`` for the data pad. Does NOT touch
``self.filter_deque``.
- ``pull`` on the **filter sink pad**: overridden — calls
``super().pull()`` (per-pad-keyed for the filter pad's
own slot), then appends to ``self.filter_deque``. The
filter sink pad is the sole writer of ``self.filter_deque``,
so concurrent same-element pulls cannot produce a
same-deque write race.
- ``internal``: reads ``self.filter_deque`` and may
``popleft`` from it; runs alone (no concurrent reader or
writer in the same wave).
**Future editors MUST preserve thread safety**:
1. Do NOT add new writers to ``self.filter_deque`` from
any ``pull`` path other than the filter sink pad — that
would introduce a same-deque write race across same-wave
pulls.
2. Do NOT introduce additional element-level state mutated
from ``pull`` paths outside of per-pad-keyed containers.
3. ``self.filters`` is reassigned during adaptation in
``internal()``; that is fine because ``internal`` runs
alone, but if you split adaptation logic into ``pull``
you must move ``self.filters`` to per-call local state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_sink_name
|
str
|
str, the name of the sink pad to pull data from |
'filters'
|
Raises:
| Type | Description |
|---|---|
ValueError
|
Raises a value error if more than one filter update is passed per stride |
Source code in src/sgnts/transforms/correlate.py
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 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 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
filters_cur
property
¶
Get the current filters
filters_new
property
¶
Get the new filters
is_adapting
property
¶
Check if the adaptive filter is adapting
static_sink_pads
property
¶
Add the filter sink pad as an static sink pad.
static_unaligned_sink_pads
property
¶
Declare that the filter sink pad is unaligned.
can_adapt(frame)
¶
Check if the buffer can be adapted
Source code in src/sgnts/transforms/correlate.py
internal()
¶
Override internal to perform correlation with both current and new filters when adapting, and just current filters when not adapting.
Source code in src/sgnts/transforms/correlate.py
Correlate
dataclass
¶
Bases: TSTransform
flowchart TD
sgnts.transforms.correlate.Correlate[Correlate]
sgnts.base.base.TSTransform[TSTransform]
sgnts.base.base.TimeSeriesMixin[TimeSeriesMixin]
sgnts.base.base.TSTransform --> sgnts.transforms.correlate.Correlate
sgnts.base.base.TimeSeriesMixin --> sgnts.base.base.TSTransform
click sgnts.transforms.correlate.Correlate href "" "sgnts.transforms.correlate.Correlate"
click sgnts.base.base.TSTransform href "" "sgnts.base.base.TSTransform"
click sgnts.base.base.TimeSeriesMixin href "" "sgnts.base.base.TimeSeriesMixin"
Correlates input data with filters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sample_rate
|
int
|
int, the sample rate of the input data |
required |
filters
|
Optional[Array]
|
Optional[Array], the filter to correlate over. Default is None, which will be treated as the null initial condition (produce gap buffers until filters are provided in the case of AdaptiveCorrelate, or just produce gap buffers in the case of Correlate). This is done to prevent requiring non DRY initial condition/behavior specification for Correlate vs AdaptiveCorrelate, since the latter has a sink pad for filters which will be given a default value by the first frame. |
None
|
latency
|
int
|
int, the latency of the filter in samples |
0
|
Notes
Thread safety:
Marked thread_safe = True. With Pipeline.run(threaded=N)
the pad callbacks (pull, new, internal) for this
element are dispatched onto worker threads.
Pad layout: 1 sink + 1 source pad
(enforced by ``@validator.one_to_one``). There is therefore no
same-element ``pull``/``new`` concurrency to worry about —
only one ``pull`` and one ``new`` ever run at a time on this
element. ``internal`` always runs alone (single
``InternalPad``).
Where the GIL-releasing work lives: ``internal()`` calls
``scipy.signal.correlate``, which releases the GIL — so this
element delivers significant wall-clock speedup when there
are multiple parallel correlation branches in the graph and
their elements all opt in.
State touched per call:
- ``pull`` (inherited ``TimeSeriesMixin.pull``): writes
per-pad-keyed dicts (``inbufs[pad]``, ``metadata[pad]``);
ORs ``self.at_EOS`` (idempotent for booleans).
- ``new`` (inherited ``TSTransform.new``): read-only lookup
in ``self.outframes``.
- ``internal``: reads ``self.filters`` (set in
``configure()`` and read-only afterwards) and
``self.shape``; writes the next output frame.
**Future editors MUST preserve thread safety**: do not
relax the one-to-one constraint without re-auditing
``self.filters`` access. Do not introduce element-level
state that is mutated from ``pull``/``new`` outside of
per-pad-keyed containers.
Source code in src/sgnts/transforms/correlate.py
27 28 29 30 31 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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | |
corr(data)
¶
Correlate an array of data with an array of filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Array
|
Array, the data to correlate with the filters |
required |
Returns:
| Type | Description |
|---|---|
Array
|
Array, the result of the correlation |