ESPectre SDK 2.8.0-280-gac7af68
Wi-Fi CSI motion sensing for ESP32 firmware
Loading...
Searching...
No Matches
filtered_turbulence_ring.h
Go to the documentation of this file.
1/*
2 * ESPectre - Filtered Turbulence Ring
3 *
4 * Shared filtered ring used by detector feature streams.
5 *
6 * Author: Francesco Pace <francesco.pace@gmail.com>
7 * SPDX-License-Identifier: GPL-3.0-only
8 * Commercial licensing available under separate agreement; see LICENSING.md.
9 */
10#pragma once
11
12#include <cstdint>
13
14#include "filters.h"
15
16namespace espectre {
17
18/** @brief Fixed-capacity turbulence history with optional Hampel and low-pass filtering. */
20 public:
21 /** @brief Construct an unbound history with default filter parameters. */
23
24 /** @brief Attach caller-owned storage and reset the history. */
25 void bind(float *storage, uint16_t capacity);
26 /** @brief Clear samples while preserving the configured filters. */
27 void clear();
28 /** @brief Configure and reset the Hampel filter. */
29 void configure_hampel(bool enabled, uint8_t window_size, float threshold);
30 /** @brief Configure and reset the low-pass filter. */
31 void configure_lowpass(bool enabled, float cutoff_hz);
32 /** @brief Filter and append one turbulence sample. */
33 void add(float turbulence);
34 /** @brief Append missing-sample markers without running the filters. */
36
37 /**
38 * @brief Return the samples in chronological order.
39 * @param scratch Caller-owned storage used only after the ring wraps.
40 * @param scratch_capacity Number of elements available in @p scratch.
41 * @param count Receives the returned element count, or zero when scratch is too small.
42 * @return Internal storage before wrap, @p scratch after wrap, or nullptr when empty or invalid.
43 */
44 const float *ordered_view(float *scratch, uint16_t scratch_capacity, uint16_t &count) const;
45 /** @brief Return the number of occupied slots, including missing markers. */
46 uint16_t count() const { return count_; }
47 /** @brief Return the number of finite samples in the history. */
48 uint16_t valid_count() const { return valid_count_; }
49 /** @brief Return the bound storage capacity. */
50 uint16_t capacity() const { return capacity_; }
51 /** @brief Return whether Hampel filtering is enabled. */
52 bool hampel_enabled() const { return hampel_state_.enabled; }
53
54 private:
55 float *storage_{nullptr};
56 uint16_t capacity_{0U};
57 uint16_t index_{0U};
58 uint16_t count_{0U};
59 uint16_t valid_count_{0U};
60 hampel_filter_state_t hampel_state_{};
61 lowpass_filter_state_t lowpass_state_{};
62};
63
64} // namespace espectre
void bind(float *storage, uint16_t capacity)
Attach caller-owned storage and reset the history.
uint16_t capacity() const
Return the bound storage capacity.
uint16_t count() const
Return the number of occupied slots, including missing markers.
const float * ordered_view(float *scratch, uint16_t scratch_capacity, uint16_t &count) const
Return the samples in chronological order.
void add(float turbulence)
Filter and append one turbulence sample.
FilteredTurbulenceRing()
Construct an unbound history with default filter parameters.
bool hampel_enabled() const
Return whether Hampel filtering is enabled.
void configure_hampel(bool enabled, uint8_t window_size, float threshold)
Configure and reset the Hampel filter.
void configure_lowpass(bool enabled, float cutoff_hz)
Configure and reset the low-pass filter.
void clear()
Clear samples while preserving the configured filters.
uint16_t valid_count() const
Return the number of finite samples in the history.
void advance_missing_slots(uint32_t count)
Append missing-sample markers without running the filters.
hampel_turbulence_state_t hampel_filter_state_t
Definition filters.h:52