Macros | Functions
acc_algorithm.h File Reference
`#include <complex.h>`
`#include <stdint.h>`
`#include "acc_config.h"`
`#include "acc_definitions_a121.h"`
`#include "acc_definitions_common.h"`

Go to the source code of this file.

## Macros
#define | ACC_APPROX_BASE_STEP_LENGTH_M (2.5e-3f)
| Approximate minimum step length for a sensor measurement in meters. More...

## Functions
void | acc_algorithm_roll_and_push (float *data, uint16_t data_length, float element)
| Roll array elements and push new element last. More...
void | acc_algorithm_roll_and_push_matrix_f32 (float *data, uint16_t rows, uint16_t cols, const float *column, bool pos_shift)
| Roll row elements and push a new column. More...
void | acc_algorithm_roll_and_push_matrix_f32_complex (float complex *data, uint16_t rows, uint16_t cols, const float complex *column, bool pos_shift)
| Roll row elements and push a new column. More...
void | acc_algorithm_roll_and_push_mult_matrix_i16_complex (acc_int16_complex_t *data, uint16_t data_rows, uint16_t cols, const acc_int16_complex_t *matrix, uint16_t matrix_rows, bool pos_shift)
| Roll row elements and push multiple columns. More...
void | acc_algorithm_unwrap (float *data, uint16_t data_length)
| Unwraps a signal by changing elements which have an absolute difference from their predecessor of more than 2*pi to their period-complementary values. More...
uint16_t | acc_algorithm_argmax (const float *data, uint16_t data_length)
| Find index of largest element in the array. More...
float | acc_algorithm_interpolate_peaks (const float *y, const float *x)
| Interpolate peak. More...
float | acc_algorithm_interpolate_peaks_equidistant (const float *y, float x_start, float x_delta, uint16_t peak_idx)
| Interpolate equidistant peaks. More...
void | acc_algorithm_butter_lowpass (float freq, float fs, float *b, float *a)
| Design a 2nd order digital Butterworth lowpass filter. More...
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. More...
void | acc_algorithm_lfilter (const float *b, const float *a, float *data, uint16_t data_length)
| Filter data with a digital filter. More...
void | acc_algorithm_lfilter_matrix (const float *b, const float *a, float *data, uint16_t rows, uint16_t cols)
| Filter data along row dimension. More...
void | acc_algorithm_apply_filter_f32 (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. More...
void | acc_algorithm_apply_filter_f32_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. More...
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. More...
void | acc_algorithm_sum_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 *sum_sweep)
| Calculate the sum of all sweeps in a frame, from start_point to end_point. More...
void | acc_algorithm_mean_i16_complex (const acc_int16_complex_t *data, uint16_t data_length, float complex *out)
| Calculate mean value of an array. More...
void | acc_algorithm_mean_matrix_i16_complex (const acc_int16_complex_t *matrix, uint16_t rows, uint16_t cols, float complex *out, uint16_t axis)
| Calculate mean array of a matrix. More...
void | acc_algorithm_conj_f32 (float complex *data, uint16_t data_length)
| Inline calculate conjugate of all elements in an array. More...
void | acc_algorithm_normalize_f32_complex (float complex *data, uint16_t data_length)
| Normalize all elements in an array individually. More...
void | acc_algorithm_rfft (const float *data, uint16_t data_length, uint16_t length_shift, float complex *output)
| 1D Fast Fourier Transform for real input More...
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 More...
void | acc_algorithm_fft (const float complex *data, uint16_t data_length, uint16_t length_shift, float complex *output)
| 1D Fast Fourier Transform for complex input More...
void | acc_algorithm_fft_matrix (const float complex *data, uint16_t rows, uint16_t cols, uint16_t length_shift, float complex *output, uint16_t axis)
| 1D Fast Fourier Transform for input matrix More...
float | acc_algorithm_fftfreq_delta (uint16_t n, float d)
| Calculate delta between frequency bins in rfft. More...
void | acc_algorithm_rfftfreq (uint16_t n, float d, float *freqs)
| Calculate the real Fast Fourier Transform sample frequencies. More...
void | acc_algorithm_fftfreq (uint16_t n, float d, float *freqs)
| Calculate the Fast Fourier Transform sample frequencies. More...
float | acc_algorithm_exp_smoothing_coefficient (float fs, float tc)
| Calculate exponential smoothing coefficient. More...
float complex | acc_algorithm_cdiv (float complex num, float complex denom)
| Divide complex number num / denum. More...
void | acc_algorithm_hamming (uint16_t n, float *window)
| Calculate hamming window for a specified number of points. More...
void | acc_algorithm_hann (uint16_t n, float *window)
| Calculate non-symmetrical hann window for a specified number of points. More...
float | acc_algorithm_get_fwhm (acc_config_profile_t profile)
| Get the envelope Full Width Half Maximum in meters given a profile. More...
void | acc_algorithm_double_buffering_frame_filter (acc_int16_complex_t *frame, const uint16_t sweeps_per_frame, const uint16_t num_points, int32_t *work_buffer)
| Double buffering frame filter. More...
void | acc_algorithm_fftshift_matrix (float *data, uint16_t rows, uint16_t cols)
| Shift the zero-frequency component to the center along row dimensions. More...
void | acc_algorithm_fftshift (float *data, uint16_t data_length)
| Shift the zero-frequency component to the center. More...
void | acc_algorithm_welch_matrix (const float complex *data, uint16_t rows, uint16_t cols, uint16_t segment_length, float complex *data_buffer, float complex *fft_out, float *psds, const float *window, uint16_t length_shift, float fs)
| Estimate power spectral density (PSD) using Welch’s method along row dimensions. More...
void | acc_algorithm_welch (const float complex *data, uint16_t data_length, uint16_t segment_length, float complex *data_buffer, float complex *fft_out, float *psd, const float *window, uint16_t length_shift, float fs)
| Estimate power spectral density using Welch’s method. More...
float | acc_algorithm_calculate_cfar (const float *data, uint16_t data_length, uint16_t window_length, uint16_t half_guard_length, float sensitivity, uint16_t idx)
| Calculate CFAR threshold. More...
float | acc_algorithm_calculate_mirrored_one_sided_cfar (const float *data, uint16_t data_length, uint16_t middle_idx, uint16_t window_length, uint16_t half_guard_length, float sensitivity, uint16_t idx)
| Calculate mirrored one sided CFAR threshold. More...
uint16_t | acc_algorithm_get_distance_idx (const float *data, uint16_t cols, uint16_t rows, uint16_t middle_idx, uint16_t half_slow_zone)
| Find the index of the distance column containing the largest amplitude, disregarding amplitudes present in the slow zone. More...
float | acc_algorithm_get_peak_velocity (const float *velocities, const float *energies, const uint16_t *peak_idxs, uint16_t num_peaks, float limit)
| Find the velocity of the peak with the largest amplitude, prioritizing peaks with a velocity over the slow zone limit. More...
bool | acc_algorithm_merge_peaks (float max_peak_separation, const float *velocities, const float *energies, const uint16_t *peak_idxs, uint16_t num_peaks, float *merged_velocities, float *merged_energies, uint16_t merged_peaks_length, uint16_t *num_merged_peaks)
| Merges peaks. More...
float | acc_algorithm_get_distance_m (uint16_t step_length, uint16_t start_point, float base_step_length_m, uint16_t idx)
| Calculate distance for a point at an index. More...
acc_config_profile_t | acc_algorithm_select_profile (int32_t start_point, float base_step_length)
| Select the highest possible profile without interference of direct leakage. More...
acc_config_prf_t | acc_algorithm_select_prf (int16_t breakpoint, acc_config_profile_t profile, float base_step_length)
| Select a suitable PRF given a breakpoint and profile. More...
bool | acc_algorithm_find_peaks (const float *abs_sweep, const uint16_t data_length, const uint32_t *threshold_check, uint16_t *peak_idxs, uint16_t peak_idxs_length, uint16_t *num_peaks)
| Find peaks above threshold. More...
void | acc_algorithm_count_points_above_threshold (const float *matrix, uint16_t rows, uint16_t cols, const float threshold, uint16_t *count, uint16_t offset, uint16_t threshold_check_length, uint16_t axis)
| Count points in matrix above threshold row-wise or col-wise. More...
int16_t | acc_algorithm_median_i16 (int16_t *data, uint16_t length)
| Calculate median of input data. More...
float | acc_algorithm_median_f32 (float *data, uint16_t length)
| Calculate median of input data. More...
float | acc_algorithm_max_f32 (const float *data, uint16_t length)
| Find max value of input data. More...
float | acc_algorithm_weighted_mean (const float *data, const float *weights, uint16_t length)
| Calculate weighted mean. More...
float | acc_algorithm_variance_f32 (const float *data, uint16_t length)
| Calculate variance. More...
float | acc_algorithm_stddev_f32 (const float *data, uint16_t length)
| Calculate standard deviation. More...
float | acc_algorithm_clip_f32 (float value, float min, float max)
| Clip passed value into the interval [min, max]. More...

