|
#include <assert.h>
#include <complex.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "acc_control_helper.h"
#include "acc_processing_helpers.h"
#include "acc_integration_log.h"
Go to the source code of this file.
Macros | |
#define | MAX_DATA_ENTRY_LEN_IQ 87 |
#define | MAX_DATA_ENTRY_LEN_FLOAT 44 |
Functions | |
acc_vector_iq_t * | acc_vector_iq_alloc (uint32_t data_length) |
Allocate storage for an IQ vector. More... | |
acc_vector_float_t * | acc_vector_float_alloc (uint32_t data_length) |
Allocate storage for a float vector. More... | |
void | acc_vector_iq_free (acc_vector_iq_t *vector) |
Free storage of data elements in an IQ vector. More... | |
void | acc_vector_float_free (acc_vector_float_t *vector) |
Free storage of data elements in a float vector. More... | |
float | acc_processing_helper_tc_to_sf (float time_constant_s, float update_rate_hz) |
Convert time constant to smoothing factor. More... | |
float | acc_processing_helper_dynamic_sf (float static_sf, uint32_t update_count) |
Calculate a dynamic smoothing factor. More... | |
void | acc_vector_iq_update_exponential_average (const acc_vector_iq_t *current, acc_vector_iq_t *averaged_data, float sf) |
Update the exponential average of an IQ vector. More... | |
void | acc_vector_float_update_exponential_average (const acc_vector_float_t *current, acc_vector_float_t *averaged_data, float sf) |
Update the exponential average of a float vector. More... | |
void | acc_get_iq_sweep_vector (const acc_control_helper_t *control_helper_state, acc_vector_iq_t *vector_out) |
Converts a newly captured IQ frame with one sweep to an IQ vector. More... | |
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 multiple sweeps. More... | |
uint32_t | acc_processing_helper_get_filter_length (uint32_t peak_width_points, uint32_t step_length) |
Calculate filter vector length. More... | |
void | acc_vector_float_create_depth_filter_vector (acc_vector_float_t *vector_out) |
Create a distance filter vector. More... | |
void | acc_vector_iq_apply_filter (const acc_vector_iq_t *vector_a, acc_vector_float_t *filter_vector, acc_vector_iq_t *vector_out) |
Apply a FIR filter to an IQ vector. More... | |
void | acc_vector_iq_copy (const acc_vector_iq_t *vector_a, acc_vector_iq_t *vector_out) |
Copy an IQ vector. More... | |
void | acc_vector_iq_add (const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out) |
Add two IQ vectors. More... | |
void | acc_vector_iq_subtract (const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out) |
Subtract two IQ vectors. More... | |
void | acc_vector_iq_mult (const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out) |
Multiply two IQ vectors. More... | |
void | acc_vector_iq_mult_conj (const acc_vector_iq_t *vector_a, const acc_vector_iq_t *vector_b, acc_vector_iq_t *vector_out) |
Multiply first IQ vector with conjugate of second IQ vector. More... | |
void | acc_vector_iq_rotate_phase_inline (acc_vector_iq_t *vector_a, float radians) |
Rotate the phase of elements in an IQ vector. More... | |
void | acc_vector_iq_conj_inline (acc_vector_iq_t *vector_a) |
Update an IQ vector with its conjugate. More... | |
void | acc_vector_iq_amplitude (const acc_vector_iq_t *vector_a, acc_vector_float_t *vector_out) |
Amplitude of an IQ vector. More... | |
float | acc_vector_iq_coherent_mean_amplitude (const acc_vector_iq_t *vector_a) |
Coherent mean amplitude of IQ vector. More... | |
float | acc_vector_iq_noncoherent_mean_amplitude (const acc_vector_iq_t *vector_a) |
Non-coherent mean amplitude of IQ vector. More... | |
void | acc_vector_iq_phase (const acc_vector_iq_t *vector_a, acc_vector_float_t *vector_out) |
Phase of an IQ vector. More... | |
uint32_t | acc_vector_float_argmax (acc_vector_float_t *vector_a) |
Index of element with maximum value in a float vector. More... | |
uint32_t | acc_vector_float_argmax_skip_edges (acc_vector_float_t *vector_a, uint32_t elemets_to_skip) |
Index of element with maximum value in a float vector disregarding edge elements. More... | |
float | acc_processing_helper_interpolate_peak_position (float y1, float y2, float y3) |
Interpolate peak position. More... | |
void | acc_vector_float_print (const char *label, acc_vector_float_t *vector_a) |
Print float vector. More... | |
void | acc_vector_iq_print (const char *label, acc_vector_iq_t *vector_a) |
Print IQ vector. More... | |
#define MAX_DATA_ENTRY_LEN_FLOAT 44 |
Definition at line 24 of file acc_processing_helpers.c.
#define MAX_DATA_ENTRY_LEN_IQ 87 |
Definition at line 23 of file acc_processing_helpers.c.
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 multiple sweeps.
The resulting vector can be used with the processing functions in this file.
[in] | control_helper_state | Pointer to control helper radar state struct |
[in] | point | The point to get the IQ vector for |
[out] | vector_out | IQ vector |
Definition at line 152 of file acc_processing_helpers.c.
void acc_get_iq_sweep_vector | ( | const acc_control_helper_t * | control_helper_state, |
acc_vector_iq_t * | vector_out | ||
) |
Converts a newly captured IQ frame with one sweep to an IQ vector.
The resulting vector can be used with the processing functions in this file.
[in] | control_helper_state | Pointer to control helper radar state struct |
[out] | vector_out | IQ vector |
Definition at line 138 of file acc_processing_helpers.c.
float acc_processing_helper_dynamic_sf | ( | float | static_sf, |
uint32_t | update_count | ||
) |
Calculate a dynamic smoothing factor.
Calculate a smoothing factor that are lower for the first sweeps. For the first n sweeps the exponential average will be equal to the arithmetic mean of the first n sweeps.
[in] | static_sf | The target smoothing factor that will be used after the first sweeps |
[in] | update_count | The update count should be 0 for the first sweep and increased by one for each update |
Definition at line 110 of file acc_processing_helpers.c.
uint32_t acc_processing_helper_get_filter_length | ( | uint32_t | peak_width_points, |
uint32_t | step_length | ||
) |
Calculate filter vector length.
Calculate filter vector length given peak width and step size. The peak width varies depending on profile.
[in] | peak_width_points | Peak width in base points |
[in] | step_length | Step length in base points |
Definition at line 166 of file acc_processing_helpers.c.
float acc_processing_helper_interpolate_peak_position | ( | float | y1, |
float | y2, | ||
float | y3 | ||
) |
Interpolate peak position.
The function fits a second degree polynomial to three consecutive amplitude values where second element is expected to contain the maximum measured amplitude. The function then finds the position of the maximum amplitude of the polynomial. The position is normalized and a return value of 0 means that the peak is at the position of the second amplitude. A value of -1 and 1 means that the peak is at the position of the first or third input amplitude respectively.
[in] | y1 | The first amplitude value |
[in] | y2 | The second amplitude value |
[in] | y3 | The third amplitude value |
Definition at line 395 of file acc_processing_helpers.c.
float acc_processing_helper_tc_to_sf | ( | float | time_constant_s, |
float | update_rate_hz | ||
) |
Convert time constant to smoothing factor.
[in] | time_constant_s | Time constant |
[in] | update_rate_hz | Update rate |
Definition at line 97 of file acc_processing_helpers.c.
acc_vector_float_t* acc_vector_float_alloc | ( | uint32_t | data_length | ) |
Allocate storage for a float vector.
[in] | data_length | Length of the vector |
Definition at line 50 of file acc_processing_helpers.c.
uint32_t acc_vector_float_argmax | ( | acc_vector_float_t * | vector_a | ) |
Index of element with maximum value in a float vector.
[in] | vector_a | Input vector |
Definition at line 357 of file acc_processing_helpers.c.
uint32_t acc_vector_float_argmax_skip_edges | ( | acc_vector_float_t * | vector_a, |
uint32_t | elements_to_skip | ||
) |
Index of element with maximum value in a float vector disregarding edge elements.
Find the index of the maximum element in a float vector disregarding the first and last elements in the vector.
[in] | vector_a | Input vector |
[in] | elements_to_skip | The number of elements to skip |
Definition at line 375 of file acc_processing_helpers.c.
void acc_vector_float_create_depth_filter_vector | ( | acc_vector_float_t * | vector_out | ) |
Create a distance filter vector.
Create a triangle shaped distance filter vector. Use the function acc_processing_helper_get_filter_length when allocating memory for the output vector to get the right length of the filter for a given peak width and step size.
[out] | vector_out | Filter vector |
Definition at line 172 of file acc_processing_helpers.c.
void acc_vector_float_free | ( | acc_vector_float_t * | vector | ) |
Free storage of data elements in a float vector.
[in] | vector | Vector to be freed |
Definition at line 85 of file acc_processing_helpers.c.
void acc_vector_float_print | ( | const char * | label, |
acc_vector_float_t * | vector_a | ||
) |
Print float vector.
Print a float vector to stdout.
[in] | label | A string description of the vector |
[in] | vector_a | The float vector to print |
Definition at line 401 of file acc_processing_helpers.c.
void acc_vector_float_update_exponential_average | ( | const acc_vector_float_t * | current, |
acc_vector_float_t * | averaged_data, | ||
float | sf | ||
) |
Update the exponential average of a float vector.
[in] | current | The new IQ float that will be included in the updated exponential average |
[in,out] | averaged_data | The filtered data or exponential average that should be updated |
[in] | sf | Smoothing factor that determines how much of the old data that should be kept |
Definition at line 127 of file acc_processing_helpers.c.
void acc_vector_iq_add | ( | const acc_vector_iq_t * | vector_a, |
const acc_vector_iq_t * | vector_b, | ||
acc_vector_iq_t * | vector_out | ||
) |
Add two IQ vectors.
[in] | vector_a | First input vector |
[in] | vector_b | Second input vector |
[out] | vector_out | The result a + b |
Definition at line 237 of file acc_processing_helpers.c.
acc_vector_iq_t* acc_vector_iq_alloc | ( | uint32_t | data_length | ) |
Allocate storage for an IQ vector.
[in] | data_length | Length of the vector |
Definition at line 27 of file acc_processing_helpers.c.
void acc_vector_iq_amplitude | ( | const acc_vector_iq_t * | vector_a, |
acc_vector_float_t * | vector_out | ||
) |
Amplitude of an IQ vector.
Calculate the amplitude of the elements in an IQ vector.
[in] | vector_a | Input IQ vector |
[out] | vector_out | The amplitude of the elements in the input vector |
Definition at line 305 of file acc_processing_helpers.c.
void acc_vector_iq_apply_filter | ( | const acc_vector_iq_t * | vector_a, |
acc_vector_float_t * | filter_vector, | ||
acc_vector_iq_t * | vector_out | ||
) |
Apply a FIR filter to an IQ vector.
Performs coherent filtering of the input vector.
[in] | vector_a | IQ vector |
[in] | filter_vector | Filter vector |
[out] | vector_out | Filtered result |
Definition at line 203 of file acc_processing_helpers.c.
float acc_vector_iq_coherent_mean_amplitude | ( | const acc_vector_iq_t * | vector_a | ) |
Coherent mean amplitude of IQ vector.
Calculate the coherent mean amplitude of the elements in an IQ vector.
[in] | vector_a | Input IQ vector |
Definition at line 316 of file acc_processing_helpers.c.
void acc_vector_iq_conj_inline | ( | acc_vector_iq_t * | vector_a | ) |
Update an IQ vector with its conjugate.
Replace the elements in an IQ vector with the conjugate of the elements.
[in,out] | vector_a | The IQ vector to be modified |
Definition at line 296 of file acc_processing_helpers.c.
void acc_vector_iq_copy | ( | const acc_vector_iq_t * | vector_a, |
acc_vector_iq_t * | vector_out | ||
) |
Copy an IQ vector.
Copy the contents of one IQ vector to another IQ vector.
[in] | vector_a | Source IQ vector |
[out] | vector_out | Destination IQ vector |
Definition at line 226 of file acc_processing_helpers.c.
void acc_vector_iq_free | ( | acc_vector_iq_t * | vector | ) |
Free storage of data elements in an IQ vector.
[in] | vector | Vector to be freed |
Definition at line 73 of file acc_processing_helpers.c.
void acc_vector_iq_mult | ( | const acc_vector_iq_t * | vector_a, |
const acc_vector_iq_t * | vector_b, | ||
acc_vector_iq_t * | vector_out | ||
) |
Multiply two IQ vectors.
Perform element wise multiplication of two IQ vectors.
[in] | vector_a | First input vector |
[in] | vector_b | Second input vector |
[out] | vector_out | The result a * b |
Definition at line 261 of file acc_processing_helpers.c.
void acc_vector_iq_mult_conj | ( | const acc_vector_iq_t * | vector_a, |
const acc_vector_iq_t * | vector_b, | ||
acc_vector_iq_t * | vector_out | ||
) |
Multiply first IQ vector with conjugate of second IQ vector.
Make element wise multiplication of an IQ vector with the conjugate of another IQ vector. The amplitudes of the result will be the product of the amplitudes of the input vectors. The phases of the result will be the phase differences of the two input vectors.
The function can be used when calculating the phase difference between two consecutive sweeps.
[in] | vector_a | First input vector |
[in] | vector_b | Second input vector |
[out] | vector_out | The result: a * conj(b) |
Definition at line 273 of file acc_processing_helpers.c.
float acc_vector_iq_noncoherent_mean_amplitude | ( | const acc_vector_iq_t * | vector_a | ) |
Non-coherent mean amplitude of IQ vector.
Calculate the non-coherent mean amplitude of the elements in an IQ vector.
[in] | vector_a | Input IQ vector |
Definition at line 331 of file acc_processing_helpers.c.
void acc_vector_iq_phase | ( | const acc_vector_iq_t * | vector_a, |
acc_vector_float_t * | vector_out | ||
) |
Phase of an IQ vector.
Calculate the phase of the elements in an IQ vector.
[in] | vector_a | Input IQ vector |
[out] | vector_out | The phase of the elements in the input vector |
Definition at line 346 of file acc_processing_helpers.c.
void acc_vector_iq_print | ( | const char * | label, |
acc_vector_iq_t * | vector_a | ||
) |
Print IQ vector.
Print an IQ vector to stdout.
[in] | label | A string description of the vector |
[in] | vector_a | The IQ vector to print |
Definition at line 423 of file acc_processing_helpers.c.
void acc_vector_iq_rotate_phase_inline | ( | acc_vector_iq_t * | vector_a, |
float | radians | ||
) |
Rotate the phase of elements in an IQ vector.
[in,out] | vector_a | The IQ vector to be modified |
[in] | radians | The angle in radians to rotate the phase |
Definition at line 285 of file acc_processing_helpers.c.
void acc_vector_iq_subtract | ( | const acc_vector_iq_t * | vector_a, |
const acc_vector_iq_t * | vector_b, | ||
acc_vector_iq_t * | vector_out | ||
) |
Subtract two IQ vectors.
[in] | vector_a | First input vector |
[in] | vector_b | Second input vector |
[out] | vector_out | The result a - b |
Definition at line 249 of file acc_processing_helpers.c.
void acc_vector_iq_update_exponential_average | ( | const acc_vector_iq_t * | current, |
acc_vector_iq_t * | averaged_data, | ||
float | sf | ||
) |
Update the exponential average of an IQ vector.
[in] | current | The new IQ vector that will be included in the updated exponential average |
[in,out] | averaged_data | The filtered data or exponential average that should be updated |
[in] | sf | Smoothing factor that determines how much of the old data that should be kept |
Definition at line 116 of file acc_processing_helpers.c.