Go to the documentation of this file.
33 #define SENSOR_ID (1U)
34 #define SENSOR_TIMEOUT_MS (1000U)
36 #define ACC_ALGORITHM_APPROX_BASE_STEP_LENGTH_M (2.5e-3f)
38 #define DEFAULT_PRESET_CONFIG BREATHING_PRESET_SITTING
40 #define B_STATIC_LENGTH (3U)
41 #define A_STATIC_LENGTH (2U)
42 #define B_ANGLE_LENGTH (5U)
43 #define A_ANGLE_LENGTH (4U)
228 bool *recalibration_done);
253 printf(
"acc_config_create() failed\n");
262 printf(
"Failed to validate config\n");
269 printf(
"Failed to initialize handle\n");
274 uint32_t sleep_time_ms = (uint32_t)(1000.0f / handle.
frame_rate);
279 printf(
"Failed to initialize sensor resources\n");
286 bool recalibration_done =
false;
290 printf(
"enter_hibernate failed\n");
297 if (!
measure(&handle, &presence_result))
309 if (recalibration_done)
311 recalibration_done =
false;
342 printf(
"Application finished OK\n");
359 if (handle->
sensor != NULL)
369 if (handle->
buffer != NULL)
394 if (handle->
angle != NULL)
500 if (frame_rate == 0.0f)
502 printf(
"Frame rate must be set, i.e. > 0.0\n");
508 printf(
"Lowest breathing rate must be lower than highest breathing rate\n");
514 printf(
"Number of distances to analyze must be higher than 1");
534 printf(
"acc_detector_presence_create() failed\n");
571 handle->
first =
true;
633 if (handle->
sensor == NULL)
635 printf(
"acc_sensor_create() failed\n");
641 printf(
"Sensor calibration failed\n");
649 printf(
"acc_detector_presence_prepare() failed\n");
660 bool cal_complete =
false;
661 const uint16_t calibration_retries = 1U;
664 for (uint16_t i = 0; !status && (i <= calibration_retries); i++)
674 if (status && !cal_complete)
678 }
while (status && !cal_complete);
689 printf(
"acc_sensor_calibrate() failed\n");
703 handle->
first =
true;
726 printf(
"exit_hibernate failed\n");
732 printf(
"acc_sensor_measure failed\n");
739 printf(
"Sensor interrupt timeout\n");
746 printf(
"acc_sensor_read() failed\n");
753 printf(
"enter_hibernate failed\n");
759 printf(
"acc_detector_presence_process() failed\n");
773 printf(
"acc_sensor_hibernate_on failed\n");
790 printf(
"acc_sensor_hibernate_off failed\n");
880 uint16_t center_idx =
882 start_p = center_idx >=
939 handle->
first =
false;
953 if ((
float)
M_PI < angle_diff)
955 angle_diff -= 2.0f * (float)
M_PI;
957 else if (angle_diff < -(
float)
M_PI)
959 angle_diff += 2.0f * (float)
M_PI;
993 float lp_filt_ampl_sum = 0U;
1049 printf(
"NO_PRESENCE_DETECTED\n");
1052 printf(
"INTRA_PRESENCE_DETECTED\n");
1055 printf(
"DETERMINE_DISTANCE_ESTIMATE\n");
1058 printf(
"ESTIMATE_BREATHING_RATE\n");
1076 bool *recalibration_done)
1080 printf(
"Data saturated. The detector result is not reliable.\n");
1085 printf(
"Frame delayed. Could not read data fast enough.\n");
1086 printf(
"Try lowering the frame rate or call 'acc_sensor_read' more frequently.\n");
1091 printf(
"Sensor recalibration needed ... \n");
1095 printf(
"Sensor calibration failed\n");
1099 printf(
"Sensor recalibration done!\n");
1106 printf(
"acc_detector_presence_prepare() failed\n");
1110 *recalibration_done =
true;
uint16_t distance_determination_duration_s
static bool process_breathing(acc_breathing_handle_t *handle, acc_int16_complex_t *frame, acc_breathing_result_t *result)
acc_breathing_app_state_t app_state
uint16_t rfft_output_length
void acc_detector_presence_config_sweeps_per_frame_set(acc_detector_presence_config_t *presence_config, uint16_t sweeps_per_frame)
Set the number of sweeps per frame.
@ ACC_BREATHING_APP_STATE_INIT
float base_presence_distance
void acc_hal_integration_sensor_supply_off(acc_sensor_id_t sensor_id)
Power off sensor supply.
float acc_algorithm_exp_smoothing_coefficient(float fs, float tc)
Calculate exponential smoothing coefficient.
@ BREATHING_PRESET_INFANT
bool acc_detector_presence_prepare(acc_detector_presence_handle_t *presence_handle, acc_detector_presence_config_t *presence_config, acc_sensor_t *sensor, const acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Prepare the detector to do a measurement.
void acc_hal_integration_sensor_supply_on(acc_sensor_id_t sensor_id)
Power on sensor supply.
void acc_detector_presence_destroy(acc_detector_presence_handle_t *presence_handle)
Destroy a presence detector identified with the provided handle.
void acc_detector_presence_config_hwaas_set(acc_detector_presence_config_t *presence_config, uint16_t hwaas)
Set the hardware accelerated average samples (HWAAS)
@ ACC_BREATHING_APP_STATE_DETERMINE_DISTANCE
uint16_t distance_determination_counter
uint16_t lowest_breathing_rate
Breathing application config container.
bool acc_sensor_read(const acc_sensor_t *sensor, void *buffer, uint32_t buffer_size)
Read out radar data.
@ ACC_BREATHING_APP_STATE_ESTIMATE_BREATHING_RATE
uint16_t sweeps_per_frame
void acc_detector_presence_config_auto_profile_set(acc_detector_presence_config_t *presence_config, bool enable)
Enable automatic selection of profile based on start point of measurement.
static float presence_distance
float * filt_angle_buffer
Data type for interger-based representation of complex numbers.
uint16_t time_series_length
float complex * filt_sparse_iq_buffer
float acc_algorithm_interpolate_peaks_equidistant(const float *y, float x_start, float x_delta, uint16_t peak_idx)
Interpolate equidistant peaks.
static void print_app_state(acc_breathing_handle_t *handle)
acc_processing_result_t processing_result
#define DEFAULT_PRESET_CONFIG
void acc_detector_presence_config_frame_rate_set(acc_detector_presence_config_t *presence_config, float frame_rate)
Set the frame rate.
@ ACC_BREATHING_APP_STATE_INTRA_PRESENCE
Breathing application results container.
static void set_config(acc_breathing_config_t *config, breathing_preset_t preset)
@ BREATHING_PRESET_SITTING
static void determine_state(acc_breathing_handle_t *handle, acc_detector_presence_result_t *presence_result)
@ ACC_BREATHING_APP_STATE_NO_PRESENCE
float presence_distance_threshold
bool acc_detector_presence_get_buffer_size(const acc_detector_presence_handle_t *presence_handle, uint32_t *buffer_size)
Get the buffer size needed for the provided presence detector handle.
static bool enter_hibernate(acc_sensor_t *sensor)
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
void acc_detector_presence_config_intra_detection_threshold_set(acc_detector_presence_config_t *presence_config, float intra_detection_threshold)
Set the detection threshold for the intra-frame presence detection.
void * acc_integration_mem_alloc(size_t size)
Allocate dynamic memory.
uint16_t padded_time_series_length
static bool reinit_breathing(acc_breathing_handle_t *handle, uint16_t start_point, uint16_t end_point)
int acconeer_main(int argc, char *argv[])
Assembly test example.
void acc_integration_set_periodic_wakeup(uint32_t time_msec)
Set up a periodic timer used to wake up the system from sleep.
Presence detector results container.
static bool measure(acc_breathing_handle_t *handle, acc_detector_presence_result_t *presence_result)
void acc_detector_presence_config_inter_frame_presence_timeout_set(acc_detector_presence_config_t *presence_config, uint16_t inter_frame_presence_timeout)
Set the inter-frame presence timeout in seconds.
void acc_algorithm_butter_lowpass(float freq, float fs, float *b, float *a)
Design a 2nd order digital Butterworth lowpass filter.
uint16_t acc_algorithm_argmax(const float *data, uint16_t data_length)
Find index of largest element in the array.
acc_cal_result_t sensor_cal_result
void acc_detector_presence_config_destroy(acc_detector_presence_config_t *presence_config)
Destroy a presence detector configuration.
bool acc_hal_integration_wait_for_sensor_interrupt(acc_sensor_id_t sensor_id, uint32_t timeout_ms)
Wait for a sensor interrupt.
void acc_algorithm_rfft_matrix(const float *data, uint16_t rows, uint16_t cols, uint16_t length_shift, float complex *output, uint16_t axis)
1D Fast Fourier Transform for real input matrix
void acc_detector_presence_config_end_set(acc_detector_presence_config_t *presence_config, float end)
Set the end point of measurement interval in meters.
void acc_detector_presence_config_intra_output_time_const_set(acc_detector_presence_config_t *presence_config, float intra_output_time_const)
Set the time constant for the output in the intra-frame part.
bool acc_sensor_hibernate_off(const acc_sensor_t *sensor)
Restore sensor after exiting hibernation.
const char * acc_version_get(void)
Get the version of the Acconeer software.
uint16_t time_series_length_s
float intra_presence_score
bool use_presence_processor
uint16_t use_presence_processor
static bool validate_config(acc_breathing_config_t *config)
void acc_hal_integration_sensor_enable(acc_sensor_id_t sensor_id)
Enable sensor.
acc_breathing_app_state_t prev_app_state
bool acc_detector_presence_process(acc_detector_presence_handle_t *presence_handle, void *buffer, acc_detector_presence_result_t *result)
Process the data according to the configuration used in acc_detector_presence_config_create.
void acc_detector_presence_config_inter_output_time_const_set(acc_detector_presence_config_t *presence_config, float inter_output_time_const)
Set the time constant for the output in the inter-frame part.
void acc_algorithm_mean_sweep(const acc_int16_complex_t *frame, uint16_t num_points, uint16_t sweeps_per_frame, uint16_t start_point, uint16_t end_point, float complex *sweep)
Calculate mean sweep of a frame from start_point to end_point.
Breathing application context handle.
void acc_algorithm_apply_filter(const float *a, const float *filt_data, uint16_t filt_rows, uint16_t filt_cols, const float *b, const float *data, uint16_t data_rows, uint16_t data_cols, float *output, uint16_t output_length)
Apply filter coefficients to filtered data matrix and data matrix.
float acc_algorithm_fftfreq_delta(uint16_t n, float d)
Calculate delta between frequency bins in rfft.
acc_int16_complex_t * frame
void acc_hal_integration_sensor_disable(acc_sensor_id_t sensor_id)
Disable sensor.
float complex * filt_sparse_iq
struct acc_detector_presence_config acc_detector_presence_config_t
acc_detector_presence_handle_t * presence_handle
uint16_t acc_detector_presence_config_sweeps_per_frame_get(const acc_detector_presence_config_t *presence_config)
Get the number of sweeps per frame.
static bool init_handle(acc_breathing_handle_t *handle, acc_breathing_config_t *config)
float * windowed_breathing_motion_buffer
static bool sensor_calibration(acc_breathing_handle_t *handle)
bool acc_sensor_hibernate_on(acc_sensor_t *sensor)
Prepare sensor for entering hibernation.
float complex * rfft_output
float complex * sparse_iq_buffer
void acc_sensor_status(const acc_sensor_t *sensor)
Check the status of the sensor.
uint16_t num_points_to_analyze
void acc_algorithm_roll_and_push_f32_matrix(float *data, uint16_t rows, uint16_t cols, const float *column, bool pos_shift)
Roll row elements and push a new column.
uint16_t padded_time_series_length_shift
float * breathing_motion_buffer
uint16_t time_series_length_s
uint16_t num_points_to_analyze_half_width
float acc_detector_presence_config_frame_rate_get(const acc_detector_presence_config_t *presence_config)
Get the frame rate.
void acc_detector_presence_config_profile_set(acc_detector_presence_config_t *presence_config, acc_config_profile_t profile)
Set a profile.
float acc_algorithm_get_fwhm(acc_config_profile_t profile)
Get the envelope Full Width Half Maximum in meters given a profile.
void acc_integration_mem_free(void *ptr)
Free dynamic memory.
void acc_integration_sleep_until_periodic_wakeup(void)
Put the system in sleep until the periodic timer triggers.
acc_detector_presence_handle_t * acc_detector_presence_create(acc_detector_presence_config_t *presence_config, acc_detector_presence_metadata_t *metadata)
Create a presence detector with the provided configuration.
float acc_detector_presence_config_intra_detection_threshold_get(const acc_detector_presence_config_t *presence_config)
Get the detection threshold for the intra-frame presence detection.
acc_config_profile_t acc_detector_presence_config_profile_get(const acc_detector_presence_config_t *presence_config)
Get the currently set profile.
void acc_algorithm_butter_bandpass(float min_freq, float max_freq, float fs, float *b, float *a)
Design a 2nd order digital Butterworth bandpass filter.
float complex * mean_sweep
struct acc_detector_presence_handle acc_detector_presence_handle_t
static bool init_sensor_resources(acc_breathing_handle_t *handle, acc_breathing_config_t *config)
bool acc_sensor_calibrate(acc_sensor_t *sensor, bool *cal_complete, acc_cal_result_t *cal_result, void *buffer, uint32_t buffer_size)
Calibrate a sensor.
static bool check_indications(acc_breathing_handle_t *handle, acc_breathing_config_t *config, acc_detector_presence_result_t *presence_result, bool *recalibration_done)
acc_detector_presence_config_t * acc_detector_presence_config_create(void)
Create a configuration for a presence detector.
uint16_t highest_breathing_rate
void acc_detector_presence_config_start_set(acc_detector_presence_config_t *presence_config, float start)
Set the start point of measurement interval in meters.
uint16_t distance_determination_count
void acc_algorithm_roll_and_push_f32_complex_matrix(float complex *data, uint16_t rows, uint16_t cols, const float complex *column, bool pos_shift)
Roll row elements and push a new column.
bool acc_sensor_measure(acc_sensor_t *sensor)
Start a radar measurement with previously prepared configuration.
void acc_detector_presence_config_auto_step_length_set(acc_detector_presence_config_t *presence_config, bool enable)
Enable automatic selection of step length based on the profile.
float intra_detection_threshold
void acc_algorithm_hamming(uint16_t n, float *window)
Calculate hamming window for a specified number of points.
void acc_algorithm_apply_filter_complex(const float *a, const float complex *filt_data, uint16_t filt_rows, uint16_t filt_cols, const float *b, const float complex *data, uint16_t data_rows, uint16_t data_cols, float complex *output, uint16_t output_length)
Apply filter coefficients to filtered data matrix and data matrix.
static void print_result(acc_breathing_result_t *result)
uint16_t num_dists_to_analyze
static void update_presence_distance(acc_breathing_handle_t *handle, float presence_distance)
static bool exit_hibernate(acc_sensor_t *sensor)
acc_breathing_app_state_t
struct acc_sensor acc_sensor_t
static void cleanup(acc_breathing_handle_t *handle, acc_breathing_config_t *config)
void acc_detector_presence_config_step_length_set(acc_detector_presence_config_t *presence_config, uint16_t step_length)
Set the step length in points.
void acc_sensor_destroy(acc_sensor_t *sensor)
Destroy a sensor instance freeing any resources allocated.
#define SENSOR_TIMEOUT_MS
acc_detector_presence_config_t * presence_config
void acc_detector_presence_config_frame_rate_app_driven_set(acc_detector_presence_config_t *presence_config, bool enable)
Set if the application should maintain the requested frame rate.
void acc_detector_presence_config_inter_frame_fast_cutoff_set(acc_detector_presence_config_t *presence_config, float inter_frame_fast_cutoff)
Set the cutoff frequency of the low pass filter for the fast filtered absolute sweep mean.
static bool perform_action_based_on_state(acc_breathing_handle_t *handle, acc_int16_complex_t *frame, acc_breathing_result_t *result)
acc_sensor_t * acc_sensor_create(acc_sensor_id_t sensor_id)
Create a sensor instance.