acc_algorithm.h
Go to the documentation of this file.
1 // Copyright (c) Acconeer AB, 2023
2 // All rights reserved
3 
4 #ifndef ACC_ALGORITHM_H_
5 #define ACC_ALGORITHM_H_
6 
7 #include <complex.h>
8 #include <stdint.h>
9 
10 #include "acc_config.h"
11 #include "acc_definitions_a121.h"
12 #include "acc_definitions_common.h"
13 
14 
15 /**
16  * @brief Roll array elements and push new element last
17  *
18  * @param[in, out] data Array to be rolled
19  * @param[in] data_length Length of the array
20  * @param[in] element The new element
21  */
22 void acc_algorithm_roll_and_push(float *data, uint16_t data_length, float element);
23 
24 
25 /**
26  * @brief Roll row elements and push a new column
27  *
28  * @param[in, out] data Matrix to be rolled of size rows*cols
29  * @param[in] rows Number of rows in the matrix
30  * @param[in] cols Number of cols in the matrix
31  * @param[in] column The new column
32  * @param[in] pos_shift If true will be the same as shift=1 in np.roll, otherwise the same as shift=-1
33  */
34 void acc_algorithm_roll_and_push_f32_matrix(float *data, uint16_t rows, uint16_t cols, const float *column, bool pos_shift);
35 
36 
37 /**
38  * @brief Roll row elements and push a new column
39  *
40  * @param[in, out] data Matrix to be rolled of size rows*cols
41  * @param[in] rows Number of rows in the matrix
42  * @param[in] cols Number of cols in the matrix
43  * @param[in] column The new column
44  * @param[in] pos_shift If true will be the same as shift=1 in np.roll, otherwise the same as shift=-1
45  */
46 void acc_algorithm_roll_and_push_f32_complex_matrix(float complex *data, uint16_t rows, uint16_t cols, const float complex *column,
47  bool pos_shift);
48 
49 
50 /**
51  * @brief Unwraps a signal by changing elements which have an absolute difference from
52  * their predecessor of more than 2*pi to their period-complementary values.
53  *
54  * @param[in, out] data Array with signal data
55  * @param[in] data_length Length of the array
56  */
57 void acc_algorithm_unwrap(float *data, uint16_t data_length);
58 
59 
60 /**
61  * @brief Find index of largest element in the array
62  *
63  * @param[in] data Array of data
64  * @param[in] data_length Length of the array
65  * @return Index of largest element
66  */
67 uint16_t acc_algorithm_argmax(const float *data, uint16_t data_length);
68 
69 
70 /**
71  * @brief Interpolate peak
72  *
73  * @param[in] y Amplitudes of frequency peaks
74  * @param[in] x Frequencies
75  * @return Interpolated frequency
76  */
77 float acc_algorithm_interpolate_peaks(const float *y, const float *x);
78 
79 
80 /**
81  * @brief Interpolate equidistant peaks
82  *
83  * The function fits a second degree polynomial to three consecutive amplitude
84  * values where the second element is expected to contain the maximum measured amplitude.
85  * The function then finds the position of the maximum amplitude of the polynomial.
86  * The position is normalized.
87  *
88  * @param[in] y Y values to interpolate
89  * @param[in] x_start Start value of X-axis
90  * @param[in] x_delta Delta between values on X-axis
91  * @param[in] peak_idx Idx of peak
92  * @return Interpolated X-values
93  */
94 float acc_algorithm_interpolate_peaks_equidistant(const float *y, float x_start, float x_delta, uint16_t peak_idx);
95 
96 
97 /**
98  * @brief Design a 2nd order digital Butterworth lowpass filter
99  *
100  * @param[in] freq Cutoff freuency
101  * @param[in] fs Sampling frequency, > 0 Hz
102  * @param[out] b Numerator in polynomial of the IIR filter, length == 3
103  * @param[out] a Denominator of polynomial of the IIR filter, length == 2
104  */
105 void acc_algorithm_butter_lowpass(float freq, float fs, float *b, float *a);
106 
107 
108 /**
109  * @brief Design a 2nd order digital Butterworth bandpass filter
110  *
111  * @param[in] min_freq Low cutoff frequency
112  * @param[in] max_freq High cutoff frequency
113  * @param[in] fs Sampling frequency, > 0 Hz
114  * @param[out] b Numerator in polynomial of the IIR filter, length == 5
115  * @param[out] a Denominator of polynomial of the IIR filter, length == 4
116  */
117 void acc_algorithm_butter_bandpass(float min_freq, float max_freq, float fs, float *b, float *a);
118 
119 
120 /**
121  * @brief Filter data with a digital filter
122  *
123  * @param[in] b Numerator in polynomial of the IIR filter, length == 5
124  * @param[in] a Denominator of polynomial of the IIR filter, length == 4
125  * @param[in, out] data Data array to filter
126  * @param[in] data_length Length of the array
127  */
128 void acc_algorithm_lfilter(const float *b, const float *a, float *data, uint16_t data_length);
129 
130 
131 /**
132  * @brief Filter data along row dimension
133  *
134  * @param[in] b Numerator in polynomial of the IIR filter, length == 5
135  * @param[in] a Denominator of polynomial of the IIR filter, length == 4
136  * @param[in, out] data Matrix to filter
137  * @param[in] rows Number of rows in the matrix
138  * @param[in] cols Number of columns in the matrix
139  */
140 void acc_algorithm_lfilter_matrix(const float *b, const float *a, float *data, uint16_t rows, uint16_t cols);
141 
142 
143 /**
144  * @brief Apply filter coefficients to filtered data matrix and data matrix
145  *
146  * @param[in] a Denominator of polynomial of the IIR filter
147  * @param[in] filt_data Filtered data matrix
148  * @param[in] filt_rows Number of rows in filtered data matrix, == len(a)
149  * @param[in] filt_cols Number of columns in filtered data matrix, == data_cols
150  * @param[in] b Numerator of polynomial of the IIR filter
151  * @param[in] data Data matrix
152  * @param[in] data_rows Number of rows in data matrix, == len(b)
153  * @param[in] data_cols Number of columns in data matrix, == filt_cols
154  * @param[out] output Output filtered data array
155  * @param[in] output_length Length of output, == data_cols and filt_cols
156  */
157 void acc_algorithm_apply_filter(const float *a, const float *filt_data, uint16_t filt_rows, uint16_t filt_cols, const float *b,
158  const float *data, uint16_t data_rows, uint16_t data_cols, float *output, uint16_t output_length);
159 
160 
161 /**
162  * @brief Apply filter coefficients to filtered data matrix and data matrix
163  *
164  * @param[in] a Denominator of polynomial of the IIR filter
165  * @param[in] filt_data Filtered data matrix
166  * @param[in] filt_rows Number of rows in filtered data matrix, == len(a)
167  * @param[in] filt_cols Number of columns in filtered data matrix, == data_cols
168  * @param[in] b Numerator of polynomial of the IIR filter
169  * @param[in] data Data matrix
170  * @param[in] data_rows Number of rows in data matrix, == len(b)
171  * @param[in] data_cols Number of columns in data matrix, == filt_cols
172  * @param[out] output Output filtered data array
173  * @param[in] output_length Length of output, == data_cols and filt_cols
174  */
175 void acc_algorithm_apply_filter_complex(const float *a, const float complex *filt_data, uint16_t filt_rows, uint16_t filt_cols,
176  const float *b, const float complex *data, uint16_t data_rows, uint16_t data_cols,
177  float complex *output, uint16_t output_length);
178 
179 
180 /**
181  * @brief Calculate mean sweep of a frame from start_point to end_point
182  *
183  * @param[in] frame Frame to calculate mean sweep for
184  * @param[in] num_points Number of points in a sweep
185  * @param[in] sweeps_per_frame Number of sweeps in the frame
186  * @param[in] start_point Start point of mean sweep, if 0 will be same start point as for sweeps in frame
187  * @param[in] end_point End point of mean sweep, if num_points will be same end point as for sweeps in frame
188  * @param[out] sweep Mean sweep returned from calculation, length >= (end_point - start_point)
189  */
190 void acc_algorithm_mean_sweep(const acc_int16_complex_t *frame, uint16_t num_points, uint16_t sweeps_per_frame, uint16_t start_point,
191  uint16_t end_point, float complex *sweep);
192 
193 
194 /**
195  * @brief 1D Fast Fourier Transform for real input
196  *
197  * @param[in] data Array of data
198  * @param[in] data_length Length of data
199  * @param[in] length_shift Integer that specifies the transform length N in accordance with N = (1 << length_shift) and N >= data_length
200  * @param[out] output Array for output data, length >= (data_length / 2) + 1
201  * @param[in] stride Used when calculating rfft of a matrix, for an array set stride = 1
202  */
203 void acc_algorithm_rfft(const float *data, uint16_t data_length, uint16_t length_shift, float complex *output, uint16_t stride);
204 
205 
206 /**
207  * @brief 1D Fast Fourier Transform for real input matrix
208  *
209  * @param[in] data Matrix of data
210  * @param[in] rows Number of rows in the matrix
211  * @param[in] cols Number of columns in the matrix
212  * @param[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
213  * @param[out] output Matrix for output data, size = ((rows / 2) + 1, cols) if axis=0 and size = (rows, (cols / 2) + 1) if axis=1
214  * @param[in] axis Axis over which to calculate the FFT, must be 0 or 1
215  */
216 void acc_algorithm_rfft_matrix(const float *data, uint16_t rows, uint16_t cols, uint16_t length_shift, float complex *output, uint16_t axis);
217 
218 
219 /**
220  * @brief 1D Fast Fourier Transform for complex input
221  *
222  * @param[in] data Matrix of data
223  * @param[in] data_length Length of data
224  * @param[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
225  * @param[out] output Array for output data, must be of length N
226  * @param[in] stride Used when calculating rfft of a matrix, for an array set stride = 1
227  */
228 void acc_algorithm_fft(const float complex *data, uint16_t data_length, uint16_t length_shift, float complex *output, uint16_t stride);
229 
230 
231 /**
232  * @brief 1D Fast Fourier Transform for input matrix
233  *
234  * @param[in] data Matrix of data
235  * @param[in] rows Number of rows in the matrix
236  * @param[in] cols Number of columns in the matrix
237  * @param[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
238  * @param[out] output Matrix for output data, size = (N, cols) if axis=0 and size = (rows, N) if axis=1
239  * @param[in] axis Axis over which to calculate the FFT, must be 0 or 1
240  */
241 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);
242 
243 
244 /** @brief Calculate delta between frequency bins in rfft
245  *
246  * @param[in] n Window length, > 0
247  * @param[in] d Sample spacing, > 0
248  * @return Delta between frequency bins
249  */
250 float acc_algorithm_fftfreq_delta(uint16_t n, float d);
251 
252 
253 /**
254  * @brief Calculate the real Fast Fourier Transform sample frequencies
255  *
256  * @param[in] n Window length, > 0
257  * @param[in] d Sample spacing, > 0
258  * @param[out] freqs Sample frequencies, length >= (n / 2) + 1
259  */
260 void acc_algorithm_rfftfreq(uint16_t n, float d, float *freqs);
261 
262 
263 /**
264  * @brief Calculate the Fast Fourier Transform sample frequencies
265  *
266  * @param[in] n Window length, > 0
267  * @param[in] d Sample spacing, > 0
268  * @param[out] freqs Sample frequencies, length >= n
269  */
270 void acc_algorithm_fftfreq(uint16_t n, float d, float *freqs);
271 
272 
273 /**
274  * @brief Calculate exponential smoothing coefficient
275  *
276  * @param[in] fs Sampling frequency
277  * @param[in] tc Time constant
278  *
279  * @return Exponential smoothing coefficient, NAN if fs=0 or tc=0
280  */
281 float acc_algorithm_exp_smoothing_coefficient(float fs, float tc);
282 
283 
284 /**
285  * @brief Divide complex number num / denum
286  *
287  * @param[in] num Numerator
288  * @param[in] denom Denominator
289  *
290  * @return num / denom
291  */
292 float complex acc_algorithm_cdiv(float complex num, float complex denom);
293 
294 
295 /**
296  * @brief Calculate hamming window for a specified number of points
297  *
298  * @param[in] n Number of points
299  * @param[out] window Returned hamming window, length = n
300  */
301 void acc_algorithm_hamming(uint16_t n, float *window);
302 
303 
304 /**
305  * @brief Calculate non-symmetrical hann window for a specified number of points
306  *
307  * @param[in] n Number of points
308  * @param[out] window Returned hann window, length = n
309  */
310 void acc_algorithm_hann(uint16_t n, float *window);
311 
312 
313 /**
314  * @brief Get the envelope Full Width Half Maximum in meters given a profile
315  *
316  * @param[in] profile The profile to get envelope FWHM for
317  * @return The envelope FWHM in meters or 0.0 if profile is not valid.
318  */
320 
321 
322 /**
323  * @brief Double buffering frame filter
324  *
325  * Detects and removes outliers in data that appear when the double buffering mode is enabled,
326  * and returns the filtered frame.
327  *
328  * Outliers are detected along the sweep dimension using the second order difference. For
329  * reliable outlier detection, the filter is applied only when there are 32 or more sweeps per frame.
330  *
331  * The disturbance caused by enabling the double buffering mode can appear in multiple sweeps
332  * but, according to observations, is limited to a maximum of two consecutive sweeps. Therefore, the
333  * function removes outliers by interpolating between the sample before and the sample two positions
334  * ahead.
335  *
336  * The function does not correct disturbances that may appear in the initial or final sweeps.
337  *
338  * @param[in, out] frame Data frame to where the filter is applied
339  * @param[in] sweeps_per_frame How many sweeps there are in the frame
340  * @param[in] num_points The number of points in the frame
341  * @param[in] work_buffer A work buffer for the filter, length >= (sweeps_per_frame - 2)
342  */
344  const uint16_t sweeps_per_frame,
345  const uint16_t num_points,
346  int32_t *work_buffer);
347 
348 
349 /**
350  * @brief Shift the zero-frequency component to the center along row dimensions
351  *
352  * @param[in, out] data Matrix to be shifted
353  * @param[in] rows Number of rows in the matrix
354  * @param[in] cols Number of cols in the matrix
355  */
356 void acc_algorithm_fftshift_matrix(float *data, uint16_t rows, uint16_t cols);
357 
358 
359 /**
360  * @brief Shift the zero-frequency component to the center
361  *
362  * @param[in, out] data Array of data
363  * @param[in] data_length Length of data
364  * @param[in] stride Used when performing fftshift on a matrix, for an array set stride = 1
365  */
366 void acc_algorithm_fftshift(float *data, uint16_t data_length, uint16_t stride);
367 
368 
369 /**
370  * @brief Estimate power spectral density (PSD) using Welch’s method along row dimensions
371  *
372  * See @ref acc_algorithm_welch for more details
373  *
374  * @param[in] data Matrix of data
375  * @param[in] rows Number of rows in the matrix
376  * @param[in] cols Number of cols in the matrix
377  * @param[in] segment_length Length of each segment
378  * @param[in] data_buffer Buffer used for calculations, length = segment_length
379  * @param[out] fft_out Array for fft output data, length = segment_length
380  * @param[out] psds Matrix for output data, size = (cols, segment_length)
381  * @param[in] window Desired window to use, length = segment_length
382  * @param[in] length_shift Integer that specifies the transform length N in accordance with N = 1 << length_shift and N >= segment_length
383  * @param[in] fs Sampling frequency
384  */
385 void acc_algorithm_welch_matrix(const float complex *data,
386  uint16_t rows,
387  uint16_t cols,
388  uint16_t segment_length,
389  float complex *data_buffer,
390  float complex *fft_out,
391  float *psds,
392  const float *window,
393  uint16_t length_shift,
394  float fs);
395 
396 
397 /**
398  * @brief Estimate power spectral density using Welch’s method
399  *
400  * Computes an estimate of the PSD by dividing the data into non-overlapping segments,
401  * computing a periodogram for each segment and averaging the periodograms.
402  *
403  * @param[in] data Array of data
404  * @param[in] data_length Length of data
405  * @param[in] segment_length Length of each segment
406  * @param[in] data_buffer Buffer used for calculations, length = segment_length
407  * @param[out] fft_out Array for fft output data, length = segment_length
408  * @param[out] psd Array for output data, length = segment_length
409  * @param[in] window Desired window to use, length = segment_length
410  * @param[in] length_shift Integer that specifies the transform length N in accordance with N = 1 << length_shift and N >= segment_length
411  * @param[in] fs Sampling frequency
412  * @param[in] stride Used when calculating psd of a matrix, for an array set stride = 1
413  */
414 void acc_algorithm_welch(const float complex *data,
415  uint16_t data_length,
416  uint16_t segment_length,
417  float complex *data_buffer,
418  float complex *fft_out,
419  float *psd,
420  const float *window,
421  uint16_t length_shift,
422  float fs,
423  uint16_t stride);
424 
425 
426 /**
427  * @brief Calculate CFAR threshold
428  *
429  * @param[in] data Array of data
430  * @param[in] data_length Length of the data array
431  * @param[in] middle_idx Middle index
432  * @param[in] cfar_win_length Number of frequency bins next to the CFAR guard from which the threshold level will be calculated
433  * @param[in] cfar_guard_length Number of frequency bins around the point of interest that is omitted when calculating the CFAR threshold
434  * @param[in] cfar_sensitivity Sensitivity of the CFAR threshold
435  * @param[in] idx Index to calculate cfar for
436  * @return Threshold value at index
437  */
438 float acc_algorithm_calculate_cfar(const float *data,
439  uint16_t data_length,
440  uint16_t middle_idx,
441  uint16_t cfar_win_length,
442  uint16_t cfar_guard_length,
443  float cfar_sensitivity,
444  uint16_t idx);
445 
446 
447 /**
448  * @brief Find the index of the distance column containing the largest amplitude, disregarding amplitudes present in the slow zone
449  *
450  * @param[in] data Matrix of data
451  * @param[in] cols Number of cols
452  * @param[in] rows Number of rows
453  * @param[in] middle_idx Middle index
454  * @param[in] half_slow_zone Half size of the number of frequency bins that are regarded as the slow zone
455  * @return Distance index
456  */
457 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);
458 
459 
460 /**
461  * @brief Find the velocity of the peak with the largest amplitude, prioritizing peaks with a velocity over the slow zone limit
462  *
463  * @param[in] velocities Array of velocities
464  * @param[in] energies Array of energies
465  * @param[in] peak_idxs Indices of identified peaks
466  * @param[in] num_peaks Number of identified peaks
467  * @param[in] limit Slow zone limit
468  * @return Peak velocity
469  */
470 float acc_algorithm_get_peak_velocity(const float *velocities,
471  const float *energies,
472  const uint16_t *peak_idxs,
473  uint16_t num_peaks,
474  float limit);
475 
476 
477 /**
478  * @brief Merges peaks
479  *
480  * @param[in] max_peak_separation The greatest distance (in meters) between peaks that will result in a merge
481  * @param[in] velocities The velocities to merge
482  * @param[in] energies The energies to merge
483  * @param[in] peak_idxs Indices of identified peaks
484  * @param[in] num_peaks Number of peaks in the peak_idxs array, if 0 nothing will happen
485  * @param[out] merged_velocities Output array for the merged velocities
486  * @param[out] merged_energies Output array for the merged energies
487  * @param[in] merged_peaks_length The length of the merged_velocities and merged_energies arrays
488  * @param[out] num_merged_peaks The number of peaks that were merged
489  * @return true if successful, false otherwise
490  */
491 bool acc_algorithm_merge_peaks(float max_peak_separation,
492  const float *velocities,
493  const float *energies,
494  const uint16_t *peak_idxs,
495  uint16_t num_peaks,
496  float *merged_velocities,
497  float *merged_energies,
498  uint16_t merged_peaks_length,
499  uint16_t *num_merged_peaks);
500 
501 
502 /**
503  * @brief Calculate distance for a point at an index
504  *
505  * @param[in] step_length Step length in points
506  * @param[in] start_point Start point
507  * @param[in] base_step_length_m Base step length
508  * @param[in] idx Distance index
509  * @return Distance at index
510  */
511 float acc_algorithm_get_distance_m(uint16_t step_length, uint16_t start_point, float base_step_length_m, uint16_t idx);
512 
513 
514 /**
515  * @brief Select the highest possible profile without interference of direct leakage
516  *
517  * @param[in] start_point Start point
518  * @param[in] base_step_length base_step_length
519  * @return A suitable profile
520  */
521 acc_config_profile_t acc_algorithm_select_profile(int32_t start_point, float base_step_length);
522 
523 
524 /**
525  * @brief Select a suitable PRF given a breakpoint and profile
526  *
527  * @param[in] breakpoint A base step, relative to start_point = 0
528  * @param[in] profile The profile at breakpoint
529  * @param[in] base_step_length The base step length
530  * @return A suitable PRF
531  */
532 acc_config_prf_t acc_algorithm_select_prf(int16_t breakpoint, acc_config_profile_t profile, float base_step_length);
533 
534 
535 /**
536  * @brief Find peaks above threshold
537  *
538  * A peak is defined as a point with greater value than its two neighbouring
539  * points and all three points are above the threshold.
540  *
541  * @param[in] abs_sweep Absolute values of the mean sweep
542  * @param[in] data_length Number of values in the sweep
543  * @param[in] threshold_check Bit array with information if peak is above or below threshold
544  * @param[out] peak_idxs Indexes of found peaks
545  * @param[in] peak_idxs_length Length of the found peaks array. To fit all possible
546  * peaks the length must be (abs_sweep_length / 2)
547  * @param[out] num_peaks Number of found peaks
548  * @return true if all peaks could be found, false otherwise
549  */
550 bool acc_algorithm_find_peaks(const float *abs_sweep, const uint16_t data_length, const uint32_t *threshold_check, uint16_t *peak_idxs,
551  uint16_t peak_idxs_length, uint16_t *num_peaks);
552 
553 
554 #endif
acc_algorithm_exp_smoothing_coefficient
float acc_algorithm_exp_smoothing_coefficient(float fs, float tc)
Calculate exponential smoothing coefficient.
Definition: acc_algorithm.c:577
acc_algorithm_fftshift
void acc_algorithm_fftshift(float *data, uint16_t data_length, uint16_t stride)
Shift the zero-frequency component to the center.
Definition: acc_algorithm.c:747
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 mor...
Definition: acc_algorithm.c:204
acc_config_profile_t
acc_config_profile_t
Profile.
Definition: acc_definitions_a121.h:39
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.
Definition: acc_algorithm.c:1043
acc_int16_complex_t
Data type for interger-based representation of complex numbers.
Definition: acc_definitions_common.h:43
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.
Definition: acc_algorithm.c:662
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, uint16_t stride)
Estimate power spectral density using Welch’s method.
Definition: acc_algorithm.c:784
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.
Definition: acc_algorithm.c:255
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
Definition: acc_algorithm.c:506
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.
Definition: acc_algorithm.c:122
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...
Definition: acc_algorithm.c:927
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.
Definition: acc_algorithm.c:1051
acc_algorithm_interpolate_peaks
float acc_algorithm_interpolate_peaks(const float *y, const float *x)
Interpolate peak.
Definition: acc_algorithm.c:245
acc_algorithm_fftfreq
void acc_algorithm_fftfreq(uint16_t n, float d, float *freqs)
Calculate the Fast Fourier Transform sample frequencies.
Definition: acc_algorithm.c:557
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.
Definition: acc_algorithm.c:765
acc_config_prf_t
acc_config_prf_t
Pulse Repetition Frequency.
Definition: acc_definitions_a121.h:103
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.
Definition: acc_algorithm.c:738
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.
Definition: acc_algorithm.c:1107
acc_algorithm_rfftfreq
void acc_algorithm_rfftfreq(uint16_t n, float d, float *freqs)
Calculate the real Fast Fourier Transform sample frequencies.
Definition: acc_algorithm.c:545
acc_algorithm_fft
void acc_algorithm_fft(const float complex *data, uint16_t data_length, uint16_t length_shift, float complex *output, uint16_t stride)
1D Fast Fourier Transform for complex input
Definition: acc_algorithm.c:500
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.
Definition: acc_algorithm.c:263
acc_algorithm_argmax
uint16_t acc_algorithm_argmax(const float *data, uint16_t data_length)
Find index of largest element in the array.
Definition: acc_algorithm.c:227
acc_algorithm_hann
void acc_algorithm_hann(uint16_t n, float *window)
Calculate non-symmetrical hann window for a specified number of points.
Definition: acc_algorithm.c:619
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
Definition: acc_algorithm.c:474
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 prese...
Definition: acc_algorithm.c:900
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.
Definition: acc_algorithm.c:441
acc_algorithm_apply_filter
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.
Definition: acc_algorithm.c:395
acc_algorithm_fftfreq_delta
float acc_algorithm_fftfreq_delta(uint16_t n, float d)
Calculate delta between frequency bins in rfft.
Definition: acc_algorithm.c:532
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.
Definition: acc_algorithm.c:1071
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.
Definition: acc_algorithm.c:386
acc_algorithm_roll_and_push_f32_matrix
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.
Definition: acc_algorithm.c:133
acc_algorithm_rfft
void acc_algorithm_rfft(const float *data, uint16_t data_length, uint16_t length_shift, float complex *output, uint16_t stride)
1D Fast Fourier Transform for real input
Definition: acc_algorithm.c:463
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.
Definition: acc_algorithm.c:632
acc_definitions_common.h
acc_algorithm_cdiv
float complex acc_algorithm_cdiv(float complex num, float complex denom)
Divide complex number num / denum.
Definition: acc_algorithm.c:592
acc_config.h
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.
Definition: acc_algorithm.c:306
acc_algorithm_calculate_cfar
float acc_algorithm_calculate_cfar(const float *data, uint16_t data_length, uint16_t middle_idx, uint16_t cfar_win_length, uint16_t cfar_guard_length, float cfar_sensitivity, uint16_t idx)
Calculate CFAR threshold.
Definition: acc_algorithm.c:844
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.
Definition: acc_algorithm.c:375
acc_algorithm_roll_and_push_f32_complex_matrix
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.
Definition: acc_algorithm.c:168
acc_algorithm_hamming
void acc_algorithm_hamming(uint16_t n, float *window)
Calculate hamming window for a specified number of points.
Definition: acc_algorithm.c:606
acc_algorithm_apply_filter_complex
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.
Definition: acc_algorithm.c:415
acc_definitions_a121.h
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.
Definition: acc_algorithm.c:967