## Macro Definition Documentation

## ◆ ACC_APPROX_BASE_STEP_LENGTH_M

#define ACC_APPROX_BASE_STEP_LENGTH_M (2.5e-3f)

Approximate minimum step length for a sensor measurement in meters.

Used for meter to point conversion

Definition at line 19 of file acc_algorithm.h.

## Function Documentation

## ◆ acc_algorithm_apply_filter_f32()

void acc_algorithm_apply_filter_f32 | ( | 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.

Parameters

  [in] | a | Denominator of polynomial of the IIR filter
  [in] | filt_data | Filtered data matrix
  [in] | filt_rows | Number of rows in filtered data matrix, == len(a)
  [in] | filt_cols | Number of columns in filtered data matrix, == data_cols
  [in] | b | Numerator of polynomial of the IIR filter
  [in] | data | Data matrix
  [in] | data_rows | Number of rows in data matrix, == len(b)
  [in] | data_cols | Number of columns in data matrix, == filt_cols
  [out] | output | Output filtered data array
  [in] | output_length | Length of output, == data_cols and filt_cols

Definition at line 464 of file acc_algorithm.c.

## ◆ acc_algorithm_apply_filter_f32_complex()

void acc_algorithm_apply_filter_f32_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.

Parameters

  [in] | a | Denominator of polynomial of the IIR filter
  [in] | filt_data | Filtered data matrix
  [in] | filt_rows | Number of rows in filtered data matrix, == len(a)
  [in] | filt_cols | Number of columns in filtered data matrix, == data_cols
  [in] | b | Numerator of polynomial of the IIR filter
  [in] | data | Data matrix
  [in] | data_rows | Number of rows in data matrix, == len(b)
  [in] | data_cols | Number of columns in data matrix, == filt_cols
  [out] | output | Output filtered data array
  [in] | output_length | Length of output, == data_cols and filt_cols

Definition at line 491 of file acc_algorithm.c.

## ◆ acc_algorithm_argmax()

uint16_t acc_algorithm_argmax | ( | const float * | data,
|  | uint16_t | data_length
| ) |  |

Find index of largest element in the array.

Parameters

  [in] | data | Array of data
  [in] | data_length | Length of the array

Returns
  Index of largest element

Definition at line 305 of file acc_algorithm.c.

## ◆ acc_algorithm_butter_bandpass()

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.

Parameters

  [in] | min_freq | Low cutoff frequency
  [in] | max_freq | High cutoff frequency
  [in] | fs | Sampling frequency, > 0 Hz
  [out] | b | Numerator in polynomial of the IIR filter, length == 5
  [out] | a | Denominator of polynomial of the IIR filter, length == 4

Definition at line 379 of file acc_algorithm.c.

## ◆ acc_algorithm_butter_lowpass()

void acc_algorithm_butter_lowpass | ( | float | freq,
|  | float | fs,
|  | float * | b,
|  | float * | a
| ) |  |

Design a 2nd order digital Butterworth lowpass filter.

Parameters

  [in] | freq | Cutoff freuency
  [in] | fs | Sampling frequency, > 0 Hz
  [out] | b | Numerator in polynomial of the IIR filter, length == 3
  [out] | a | Denominator of polynomial of the IIR filter, length == 2

Definition at line 337 of file acc_algorithm.c.

## ◆ acc_algorithm_calculate_cfar()

float acc_algorithm_calculate_cfar | ( | const float * | data,
|  | uint16_t | data_length,
|  | uint16_t | window_length,
|  | uint16_t | half_guard_length,
|  | float | sensitivity,
|  | uint16_t | idx
| ) |  |

Calculate CFAR threshold.

Parameters

  [in] | data | Array of data
  [in] | data_length | Length of the data array
  [in] | window_length | Number of frequency bins next to the CFAR guard from which the threshold level will be calculated
  [in] | half_guard_length | Number of frequency bins around the point of interest that is omitted when calculating the CFAR threshold
  [in] | sensitivity | Sensitivity of the CFAR threshold
  [in] | idx | Index to calculate cfar for

Returns
  Threshold value at index

Definition at line 892 of file acc_algorithm.c.

## ◆ acc_algorithm_calculate_mirrored_one_sided_cfar()

float acc_algorithm_calculate_mirrored_one_sided_cfar | ( | const float * | data,
|  | uint16_t | data_length,
|  | uint16_t | middle_idx,
|  | uint16_t | window_length,
|  | uint16_t | half_guard_length,
|  | float | sensitivity,
|  | uint16_t | idx
| ) |  |

Calculate mirrored one sided CFAR threshold.

Calculate a one sided CFAR. Guard and window are mirrored on the right half of the data. The threshold is extended to also include the CFAR margin. The margin is of size half_guard_length + window_length.

On the left half this construction is used | Window | Half guard | t(i) |

and on the right half this contruction is used | t(i) | Half guard | Window |

The threshold extension looks like this: threshold = [t(m), t(m) ... t(m) t(m+1) t(m+2) ... t(n-m-2) t(n-m-1) t(n-m) ... t(n-m) t(n-m)] where n = data_length and m = window_length + half_guard_length

Parameters

  [in] | data | Array of data
  [in] | data_length | Length of the data array
  [in] | middle_idx | Middle index
  [in] | window_length | Number of frequency bins next to the CFAR guard from which the threshold level will be calculated
  [in] | half_guard_length | Number of frequency bins around the point of interest that is omitted when calculating the CFAR threshold
  [in] | sensitivity | Sensitivity of the CFAR threshold
  [in] | idx | Index to calculate cfar for

Returns
  Threshold value at index

Definition at line 928 of file acc_algorithm.c.

## ◆ acc_algorithm_cdiv()

float complex acc_algorithm_cdiv | ( | float complex | num,
|  | float complex | denom
| ) |  |

Divide complex number num / denum.

Parameters

  [in] | num | Numerator
  [in] | denom | Denominator

Returns
  num / denom

Definition at line 708 of file acc_algorithm.c.

## ◆ acc_algorithm_clip_f32()

float acc_algorithm_clip_f32 | ( | float | value,
|  | float | min,
|  | float | max
| ) |  |

Clip passed value into the interval [min, max].

Parameters

  [in] | value | The value to clip
  [in] | min | Lower bound of clip interval
  [in] | max | Upper bound of clip interval

Returns
  The clipped value

Definition at line 1431 of file acc_algorithm.c.

## ◆ acc_algorithm_conj_f32()

void acc_algorithm_conj_f32 | ( | float complex * | data,
|  | uint16_t | data_length
| ) |  |

Inline calculate conjugate of all elements in an array.

Parameters

  [in,out] | data | Data array, will be replaced with conjugate values
  [in] | data_length | Length of data array

Definition at line 576 of file acc_algorithm.c.

## ◆ acc_algorithm_count_points_above_threshold()

void acc_algorithm_count_points_above_threshold | ( | const float * | matrix,
|  | uint16_t | rows,
|  | uint16_t | cols,
|  | const float | threshold,
|  | uint16_t * | count,
|  | uint16_t | offset,
|  | uint16_t | threshold_check_length,
|  | uint16_t | axis
| ) |  |

Count points in matrix above threshold row-wise or col-wise.

Parameters

  [in] | matrix | Matrix to check data in
  [in] | rows | Number of rows in matrix
  [in] | cols | Number of cols in matrix
  [in] | threshold | Threshold to check against
  [out] | count | Number of elements above threshold, length = rows if axis = 0 or length = cols if axis = 1
  [in] | offset | Offset on the selected axis where to start to check threshold
  [in] | threshold_check_length | The length of part to check threshold for, row wise if axis = 0 and column wise if axis = 1
  [in] | axis | Axis over which to check, must be 0 or 1

Definition at line 1281 of file acc_algorithm.c.

## ◆ acc_algorithm_double_buffering_frame_filter()

void acc_algorithm_double_buffering_frame_filter | ( | acc_int16_complex_t * | frame,
|  | const uint16_t | sweeps_per_frame,
|  | const uint16_t | num_points,
|  | int32_t * | work_buffer
| ) |  |

Double buffering frame filter.

Detects and removes outliers in data that appear when the double buffering mode is enabled, and returns the filtered frame.

Outliers are detected along the sweep dimension using the second order difference. For reliable outlier detection, the filter is applied only when there are 32 or more sweeps per frame.

The disturbance caused by enabling the double buffering mode can appear in multiple sweeps but, according to observations, is limited to a maximum of two consecutive sweeps. Therefore, the function removes outliers by interpolating between the sample before and the sample two positions ahead.

The function does not correct disturbances that may appear in the initial or final sweeps.

Parameters

  [in,out] | frame | Data frame to where the filter is applied
  [in] | sweeps_per_frame | How many sweeps there are in the frame
  [in] | num_points | The number of points in the frame
  [in] | work_buffer | A work buffer for the filter, length >= (sweeps_per_frame - 2)

Definition at line 774 of file acc_algorithm.c.

## ◆ acc_algorithm_exp_smoothing_coefficient()

float acc_algorithm_exp_smoothing_coefficient | ( | float | fs,
|  | float | tc
| ) |  |

Calculate exponential smoothing coefficient.

Parameters

  [in] | fs | Sampling frequency
  [in] | tc | Time constant

Returns
  Exponential smoothing coefficient, NAN if fs=0 or tc=0

Definition at line 694 of file acc_algorithm.c.

## ◆ acc_algorithm_fft()

void acc_algorithm_fft | ( | const float complex * | data,
|  | uint16_t | data_length,
|  | uint16_t | length_shift,
|  | float complex * | output
| ) |  |

1D Fast Fourier Transform for complex input

Parameters

  [in] | data | Matrix of data
  [in] | data_length | Length of data
  [in] | length_shift | Integer that specifies the transform length N in accordance with N = (1 << length_shift) and N >= rows if axis == 0 or N >= cols if axis == 1
  [out] | output | Array for output data, must be of length N

Definition at line 622 of file acc_algorithm.c.

## ◆ acc_algorithm_fft_matrix()

void acc_algorithm_fft_matrix | ( | const float complex * | data,
|  | uint16_t | rows,
|  | uint16_t | cols,
|  | uint16_t | length_shift,
|  | float complex * | output,
|  | uint16_t | axis
| ) |  |

1D Fast Fourier Transform for input matrix

Parameters

  [in] | data | Matrix of data
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of columns in the matrix
  [in] | length_shift | Integer that specifies the transform length N in accordance with N = (1 << length_shift) and N >= rows if axis == 0 or N >= cols if axis == 1
  [out] | output | Matrix for output data, size = (N, cols) if axis=0 and size = (rows, N) if axis=1
  [in] | axis | Axis over which to calculate the FFT, must be 0 or 1

Definition at line 627 of file acc_algorithm.c.

## ◆ acc_algorithm_fftfreq()

void acc_algorithm_fftfreq | ( | uint16_t | n,
|  | float | d,
|  | float * | freqs
| ) |  |

Calculate the Fast Fourier Transform sample frequencies.

Parameters

  [in] | n | Window length, > 0
  [in] | d | Sample spacing, > 0
  [out] | freqs | Sample frequencies, length >= n

Definition at line 675 of file acc_algorithm.c.

## ◆ acc_algorithm_fftfreq_delta()

float acc_algorithm_fftfreq_delta | ( | uint16_t | n,
|  | float | d
| ) |  |

Calculate delta between frequency bins in rfft.

Parameters

  [in] | n | Window length, > 0
  [in] | d | Sample spacing, > 0

Returns
  Delta between frequency bins

Definition at line 652 of file acc_algorithm.c.

## ◆ acc_algorithm_fftshift()

void acc_algorithm_fftshift | ( | float * | data,
|  | uint16_t | data_length
| ) |  |

Shift the zero-frequency component to the center.

Parameters

  [in,out] | data | Array of data
  [in] | data_length | Length of data

Definition at line 857 of file acc_algorithm.c.

## ◆ acc_algorithm_fftshift_matrix()

void acc_algorithm_fftshift_matrix | ( | float * | data,
|  | uint16_t | rows,
|  | uint16_t | cols
| ) |  |

Shift the zero-frequency component to the center along row dimensions.

Parameters

  [in,out] | data | Matrix to be shifted
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of cols in the matrix

Definition at line 849 of file acc_algorithm.c.

## ◆ acc_algorithm_find_peaks()

bool acc_algorithm_find_peaks | ( | const float * | abs_sweep,
|  | const uint16_t | data_length,
|  | const uint32_t * | threshold_check,
|  | uint16_t * | peak_idxs,
|  | uint16_t | peak_idxs_length,
|  | uint16_t * | num_peaks
| ) |  |

Find peaks above threshold.

A peak is defined as a point with greater value than its two neighbouring points and all three points are above the threshold.

Parameters

  [in] | abs_sweep | Absolute values of the mean sweep
  [in] | data_length | Number of values in the sweep
  [in] | threshold_check | Bit array with information if peak is above or below threshold
  [out] | peak_idxs | Indexes of found peaks
  [in] | peak_idxs_length | Length of the found peaks array. To fit all possible peaks the length must be (abs_sweep_length / 2)
  [out] | num_peaks | Number of found peaks

Returns
  true if all peaks could be found, false otherwise

Definition at line 1178 of file acc_algorithm.c.

## ◆ acc_algorithm_get_distance_idx()

uint16_t acc_algorithm_get_distance_idx | ( | const float * | data,
|  | uint16_t | cols,
|  | uint16_t | rows,
|  | uint16_t | middle_idx,
|  | uint16_t | half_slow_zone
| ) |  |

Find the index of the distance column containing the largest amplitude, disregarding amplitudes present in the slow zone.

Parameters

  [in] | data | Matrix of data
  [in] | cols | Number of cols
  [in] | rows | Number of rows
  [in] | middle_idx | Middle index
  [in] | half_slow_zone | Half size of the number of frequency bins that are regarded as the slow zone

Returns
  Distance index

Definition at line 983 of file acc_algorithm.c.

## ◆ acc_algorithm_get_distance_m()

float acc_algorithm_get_distance_m | ( | uint16_t | step_length,
|  | uint16_t | start_point,
|  | float | base_step_length_m,
|  | uint16_t | idx
| ) |  |

Calculate distance for a point at an index.

Parameters

  [in] | step_length | Step length in points
  [in] | start_point | Start point
  [in] | base_step_length_m | Base step length
  [in] | idx | Distance index

Returns
  Distance at index

Definition at line 1118 of file acc_algorithm.c.

## ◆ acc_algorithm_get_fwhm()

float acc_algorithm_get_fwhm | ( | acc_config_profile_t | profile | ) |

Get the envelope Full Width Half Maximum in meters given a profile.

Parameters

  [in] | profile | The profile to get envelope FWHM for

Returns
  The envelope FWHM in meters or 0.0 if profile is not valid.

Definition at line 745 of file acc_algorithm.c.

## ◆ acc_algorithm_get_peak_velocity()

float acc_algorithm_get_peak_velocity | ( | const float * | velocities,
|  | const float * | energies,
|  | const uint16_t * | peak_idxs,
|  | uint16_t | num_peaks,
|  | float | limit
| ) |  |

Find the velocity of the peak with the largest amplitude, prioritizing peaks with a velocity over the slow zone limit.

Parameters

  [in] | velocities | Array of velocities
  [in] | energies | Array of energies
  [in] | peak_idxs | Indices of identified peaks
  [in] | num_peaks | Number of identified peaks
  [in] | limit | Slow zone limit

Returns
  Peak velocity

Definition at line 1009 of file acc_algorithm.c.

## ◆ acc_algorithm_hamming()

void acc_algorithm_hamming | ( | uint16_t | n,
|  | float * | window
| ) |  |

Calculate hamming window for a specified number of points.

Parameters

  [in] | n | Number of points
  [out] | window | Returned hamming window, length = n

Definition at line 721 of file acc_algorithm.c.

## ◆ acc_algorithm_hann()

void acc_algorithm_hann | ( | uint16_t | n,
|  | float * | window
| ) |  |

Calculate non-symmetrical hann window for a specified number of points.

Parameters

  [in] | n | Number of points
  [out] | window | Returned hann window, length = n

Definition at line 733 of file acc_algorithm.c.

## ◆ acc_algorithm_interpolate_peaks()

float acc_algorithm_interpolate_peaks | ( | const float * | y,
|  | const float * | x
| ) |  |

Interpolate peak.

Parameters

  [in] | y | Amplitudes of frequency peaks
  [in] | x | Frequencies

Returns
  Interpolated frequency

Definition at line 322 of file acc_algorithm.c.

## ◆ acc_algorithm_interpolate_peaks_equidistant()

float acc_algorithm_interpolate_peaks_equidistant | ( | const float * | y,
|  | float | x_start,
|  | float | x_delta,
|  | uint16_t | peak_idx
| ) |  |

Interpolate equidistant peaks.

The function fits a second degree polynomial to three consecutive amplitude values where the 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.

Parameters

  [in] | y | Y values to interpolate
  [in] | x_start | Start value of X-axis
  [in] | x_delta | Delta between values on X-axis
  [in] | peak_idx | Idx of peak

Returns
  Interpolated X-values

Definition at line 330 of file acc_algorithm.c.

## ◆ acc_algorithm_lfilter()

void acc_algorithm_lfilter | ( | const float * | b,
|  | const float * | a,
|  | float * | data,
|  | uint16_t | data_length
| ) |  |

Filter data with a digital filter.

Parameters

  [in] | b | Numerator in polynomial of the IIR filter, length == 5
  [in] | a | Denominator of polynomial of the IIR filter, length == 4
  [in,out] | data | Data array to filter
  [in] | data_length | Length of the array

Definition at line 446 of file acc_algorithm.c.

## ◆ acc_algorithm_lfilter_matrix()

void acc_algorithm_lfilter_matrix | ( | const float * | b,
|  | const float * | a,
|  | float * | data,
|  | uint16_t | rows,
|  | uint16_t | cols
| ) |  |

Filter data along row dimension.

Parameters

  [in] | b | Numerator in polynomial of the IIR filter, length == 5
  [in] | a | Denominator of polynomial of the IIR filter, length == 4
  [in,out] | data | Matrix to filter
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of columns in the matrix

Definition at line 456 of file acc_algorithm.c.

## ◆ acc_algorithm_max_f32()

float acc_algorithm_max_f32 | ( | const float * | data,
|  | uint16_t | length
| ) |  |

Find max value of input data.

Parameters

  [in] | data | Data to find max value for
  [in] | length | Length of data

Returns
  The maximum value

Definition at line 1360 of file acc_algorithm.c.

## ◆ acc_algorithm_mean_i16_complex()

void acc_algorithm_mean_i16_complex | ( | const acc_int16_complex_t * | data,
|  | uint16_t | data_length,
|  | float complex * | out
| ) |  |

Calculate mean value of an array.

Parameters

  [in] | data | Data array
  [in] | data_length | Length of data array
  [out] | out | Output mean value

Definition at line 549 of file acc_algorithm.c.

## ◆ acc_algorithm_mean_matrix_i16_complex()

void acc_algorithm_mean_matrix_i16_complex | ( | const acc_int16_complex_t * | matrix,
|  | uint16_t | rows,
|  | uint16_t | cols,
|  | float complex * | out,
|  | uint16_t | axis
| ) |  |

Calculate mean array of a matrix.

Parameters

  [in] | matrix | Matrix of data
  [in] | rows | Number of rows in matrix
  [in] | cols | Number of columns in matrix
  [out] | out | Output mean array, length = cols if axis = 0 or length = rows if axis = 1
  [in] | axis | Axis over which to calculate mean, must be 0 or 1

Definition at line 554 of file acc_algorithm.c.

## ◆ acc_algorithm_mean_sweep()

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.

Parameters

  [in] | frame | Frame to calculate mean sweep for
  [in] | num_points | Number of points in a sweep
  [in] | sweeps_per_frame | Number of sweeps in the frame
  [in] | start_point | Start point of mean sweep, if 0 will be same start point as for sweeps in frame
  [in] | end_point | End point of mean sweep, if num_points will be same end point as for sweeps in frame
  [out] | sweep | Mean sweep returned from calculation, length >= (end_point - start_point)

Definition at line 523 of file acc_algorithm.c.

## ◆ acc_algorithm_median_f32()

float acc_algorithm_median_f32 | ( | float * | data,
|  | uint16_t | length
| ) |  |

Calculate median of input data.

Note that this function sorts inplace and the data array will altered

Parameters

  [in,out] | data | Array of float values
  [in] | length | Length of data

Returns
  The calculated median value

Examples
  ref_app_tank_level.c.

Definition at line 1342 of file acc_algorithm.c.

## ◆ acc_algorithm_median_i16()

int16_t acc_algorithm_median_i16 | ( | int16_t * | data,
|  | uint16_t | length
| ) |  |

Calculate median of input data.

Median of data of even length is rounded down. Note that this function sorts inplace and the data array will altered

Parameters

  [in,out] | data | Array of int16_t values
  [in] | length | Length of data

Returns
  The calculated median value

Definition at line 1324 of file acc_algorithm.c.

## ◆ acc_algorithm_merge_peaks()

bool acc_algorithm_merge_peaks | ( | float | max_peak_separation,
|  | const float * | velocities,
|  | const float * | energies,
|  | const uint16_t * | peak_idxs,
|  | uint16_t | num_peaks,
|  | float * | merged_velocities,
|  | float * | merged_energies,
|  | uint16_t | merged_peaks_length,
|  | uint16_t * | num_merged_peaks
| ) |  |

Merges peaks.

Parameters

  [in] | max_peak_separation | The greatest distance (in meters) between peaks that will result in a merge
  [in] | velocities | The velocities to merge
  [in] | energies | The energies to merge
  [in] | peak_idxs | Indices of identified peaks
  [in] | num_peaks | Number of peaks in the peak_idxs array, if 0 nothing will happen
  [out] | merged_velocities | Output array for the merged velocities
  [out] | merged_energies | Output array for the merged energies
  [in] | merged_peaks_length | The length of the merged_velocities and merged_energies arrays
  [out] | num_merged_peaks | The number of peaks that were merged

Returns
  true if successful, false otherwise

Definition at line 1044 of file acc_algorithm.c.

## ◆ acc_algorithm_normalize_f32_complex()

void acc_algorithm_normalize_f32_complex | ( | float complex * | data,
|  | uint16_t | data_length
| ) |  |

Normalize all elements in an array individually.

Parameters

  [in,out] | data | Data array, will be replaced by normalized values
  [in] | data_length | Length of data array

Definition at line 584 of file acc_algorithm.c.

## ◆ acc_algorithm_rfft()

void acc_algorithm_rfft | ( | const float * | data,
|  | uint16_t | data_length,
|  | uint16_t | length_shift,
|  | float complex * | output
| ) |  |

1D Fast Fourier Transform for real input

Parameters

  [in] | data | Array of data
  [in] | data_length | Length of data
  [in] | length_shift | Integer that specifies the transform length N in accordance with N = (1 << length_shift) and N >= data_length
  [out] | output | Array for output data, length >= (data_length / 2) + 1

Definition at line 592 of file acc_algorithm.c.

## ◆ acc_algorithm_rfft_matrix()

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

Parameters

  [in] | data | Matrix of data
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of columns in the matrix
  [in] | length_shift | Integer that specifies the transform length N in accordance with N = (1 << length_shift) and N >= rows if axis == 0 or N >= cols if axis == 1
  [out] | output | Matrix for output data, size = ((rows / 2) + 1, cols) if axis=0 and size = (rows, (cols / 2) + 1) if axis=1
  [in] | axis | Axis over which to calculate the FFT, must be 0 or 1

Definition at line 597 of file acc_algorithm.c.

## ◆ acc_algorithm_rfftfreq()

void acc_algorithm_rfftfreq | ( | uint16_t | n,
|  | float | d,
|  | float * | freqs
| ) |  |

Calculate the real Fast Fourier Transform sample frequencies.

Parameters

  [in] | n | Window length, > 0
  [in] | d | Sample spacing, > 0
  [out] | freqs | Sample frequencies, length >= (n / 2) + 1

Definition at line 664 of file acc_algorithm.c.

## ◆ acc_algorithm_roll_and_push()

void acc_algorithm_roll_and_push | ( | float * | data,
|  | uint16_t | data_length,
|  | float | element
| ) |  |

Roll array elements and push new element last.

Parameters

  [in,out] | data | Array to be rolled
  [in] | data_length | Length of the array
  [in] | element | The new element

Definition at line 159 of file acc_algorithm.c.

## ◆ acc_algorithm_roll_and_push_matrix_f32()

void acc_algorithm_roll_and_push_matrix_f32 | ( | float * | data,
|  | uint16_t | rows,
|  | uint16_t | cols,
|  | const float * | column,
|  | bool | pos_shift
| ) |  |

Roll row elements and push a new column.

Parameters

  [in,out] | data | Matrix to be rolled of size rows*cols
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of cols in the matrix
  [in] | column | The new column
  [in] | pos_shift | If true will be the same as shift=1 in np.roll, otherwise the same as shift=-1

Definition at line 169 of file acc_algorithm.c.

## ◆ acc_algorithm_roll_and_push_matrix_f32_complex()

void acc_algorithm_roll_and_push_matrix_f32_complex | ( | float complex * | data,
|  | uint16_t | rows,
|  | uint16_t | cols,
|  | const float complex * | column,
|  | bool | pos_shift
| ) |  |

Roll row elements and push a new column.

Parameters

  [in,out] | data | Matrix to be rolled of size rows*cols
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of cols in the matrix
  [in] | column | The new column
  [in] | pos_shift | If true will be the same as shift=1 in np.roll, otherwise the same as shift=-1

Definition at line 203 of file acc_algorithm.c.

## ◆ acc_algorithm_roll_and_push_mult_matrix_i16_complex()

void acc_algorithm_roll_and_push_mult_matrix_i16_complex | ( | acc_int16_complex_t * | data,
|  | uint16_t | data_rows,
|  | uint16_t | cols,
|  | const acc_int16_complex_t * | matrix,
|  | uint16_t | matrix_rows,
|  | bool | pos_shift
| ) |  |

Roll row elements and push multiple columns.

Parameters

  [in,out] | data | Matrix to be rolled
  [in] | data_rows | Number of rows in data matrix
  [in] | cols | Number of cols in data matrix
  [in] | matrix | Matrix with new columns
  [in] | matrix_rows | Number of rows in the matrix
  [in] | pos_shift | If true will be the same as shift=1 in np.roll, otherwise the same as shift=-1

Definition at line 237 of file acc_algorithm.c.

## ◆ acc_algorithm_select_prf()

acc_config_prf_t acc_algorithm_select_prf | ( | int16_t | breakpoint,
|  | acc_config_profile_t | profile,
|  | float | base_step_length
| ) |  |

Select a suitable PRF given a breakpoint and profile.

Parameters

  [in] | breakpoint | A base step, relative to start_point = 0
  [in] | profile | The profile at breakpoint
  [in] | base_step_length | The base step length

Returns
  A suitable PRF

Definition at line 1144 of file acc_algorithm.c.

## ◆ acc_algorithm_select_profile()

acc_config_profile_t acc_algorithm_select_profile | ( | int32_t | start_point,
|  | float | base_step_length
| ) |  |

Select the highest possible profile without interference of direct leakage.

Parameters

  [in] | start_point | Start point
  [in] | base_step_length | base_step_length

Returns
  A suitable profile

Definition at line 1125 of file acc_algorithm.c.

## ◆ acc_algorithm_stddev_f32()

float acc_algorithm_stddev_f32 | ( | const float * | data,
|  | uint16_t | length
| ) |  |

Calculate standard deviation.

Parameters

  [in] | data | Data to calculate standard deviation for
  [in] | length | Length of data, should be > 1

Returns
  The standard deviation

Definition at line 1426 of file acc_algorithm.c.

## ◆ acc_algorithm_sum_sweep()

void acc_algorithm_sum_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 * | sum_sweep
| ) |  |

