example_processing_coherent_mean.c
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2022-2023
2 // All rights reserved
3 // This file is subject to the terms and conditions defined in the file
4 // 'LICENSES/license_acconeer.txt', (BSD 3-Clause License) which is part
5 // of this source code package.
6
7
8 /** \example example_processing_coherent_mean.c
9 * @brief example_processing_coherent_mean.c
10 * Example program that shows how to calculate the coherent mean of the values in
11 * an A121 sparse IQ frame with multiple sweeps.
12 */
13
14
15 #include <stdbool.h>
16 #include <stdint.h>
17 #include <stdio.h>
18
19 #include "acc_config.h"
20 #include "acc_hal_definitions_a121.h"
21 #include "acc_hal_integration_a121.h"
22 #include "acc_integration_log.h"
23 #include "acc_rss_a121.h"
24 #include "acc_version.h"
25
26
27 #include "acc_processing_helpers.h"
28
29
30 #define SENSOR_ID (1U)
31
32 #define SWEEPS_PER_FRAME 16
33
34
35 static void update_configuration(acc_config_t *config);
36
37
38 int acconeer_main(int argc, char *argv[]);
39
40
41 int acconeer_main(int argc, char *argv[])
42 {
43 (void)argc;
44 (void)argv;
45
46 acc_control_helper_t control_helper_state = {0};
47
48 printf("Acconeer software version %s\n", acc_version_get());
49
50 const acc_hal_a121_t *hal = acc_hal_rss_integration_get_implementation();
51
52 if (!acc_rss_hal_register(hal))
53 {
54 return EXIT_FAILURE;
55 }
56
57 bool res = acc_control_helper_create(&control_helper_state, SENSOR_ID);
58
59 if (!res)
60 {
61 printf("acc_control_helper_create() failed\n");
62 return EXIT_FAILURE;
63 }
64
65 update_configuration(control_helper_state.config);
66
67 res = acc_control_helper_activate(&control_helper_state);
68
69 if (!res)
70 {
71 printf("acc_control_helper_activate() failed\n");
72 acc_control_helper_destroy(&control_helper_state);
73 return EXIT_FAILURE;
74 }
75
76 uint32_t sweep_data_length = control_helper_state.proc_meta.sweep_data_length;
77 uint32_t point_vector_length = SWEEPS_PER_FRAME;
78
79 acc_vector_float_t *current_sweep_coherent_mean_amplitude = acc_vector_float_alloc(sweep_data_length);
80 acc_vector_iq_t *point_vector = acc_vector_iq_alloc(point_vector_length);
81
82 bool mem_ok = (current_sweep_coherent_mean_amplitude != NULL) && (point_vector != NULL);
83 if (!mem_ok)
84 {
85 printf("Memory allocation for vectors failed\n");
86 }
87 else
88 {
89 uint32_t iterations = 25U;
90 for (uint32_t i = 0U; i < iterations; i++)
91 {
92 if (!acc_control_helper_get_next(&control_helper_state))
93 {
94 printf("acc_control_helper_get_next() failed\n");
95 break;
96 }
97
98 // The acc_vector_iq_coherent_mean calculates the coherent mean by taking the mean value
99 // of the complex vector elements and then return the absabsolute value of the mean
100 // coherent mean = (z=0..n) sqrt(mean(real(z))^2 + mean(imag(z))^2)
101
102 for (uint32_t p = 0U; p < sweep_data_length; p++)
103 {
104 acc_get_iq_point_vector(&control_helper_state, p, point_vector);
105 current_sweep_coherent_mean_amplitude->data[p] = acc_vector_iq_coherent_mean_amplitude(point_vector);
106 }
107
108 acc_vector_float_print("Coherent mean amplitude", current_sweep_coherent_mean_amplitude);
109
110 uint32_t max_peak_index = acc_vector_float_argmax(current_sweep_coherent_mean_amplitude);
111 printf("Highest peak index: %" PRIu32 ", peak ampliude %" PRIfloat "\n",
112 max_peak_index,
113 ACC_LOG_FLOAT_TO_INTEGER(current_sweep_coherent_mean_amplitude->data[max_peak_index]));
114 }
115 }
116
117 acc_vector_iq_free(point_vector);
118 acc_vector_float_free(current_sweep_coherent_mean_amplitude);
119 acc_control_helper_destroy(&control_helper_state);
120
121 printf("Application finished OK\n");
122
123 return EXIT_SUCCESS;
124 }
125
126
127 static void update_configuration(acc_config_t *config)
128 {
129 int32_t start_point = 100; // start at 250 mm
130 uint16_t step_length = 2; // 2*2.5 mm = 5 mm
131 uint16_t num_points = 100; // range length 2*100*2.5 mm = 500 mm
132
133 acc_config_start_point_set(config, start_point);
134 acc_config_num_points_set(config, num_points);
135 acc_config_step_length_set(config, step_length);
136 acc_config_profile_set(config, ACC_CONFIG_PROFILE_2);
137 acc_config_hwaas_set(config, 30);
138 // The processing in this example assumes that sweeps_per_frame > 1
139 acc_config_sweeps_per_frame_set(config, SWEEPS_PER_FRAME);
140 acc_config_prf_set(config, ACC_CONFIG_PRF_13_0_MHZ);
141 }
acc_config_start_point_set
void acc_config_start_point_set(acc_config_t *config, int32_t start_point)
Set the starting point of the sweep.
acc_control_helper_create
bool acc_control_helper_create(acc_control_helper_t *radar, acc_sensor_id_t sensor_id)
Create a helper instance.
Definition: acc_control_helper.c:41
acc_rss_a121.h
acc_vector_iq_coherent_mean_amplitude
float acc_vector_iq_coherent_mean_amplitude(const acc_vector_iq_t *vector_a)
Coherent mean amplitude of IQ vector.
Definition: acc_processing_helpers.c:316
acc_get_iq_point_vector
void acc_get_iq_point_vector(const acc_control_helper_t *control_helper_state, uint32_t point, acc_vector_iq_t *vector_out)
Extract an IQ vector with sweep data for a specific point from a newly captured IQ frame with multipl...
Definition: acc_processing_helpers.c:152
acc_vector_float_free
void acc_vector_float_free(acc_vector_float_t *vector)
Free storage of data elements in a float vector.
Definition: acc_processing_helpers.c:85
acc_vector_iq_free
void acc_vector_iq_free(acc_vector_iq_t *vector)
Free storage of data elements in an IQ vector.
Definition: acc_processing_helpers.c:73
acc_control_helper_t::config
acc_config_t * config
Definition: acc_control_helper.h:25
acc_version.h
SENSOR_ID
#define SENSOR_ID
Definition: example_processing_coherent_mean.c:30
acc_config_profile_set
void acc_config_profile_set(acc_config_t *config, acc_config_profile_t profile)
Set a profile.
acc_config_sweeps_per_frame_set
void acc_config_sweeps_per_frame_set(acc_config_t *config, uint16_t sweeps)
Set sweeps per frame.
acc_vector_float_t::data
float * data
Definition: acc_processing_helpers.h:36
acc_control_helper_destroy
void acc_control_helper_destroy(acc_control_helper_t *radar)
Destroy a helper instance.
Definition: acc_control_helper.c:50
acc_hal_rss_integration_get_implementation
const acc_hal_a121_t * acc_hal_rss_integration_get_implementation(void)
Get hal implementation reference.
Definition: acc_hal_integration_stm32cube_xm.c:166
SWEEPS_PER_FRAME
#define SWEEPS_PER_FRAME
Definition: example_processing_coherent_mean.c:32
acc_vector_iq_t
Definition: acc_processing_helpers.h:27
acconeer_main
int acconeer_main(int argc, char *argv[])
Assembly test example.
Definition: example_processing_coherent_mean.c:41
acc_hal_a121_t
Definition: acc_hal_definitions_a121.h:82
acc_control_helper_t::proc_meta
acc_processing_metadata_t proc_meta
Definition: acc_control_helper.h:32
acc_rss_hal_register
bool acc_rss_hal_register(const acc_hal_a121_t *hal)
Register an integration.
ACC_CONFIG_PRF_13_0_MHZ
@ ACC_CONFIG_PRF_13_0_MHZ
Definition: acc_definitions_a121.h:110
acc_config_hwaas_set
void acc_config_hwaas_set(acc_config_t *config, uint16_t hwaas)
Set the hardware accelerated average samples (HWAAS)
acc_processing_metadata_t::sweep_data_length
uint16_t sweep_data_length
Definition: acc_processing.h:41
acc_hal_integration_a121.h
update_configuration
static void update_configuration(acc_config_t *config)
Definition: example_processing_coherent_mean.c:127
acc_version_get
const char * acc_version_get(void)
Get the version of the Acconeer software.
acc_config_t
struct acc_config acc_config_t
Definition: acc_config.h:26
printf
#define printf
Definition: printf.h:60
acc_config_step_length_set
void acc_config_step_length_set(acc_config_t *config, uint16_t step_length)
Set the step length in a sweep.
acc_config_num_points_set
void acc_config_num_points_set(acc_config_t *config, uint16_t num_points)
Set the number of data points to measure.
acc_hal_definitions_a121.h
acc_processing_helpers.h
acc_vector_float_t
Definition: acc_processing_helpers.h:33
acc_integration_log.h
ACC_LOG_FLOAT_TO_INTEGER
#define ACC_LOG_FLOAT_TO_INTEGER(a)
Definition: acc_integration_log.h:26
acc_vector_iq_alloc
acc_vector_iq_t * acc_vector_iq_alloc(uint32_t data_length)
Allocate storage for an IQ vector.
Definition: acc_processing_helpers.c:27
acc_vector_float_alloc
acc_vector_float_t * acc_vector_float_alloc(uint32_t data_length)
Allocate storage for a float vector.
Definition: acc_processing_helpers.c:50
acc_vector_float_print
void acc_vector_float_print(const char *label, acc_vector_float_t *vector_a)
Print float vector.
Definition: acc_processing_helpers.c:401
acc_control_helper_t
Definition: acc_control_helper.h:23
acc_control_helper_activate
bool acc_control_helper_activate(acc_control_helper_t *radar)
Activate the sensor.
Definition: acc_control_helper.c:81
ACC_CONFIG_PROFILE_2
@ ACC_CONFIG_PROFILE_2
Definition: acc_definitions_a121.h:43
acc_config_prf_set
void acc_config_prf_set(acc_config_t *config, acc_config_prf_t prf)
Set Pulse Repetition Frequency.
acc_config.h
PRIfloat
#define PRIfloat
Specifier for printing float type using integers.
Definition: acc_integration_log.h:31
acc_control_helper_get_next
bool acc_control_helper_get_next(acc_control_helper_t *radar)
Perform a radar measurement and wait for the result.
Definition: acc_control_helper.c:157
acc_vector_float_argmax
uint32_t acc_vector_float_argmax(acc_vector_float_t *vector_a)
Index of element with maximum value in a float vector.
Definition: acc_processing_helpers.c:357