1 /*
2  * Copyright 2024 NXP
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 
9 /* test vector sum on int16_t elements */
10 void test_vec_sum_int16_op(void);
11 /**
12  * @brief Vector Sum - makes pair wise saturated summation of vectors
13  *
14  * @param[in]		*input1 - points to the first input vector
15  * @param[in]		*input2 - points to the second input vector
16  * @param[out]		*output - points to the output vector
17  * @param[in]		length - number of samples in each vector
18  *
19  * @return none
20  */
21 void vec_sum_int16(const int16_t *input1, const int16_t *input2,
22 		   int16_t *output, uint32_t length);
23 
24 /* test sum of the squares of the int16_t vector elements */
25 void test_power_int16_op(void);
26 /**
27  * @brief Power of a Vector - makes sum of the squares of the elements of
28  *			      an int16_t vector
29  *
30  * @param[in]		*input - points to the input vector
31  * @param[in]		length - size of the input vector
32  * @param[in]		rsh - right shift of result
33  * @param[out]		*output - sum of the squares value
34  *
35  * @return none
36  *
37  * @details
38  * For NatureDSP, rsh is in range 0...31 and output may scaled down with
39  * saturation by rsh bits.
40  *
41  * For CMSIS-DSP, intermediate multiplication yields a 2.30 format,
42  * and this result is added without saturation to a 64-bit accumulator
43  * in 34.30 format.
44  *
45  * Therefore, for some cases, rsh is not used, it can be ignored.
46  */
47 void vec_power_int16(const int16_t *input, int64_t *output, int rsh, uint32_t length);
48 
49 /* test sum of the squares of the int32_t vector elements */
50 void test_power_int32_op(void);
51 /**
52  * @brief Power of a Vector - makes sum of the squares of the elements of
53  *			      an int32_t vector
54  *
55  * @param[in]		*input - points to the input vector
56  * @param[in]		length - size of the input vector
57  * @param[in]		rsh - right shift of result
58  * @param[out]		*output - sum of the squares value
59  *
60  * @return none
61  *
62  * @details
63  * For NatureDSP, rsh is in range 31...62 and output may scaled down with
64  * saturation by rsh bits.
65  *
66  * For CMSIS-DSP, intermediate multiplication yields a 2.62 format,
67  * and this result is truncated to 2.48 format by discarding the lower 14 bits.
68  * The 2.48 result is then added without saturation to a 64-bit accumulator
69  * in 16.48 format.
70  *
71  * Therefore, for some cases, rsh is not used, it can be ignored.
72  */
73 void vec_power_int32(const int32_t *input, int64_t *output, int rsh, uint32_t length);
74 
75 /* test Fast Fourier Transform (FFT) */
76 void test_fft_op(void);
77 /**
78  * @brief Fast Fourier Transform on Real Data - make FFT on real data
79  *
80  * @param[in]		*input - points to the input buffer
81  * @param[in]		length - length of the FFT
82  * @param[out]		*output - points to the output buffer
83  *
84  * @return none
85  */
86 void fft_real32(int32_t *input, int32_t *output, int length);
87 
88 /* test Bi-quad Real Block Infinite Impulse Response (IIR) Filter */
89 void test_iir_op(void);
90 /**
91  * @brief Bi-quad Real Block IIR - makes a real IIR filter
92  *				   (cascaded IIR direct form I using
93  *				   5 coefficients per bi-quad + gain term)
94  *
95  * @param[in]		M - number of bi-quad sections
96  * @param[in]		*coef_sos - points to the filter coefficients
97  * @param[in]		*coef_g - points to the scale factor for each section
98  * @param[in]		*input - points to the block of input data
99  * @param[in]		blockSize - number of samples to process
100  * @param[out]		*output - points to the block of output data
101  *
102  * @return none
103  */
104 void real_block_iir_32(int M, const int32_t *coef_sos, const int16_t *coef_g,
105 		       const int32_t *input, int32_t *output, int block_size);
106 
107 /* test Least Mean Square (LMS) Filter for Real Data */
108 void test_fir_blms_op(void);
109 /**
110  * @brief Blockwise Adaptive LMS Algorithm for Real Data - performs filtering of
111  *				reference samples 'ref', computation of
112  *				error 'err' over a block of
113  *				input samples 'input'
114  *
115  * @param[in]		*coef - points to coefficient buffer
116  * @param[in]		*input -points to the block of input data
117  * @param[in]		*ref - points to the block of reference data
118  * @param[in]		mu - step size that controls filter coefficient updates
119  * @param[in]		blockSize - number of samples to process
120  * @param[in]		M - number of filter coefficients
121  * @param[out]		*output - points to the block of output data
122  * @param[out]		*err - points to the block of error data
123  *
124  * @return	none
125  */
126 void lms_iir_32(int32_t *err, int32_t *coef, int32_t *input, int32_t *ref,
127 		int32_t mu, int block_size, int M);
128