Calculate the sum of all sweeps in a frame, from start_point to end_point.

Parameters

  [in] | frame | Frame to calculate summed sweep for
  [in] | num_points | Number of points in a sweep
  [in] | sweeps_per_frame | Number of sweeps in the frame
  [in] | start_point | Start point of sum sweep, if 0 will be same start point as for sweeps in frame
  [in] | end_point | End point of sum sweep, if num_points will be same end point as for sweeps in frame
  [out] | sum_sweep | Summed sweep returned from calculation, length >= (end_point - start_point)

Definition at line 536 of file acc_algorithm.c.

## ◆ acc_algorithm_unwrap()

void acc_algorithm_unwrap | ( | float * | data,
|  | uint16_t | data_length
| ) |  |

Unwraps a signal by changing elements which have an absolute difference from their predecessor of more than 2*pi to their period-complementary values.

Parameters

  [in,out] | data | Array with signal data
  [in] | data_length | Length of the array

Definition at line 283 of file acc_algorithm.c.

## ◆ acc_algorithm_variance_f32()

float acc_algorithm_variance_f32 | ( | const float * | data,
|  | uint16_t | length
| ) |  |

Calculate variance.

Parameters

  [in] | data | Data to calculate variance for
  [in] | length | Length of data, should be > 1

Returns
  The variance

Definition at line 1399 of file acc_algorithm.c.

## ◆ acc_algorithm_weighted_mean()

float acc_algorithm_weighted_mean | ( | const float * | data,
|  | const float * | weights,
|  | uint16_t | length
| ) |  |

Calculate weighted mean.

Parameters

  [in] | data | Data to calculate weighted mean for
  [in] | weights | Weighs for each data point in data
  [in] | length | Length of data and weights, must be > 0

Returns
  The weighted mean

Definition at line 1375 of file acc_algorithm.c.

## ◆ acc_algorithm_welch()

void acc_algorithm_welch | ( | const float complex * | data,
|  | uint16_t | data_length,
|  | uint16_t | segment_length,
|  | float complex * | data_buffer,
|  | float complex * | fft_out,
|  | float * | psd,
|  | const float * | window,
|  | uint16_t | length_shift,
|  | float | fs
| ) |  |

Estimate power spectral density using Welch’s method.

Computes an estimate of the PSD by dividing the data into non-overlapping segments, computing a periodogram for each segment and averaging the periodograms.

Parameters

  [in] | data | Array of data
  [in] | data_length | Length of data
  [in] | segment_length | Length of each segment
  [in] | data_buffer | Buffer used for calculations, length = segment_length
  [out] | fft_out | Array for fft output data, must be of length N
  [out] | psd | Array for output data, length = segment_length
  [in] | window | Desired window to use, length = segment_length
  [in] | length_shift | Integer that specifies the transform length N in accordance with N = 1 << length_shift and N >= segment_length
  [in] | fs | Sampling frequency

Definition at line 879 of file acc_algorithm.c.

## ◆ acc_algorithm_welch_matrix()

void acc_algorithm_welch_matrix | ( | const float complex * | data,
|  | uint16_t | rows,
|  | uint16_t | cols,
|  | uint16_t | segment_length,
|  | float complex * | data_buffer,
|  | float complex * | fft_out,
|  | float * | psds,
|  | const float * | window,
|  | uint16_t | length_shift,
|  | float | fs
| ) |  |

Estimate power spectral density (PSD) using Welch’s method along row dimensions.

See acc_algorithm_welch for more details

Parameters

  [in] | data | Matrix of data
  [in] | rows | Number of rows in the matrix
  [in] | cols | Number of cols in the matrix
  [in] | segment_length | Length of each segment
  [in] | data_buffer | Buffer used for calculations, length = segment_length
  [out] | fft_out | Array for fft output data, must be of length N
  [out] | psds | Matrix for output data, size = (cols, segment_length)
  [in] | window | Desired window to use, length = segment_length
  [in] | length_shift | Integer that specifies the transform length N in accordance with N = 1 << length_shift and N >= segment_length
  [in] | fs | Sampling frequency

Definition at line 862 of file acc_algorithm.c.