Exportable version of WizziLab's modem driver.
include/kal_math.h@60:08efaaca0e83, 2021-02-19 (annotated)
- Committer:
- Jeej
- Date:
- Fri Feb 19 10:59:42 2021 +0000
- Revision:
- 60:08efaaca0e83
- Parent:
- 56:67e3d9608403
Fixed responses
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Jeej | 31:517fc900afba | 1 | /// @copyright |
Jeej | 31:517fc900afba | 2 | /// ========================================================================={{{ |
Jeej | 31:517fc900afba | 3 | /// Copyright (c) 2013-2014 WizziLab / |
Jeej | 31:517fc900afba | 4 | /// All rights reserved / |
Jeej | 31:517fc900afba | 5 | /// / |
Jeej | 31:517fc900afba | 6 | /// IMPORTANT: This Software may not be modified, copied or distributed unless / |
Jeej | 31:517fc900afba | 7 | /// embedded on a WizziLab product. Other than for the foregoing purpose, this / |
Jeej | 31:517fc900afba | 8 | /// Software and/or its documentation may not be used, reproduced, copied, / |
Jeej | 31:517fc900afba | 9 | /// prepared derivative works of, modified, performed, distributed, displayed / |
Jeej | 31:517fc900afba | 10 | /// or sold for any purpose. For the sole purpose of embedding this Software / |
Jeej | 31:517fc900afba | 11 | /// on a WizziLab product, copy, modification and distribution of this / |
Jeej | 31:517fc900afba | 12 | /// Software is granted provided that the following conditions are respected: / |
Jeej | 31:517fc900afba | 13 | /// / |
Jeej | 31:517fc900afba | 14 | /// * Redistributions of source code must retain the above copyright notice, / |
Jeej | 31:517fc900afba | 15 | /// this list of conditions and the following disclaimer / |
Jeej | 31:517fc900afba | 16 | /// / |
Jeej | 31:517fc900afba | 17 | /// * Redistributions in binary form must reproduce the above copyright / |
Jeej | 31:517fc900afba | 18 | /// notice, this list of conditions and the following disclaimer in the / |
Jeej | 31:517fc900afba | 19 | /// documentation and/or other materials provided with the distribution. / |
Jeej | 31:517fc900afba | 20 | /// / |
Jeej | 31:517fc900afba | 21 | /// * The name of WizziLab can not be used to endorse or promote products / |
Jeej | 31:517fc900afba | 22 | /// derived from this software without specific prior written permission. / |
Jeej | 31:517fc900afba | 23 | /// / |
Jeej | 31:517fc900afba | 24 | /// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS / |
Jeej | 31:517fc900afba | 25 | /// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED / |
Jeej | 31:517fc900afba | 26 | /// TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR / |
Jeej | 31:517fc900afba | 27 | /// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR / |
Jeej | 31:517fc900afba | 28 | /// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, / |
Jeej | 31:517fc900afba | 29 | /// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, / |
Jeej | 31:517fc900afba | 30 | /// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, / |
Jeej | 31:517fc900afba | 31 | /// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY / |
Jeej | 31:517fc900afba | 32 | /// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING / |
Jeej | 31:517fc900afba | 33 | /// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS / |
Jeej | 31:517fc900afba | 34 | /// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. / |
Jeej | 31:517fc900afba | 35 | /// WIZZILAB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, / |
Jeej | 31:517fc900afba | 36 | /// ENHANCEMENTS OR MODIFICATIONS. / |
Jeej | 31:517fc900afba | 37 | /// / |
Jeej | 31:517fc900afba | 38 | /// Should you have any questions regarding your right to use this Software, / |
Jeej | 31:517fc900afba | 39 | /// contact WizziLab at www.wizzilab.com. / |
Jeej | 31:517fc900afba | 40 | /// / |
Jeej | 31:517fc900afba | 41 | /// =========================================================================}}} |
Jeej | 31:517fc900afba | 42 | /// @endcopyright |
Jeej | 31:517fc900afba | 43 | |
Jeej | 31:517fc900afba | 44 | #ifndef __KAL_MATH_H__ |
Jeej | 31:517fc900afba | 45 | #define __KAL_MATH_H__ |
Jeej | 31:517fc900afba | 46 | |
Jeej | 31:517fc900afba | 47 | #include "hal_types.h" |
Jeej | 31:517fc900afba | 48 | |
Jeej | 31:517fc900afba | 49 | // ============================================================================= |
Jeej | 31:517fc900afba | 50 | // Compare operators |
Jeej | 31:517fc900afba | 51 | // ============================================================================= |
Jeej | 31:517fc900afba | 52 | |
Jeej | 31:517fc900afba | 53 | #define KAL_MAX(a,b) (((a) > (b)) ? (a) : (b)) |
Jeej | 31:517fc900afba | 54 | #define KAL_MIN(a,b) (((a) < (b)) ? (a) : (b)) |
Jeej | 31:517fc900afba | 55 | |
Jeej | 56:67e3d9608403 | 56 | //#define KAL_ABS(a) (((a) > 0) ? (a) : (-(a))) |
Jeej | 31:517fc900afba | 57 | #define KAL_ABS16_FAST(a) ((a) ^ ((a) >> 15)) |
Jeej | 31:517fc900afba | 58 | #define KAL_ABS32_FAST(a) ((a) ^ ((a) >> 31)) |
Jeej | 31:517fc900afba | 59 | |
Jeej | 31:517fc900afba | 60 | #define KAL_SAT_RANGE(a,min,max) (((a) < (min)) ? (min) : ((a) > (max)) ? (max) : (a)) |
Jeej | 31:517fc900afba | 61 | #define KAL_SAT_S16(a) (((a) < MIN_S16) ? MIN_S16 : ((a) > MAX_S16) ? MAX_S16 : (s16)(a)) |
Jeej | 31:517fc900afba | 62 | #define KAL_SAT_U16(a) (((a) > MAX_U16) ? MAX_U16 : (u16)(a)) |
Jeej | 31:517fc900afba | 63 | #define KAL_SAT_S8(a) (((a) < MIN_S8) ? MIN_S8 : ((a) > MAX_S8) ? MAX_S8 : (s8)(a)) |
Jeej | 31:517fc900afba | 64 | #define KAL_SAT_U8(a) (((a) > MAX_U8) ? MAX_U8 : (u8)(a)) |
Jeej | 31:517fc900afba | 65 | |
Jeej | 31:517fc900afba | 66 | #define KAL_COMP16_FAST(a,b) (((b) - (a)) >> 15) |
Jeej | 31:517fc900afba | 67 | |
Jeej | 31:517fc900afba | 68 | // ============================================================================= |
Jeej | 31:517fc900afba | 69 | // Bit manipulation operators |
Jeej | 31:517fc900afba | 70 | // ============================================================================= |
Jeej | 31:517fc900afba | 71 | |
Jeej | 31:517fc900afba | 72 | #define KAL_BIT_CLR(d, j) (d)[(j)/8] &= (~(1 << ((j) & 7))) |
Jeej | 31:517fc900afba | 73 | #define KAL_BIT_SET(d, j) (d)[(j)/8] |= (((1) << ((j) & 7))) |
Jeej | 31:517fc900afba | 74 | #define KAL_BIT_MOV(s, i, d, j) (d)[(j)/8] |= ((((s)[(i)/8]>>((i)&7))&1)<<((j)&7)) |
Jeej | 31:517fc900afba | 75 | #define KAL_BIT_IS_ONE(s, i) ((s)[(i)/8] & (1 << ((i) & 7))) |
Jeej | 31:517fc900afba | 76 | #define KAL_BIT_GET(s, i) ((s)[(i)/8] >> ((i) & 7) & 1) |
Jeej | 31:517fc900afba | 77 | |
Jeej | 31:517fc900afba | 78 | #define KAL_2BIT_SH(i) (2 * ((i) & 3)) |
Jeej | 31:517fc900afba | 79 | #define KAL_2BIT_GET(d, i) (((d)[(i)/4] >> KAL_2BIT_SH(i)) & 3) |
Jeej | 31:517fc900afba | 80 | #define KAL_2BIT_CLR(d, i) ((d)[(i)/4] &=~ (3 << KAL_2BIT_SH(i))) |
Jeej | 31:517fc900afba | 81 | #define KAL_2BIT_SET(d, i, c) ((d)[(i)/4] |= ((c) << KAL_2BIT_SH(i))) |
Jeej | 31:517fc900afba | 82 | #define KAL_2BIT_MOV(s, i, d, j) KAL_2BIT_SET(d, j, KAL_2BIT_GET(s, i)) |
Jeej | 31:517fc900afba | 83 | |
Jeej | 31:517fc900afba | 84 | // ============================================================================= |
Jeej | 31:517fc900afba | 85 | // Simple arithmetic operators |
Jeej | 31:517fc900afba | 86 | // ============================================================================= |
Jeej | 31:517fc900afba | 87 | |
Jeej | 31:517fc900afba | 88 | #define KAL_MUL(x,y) ((x)*(y)) |
Jeej | 31:517fc900afba | 89 | #define KAL_MLF(x,y,frac) (((x)*(y)) >> (frac)) |
Jeej | 31:517fc900afba | 90 | #define KAL_SHIFT_LEFT_SIGNED(a,s) (((s) > 0) ? ((a) << (s)) : ((a) >> (-(s)))) |
Jeej | 31:517fc900afba | 91 | #define KAL_SQR(x) KAL_MUL(x,x) |
Jeej | 31:517fc900afba | 92 | #define KAL_DIV_INT(n,d) (((n) + ((d)/2))/(d)) |
Jeej | 31:517fc900afba | 93 | #define KAL_DIV_CEILING(n,d) (((n) + (d) - 1)/(d)) |
Jeej | 31:517fc900afba | 94 | #define KAL_DIV_FLOOR(n,d) (((n) )/(d)) |
Jeej | 31:517fc900afba | 95 | |
Jeej | 31:517fc900afba | 96 | // ============================================================================= |
Jeej | 31:517fc900afba | 97 | // Complex operators |
Jeej | 31:517fc900afba | 98 | // ============================================================================= |
Jeej | 31:517fc900afba | 99 | |
Jeej | 31:517fc900afba | 100 | #define KAL_COMPLEX_ADD(a,b,out) { (out).I = (a).I + (b).I; (out).Q = (a).Q + (b).Q; } |
Jeej | 31:517fc900afba | 101 | #define KAL_COMPLEX_SUB(a,b,out) { (out).I = (a).I - (b).I; (out).Q = (a).Q - (b).Q; } |
Jeej | 31:517fc900afba | 102 | |
Jeej | 31:517fc900afba | 103 | #define KAL_COMPLEX_MUL(a,b,out) { (out).I = KAL_MUL((a).I,(b).I) - KAL_MUL((a).Q,(b).Q); \ |
Jeej | 31:517fc900afba | 104 | (out).Q = KAL_MUL((a).I,(b).Q) + KAL_MUL((a).Q,(b).I); } |
Jeej | 31:517fc900afba | 105 | |
Jeej | 31:517fc900afba | 106 | #define KAL_COMPLEX_MLF(a,b,out,frac) { (out).I = KAL_MLF((a).I,(b).I,(frac)) - KAL_MLF((a).Q,(b).Q,(frac)); \ |
Jeej | 31:517fc900afba | 107 | (out).Q = KAL_MLF((a).I,(b).Q,(frac)) + KAL_MLF((a).Q,(b).I,(frac)); } |
Jeej | 31:517fc900afba | 108 | |
Jeej | 31:517fc900afba | 109 | #define KAL_COMPLEX_NORM(a) (KAL_MUL((a).I,(a).I) + KAL_MUL((a).Q,(a).Q)) |
Jeej | 56:67e3d9608403 | 110 | #define KAL_COMPLEX_MOD(a) (kal_sqrt32((u32)KAL_COMPLEX_NORM(a))) |
Jeej | 31:517fc900afba | 111 | |
Jeej | 56:67e3d9608403 | 112 | #define KAL_COMPLEX_DIST(a,b,res) { \ |
Jeej | 56:67e3d9608403 | 113 | complex_t diff; \ |
Jeej | 56:67e3d9608403 | 114 | KAL_COMPLEX_SUB((a),(b), diff); \ |
Jeej | 56:67e3d9608403 | 115 | (res) = KAL_COMPLEX_MOD(diff); \ |
Jeej | 56:67e3d9608403 | 116 | } |
Jeej | 56:67e3d9608403 | 117 | |
Jeej | 56:67e3d9608403 | 118 | //====================================================================== |
Jeej | 56:67e3d9608403 | 119 | // Circular d-dimensional buffer structure |
Jeej | 56:67e3d9608403 | 120 | //====================================================================== |
Jeej | 56:67e3d9608403 | 121 | typedef struct |
Jeej | 56:67e3d9608403 | 122 | { |
Jeej | 56:67e3d9608403 | 123 | // Number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 124 | u8 dim; |
Jeej | 56:67e3d9608403 | 125 | // Buffer length (number of vectors) |
Jeej | 56:67e3d9608403 | 126 | u8 len; |
Jeej | 56:67e3d9608403 | 127 | // Current vector position in the buffer |
Jeej | 56:67e3d9608403 | 128 | u8 curr; |
Jeej | 56:67e3d9608403 | 129 | // Pointer to the start of the buffer |
Jeej | 56:67e3d9608403 | 130 | s16 buf[1]; |
Jeej | 56:67e3d9608403 | 131 | |
Jeej | 56:67e3d9608403 | 132 | } kal_circ_buf_t; |
Jeej | 56:67e3d9608403 | 133 | |
Jeej | 56:67e3d9608403 | 134 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 135 | // kal_abs_s32 |
Jeej | 56:67e3d9608403 | 136 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 137 | /// @brief Absolute function |
Jeej | 56:67e3d9608403 | 138 | /// @param x s32 input |
Jeej | 56:67e3d9608403 | 139 | /// @retval u32 output |
Jeej | 56:67e3d9608403 | 140 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 141 | INLINE _public u32 kal_abs_s32(s32 x) |
Jeej | 56:67e3d9608403 | 142 | { |
Jeej | 56:67e3d9608403 | 143 | return (u32)((x > 0)? x : -x); |
Jeej | 56:67e3d9608403 | 144 | } |
Jeej | 56:67e3d9608403 | 145 | |
Jeej | 56:67e3d9608403 | 146 | INLINE _public u16 kal_abs_s16(s16 x) |
Jeej | 56:67e3d9608403 | 147 | { |
Jeej | 56:67e3d9608403 | 148 | return (u16)((x > 0)? x : -x); |
Jeej | 56:67e3d9608403 | 149 | } |
Jeej | 56:67e3d9608403 | 150 | |
Jeej | 56:67e3d9608403 | 151 | INLINE _public u8 kal_abs_s8(s8 x) |
Jeej | 56:67e3d9608403 | 152 | { |
Jeej | 56:67e3d9608403 | 153 | return (u8)((x > 0)? x : -x); |
Jeej | 56:67e3d9608403 | 154 | } |
Jeej | 56:67e3d9608403 | 155 | |
Jeej | 56:67e3d9608403 | 156 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 157 | // kal_sqrt |
Jeej | 56:67e3d9608403 | 158 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 159 | /// @brief Fixed point square root |
Jeej | 56:67e3d9608403 | 160 | /// @param x u16 input fixed point value |
Jeej | 56:67e3d9608403 | 161 | /// @param format u8 fixed point format (shift) |
Jeej | 56:67e3d9608403 | 162 | /// @retval u16 square root of the input in the given format |
Jeej | 56:67e3d9608403 | 163 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 164 | _public u16 kal_sqrt(u16 x, u8 format); |
Jeej | 56:67e3d9608403 | 165 | |
Jeej | 56:67e3d9608403 | 166 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 167 | // kal_sqrt32 |
Jeej | 56:67e3d9608403 | 168 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 169 | /// @brief Integer square root |
Jeej | 56:67e3d9608403 | 170 | /// @param x u32 input fixed point value |
Jeej | 56:67e3d9608403 | 171 | /// @retval u16 square root of the input |
Jeej | 56:67e3d9608403 | 172 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 173 | _public u16 kal_sqrt32(u32 x); |
Jeej | 56:67e3d9608403 | 174 | |
Jeej | 56:67e3d9608403 | 175 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 176 | // kal_div |
Jeej | 56:67e3d9608403 | 177 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 178 | /// @brief Fixed point division of two s16 values |
Jeej | 56:67e3d9608403 | 179 | /// @param nom s16 Numerator |
Jeej | 56:67e3d9608403 | 180 | /// @param denom s16 Denominator |
Jeej | 56:67e3d9608403 | 181 | /// @param format u8 fixed point format (shift) |
Jeej | 56:67e3d9608403 | 182 | /// @retval s16 division result in the given format |
Jeej | 56:67e3d9608403 | 183 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 184 | _public s16 kal_div(s16 num, s16 denom, u8 format); |
Jeej | 56:67e3d9608403 | 185 | |
Jeej | 56:67e3d9608403 | 186 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 187 | // kal_div_u32 |
Jeej | 56:67e3d9608403 | 188 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 189 | /// @brief Fixed point division of two u32 values |
Jeej | 56:67e3d9608403 | 190 | /// @param n u32 Numerator |
Jeej | 56:67e3d9608403 | 191 | /// @param d u32 Denominator |
Jeej | 56:67e3d9608403 | 192 | /// @param format u8 fixed point format (shift) |
Jeej | 56:67e3d9608403 | 193 | /// @retval u32 division result in the given format |
Jeej | 56:67e3d9608403 | 194 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 195 | _public u32 kal_div_u32(u32 n, u32 d, u8 format); |
Jeej | 56:67e3d9608403 | 196 | |
Jeej | 56:67e3d9608403 | 197 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 198 | // kal_log2 |
Jeej | 56:67e3d9608403 | 199 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 200 | /// @brief Fast log2 computation |
Jeej | 56:67e3d9608403 | 201 | /// @param in u32 operand |
Jeej | 56:67e3d9608403 | 202 | /// @retval u8 log2 of the operand |
Jeej | 56:67e3d9608403 | 203 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 204 | _public u8 kal_log2(u32 in); |
Jeej | 56:67e3d9608403 | 205 | |
Jeej | 56:67e3d9608403 | 206 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 207 | // kal_complex_arg |
Jeej | 56:67e3d9608403 | 208 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 209 | /// @brief Compute the argument of a complex number |
Jeej | 56:67e3d9608403 | 210 | /// @param in u32 operand |
Jeej | 56:67e3d9608403 | 211 | /// @retval u16 angle in degrees [0, 360[ |
Jeej | 56:67e3d9608403 | 212 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 213 | _public u16 kal_complex_arg(complex_t in); |
Jeej | 56:67e3d9608403 | 214 | |
Jeej | 56:67e3d9608403 | 215 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 216 | // kal_sin |
Jeej | 56:67e3d9608403 | 217 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 218 | /// @brief sin(a) in Q15 |
Jeej | 56:67e3d9608403 | 219 | /// @param a u16 angle in degrees [0, 360[ |
Jeej | 56:67e3d9608403 | 220 | /// @retval s16 sin(a) in Q15 |
Jeej | 56:67e3d9608403 | 221 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 222 | _public u16 kal_sin(u16 a); |
Jeej | 56:67e3d9608403 | 223 | |
Jeej | 56:67e3d9608403 | 224 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 225 | // kal_cos |
Jeej | 56:67e3d9608403 | 226 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 227 | /// @brief cos(a) in Q15 |
Jeej | 56:67e3d9608403 | 228 | /// @param a u16 angle in degrees [0, 360[ |
Jeej | 56:67e3d9608403 | 229 | /// @retval s16 cos(a) in Q15 |
Jeej | 56:67e3d9608403 | 230 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 231 | #define kal_cos(a) kal_sin(((450-(a)) % 360)) |
Jeej | 56:67e3d9608403 | 232 | |
Jeej | 56:67e3d9608403 | 233 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 234 | // kal_add |
Jeej | 56:67e3d9608403 | 235 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 236 | /// @brief Add B to A and store in A |
Jeej | 56:67e3d9608403 | 237 | /// @param a s16* pointer to the d-dimensional vector A |
Jeej | 56:67e3d9608403 | 238 | /// @param b s16* pointer to the d-dimensional vector B |
Jeej | 56:67e3d9608403 | 239 | /// @param d u8 number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 240 | /// @retval void |
Jeej | 56:67e3d9608403 | 241 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 242 | _public void kal_add(s16* a, s16* b, u8 d); |
Jeej | 56:67e3d9608403 | 243 | |
Jeej | 56:67e3d9608403 | 244 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 245 | // kal_sub |
Jeej | 56:67e3d9608403 | 246 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 247 | /// @brief Subtract B from A and store in A |
Jeej | 56:67e3d9608403 | 248 | /// @param a s16* pointer to the d-dimensional vector A |
Jeej | 56:67e3d9608403 | 249 | /// @param b s16* pointer to the d-dimensional vector B |
Jeej | 56:67e3d9608403 | 250 | /// @param d u8 number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 251 | /// @retval void |
Jeej | 56:67e3d9608403 | 252 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 253 | _public void kal_sub(s16* a, s16* b, u8 d); |
Jeej | 56:67e3d9608403 | 254 | |
Jeej | 56:67e3d9608403 | 255 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 256 | // kal_mean |
Jeej | 56:67e3d9608403 | 257 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 258 | /// @brief Get mean of data in a d-dimensional buffer |
Jeej | 56:67e3d9608403 | 259 | /// @param in s16* input circular buffer |
Jeej | 56:67e3d9608403 | 260 | /// @param out s16* pointer to the d-dimensional result |
Jeej | 56:67e3d9608403 | 261 | /// @param len u8 length of the buffer |
Jeej | 56:67e3d9608403 | 262 | /// @param d u8 number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 263 | /// @retval void |
Jeej | 56:67e3d9608403 | 264 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 265 | _public void kal_mean(s16* in, s16* out, u8 len, u8 d); |
Jeej | 56:67e3d9608403 | 266 | |
Jeej | 56:67e3d9608403 | 267 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 268 | // kal_var |
Jeej | 56:67e3d9608403 | 269 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 270 | /// @brief Get the combined variance of data in a d-dimensional buffer |
Jeej | 56:67e3d9608403 | 271 | /// @param in s16* input circular buffer |
Jeej | 56:67e3d9608403 | 272 | /// @param mean s16* pointer to the d-dimensional mean |
Jeej | 56:67e3d9608403 | 273 | /// @param len u8 length of the buffer |
Jeej | 56:67e3d9608403 | 274 | /// @param d u8 number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 275 | /// @retval u32 variance |
Jeej | 56:67e3d9608403 | 276 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 277 | _public u32 kal_var(s16* in, s16* mean, u8 len, u8 d); |
Jeej | 56:67e3d9608403 | 278 | |
Jeej | 56:67e3d9608403 | 279 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 280 | // kal_dev |
Jeej | 56:67e3d9608403 | 281 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 282 | /// @brief Get the deviation per axis in a d-dimensional buffer |
Jeej | 56:67e3d9608403 | 283 | /// @param buf s16* input circular buffer |
Jeej | 56:67e3d9608403 | 284 | /// @param inout s16* [in] pointer to the d-dimensional mean |
Jeej | 56:67e3d9608403 | 285 | /// [out] pointer to the d-dimensional dev |
Jeej | 56:67e3d9608403 | 286 | /// @param len u8 length of the buffer |
Jeej | 56:67e3d9608403 | 287 | /// @param d u8 number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 288 | /// @retval void |
Jeej | 56:67e3d9608403 | 289 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 290 | _public void kal_dev(s16* buf, s16* inout, u8 len, u8 d); |
Jeej | 56:67e3d9608403 | 291 | |
Jeej | 56:67e3d9608403 | 292 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 293 | // kal_norm |
Jeej | 56:67e3d9608403 | 294 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 295 | /// @brief Get norm of an d-dimensional vector |
Jeej | 56:67e3d9608403 | 296 | /// @param in s16* d-dimensional vector |
Jeej | 56:67e3d9608403 | 297 | /// @param d u8 number of dimensions of the vector |
Jeej | 56:67e3d9608403 | 298 | /// @retval u32 norm of the vector |
Jeej | 56:67e3d9608403 | 299 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 300 | _public u32 kal_norm(s16* in, u8 d); |
Jeej | 56:67e3d9608403 | 301 | |
Jeej | 56:67e3d9608403 | 302 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 303 | // kal_dist |
Jeej | 56:67e3d9608403 | 304 | // ----------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 305 | /// @brief Get distance between two d-dimensional vectors |
Jeej | 56:67e3d9608403 | 306 | /// @param a s16* first d-dimensional vector |
Jeej | 56:67e3d9608403 | 307 | /// @param b s16* second d-dimensional vector |
Jeej | 56:67e3d9608403 | 308 | /// @param d u8 number of dimensions of the vector |
Jeej | 56:67e3d9608403 | 309 | /// @retval u32 distance (norm of the difference) |
Jeej | 56:67e3d9608403 | 310 | // ======================================================================= |
Jeej | 56:67e3d9608403 | 311 | _public u32 kal_dist(s16* a, s16* b, u8 d); |
Jeej | 56:67e3d9608403 | 312 | |
Jeej | 56:67e3d9608403 | 313 | //====================================================================== |
Jeej | 56:67e3d9608403 | 314 | // kal_circ_buf_alloc |
Jeej | 56:67e3d9608403 | 315 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 316 | /// @brief Allocate and init circular buffer |
Jeej | 56:67e3d9608403 | 317 | /// @param len u8 Number of d-dimensional vectors in the buffer |
Jeej | 56:67e3d9608403 | 318 | /// @param dim u8 Number of dimensions of the buffer |
Jeej | 56:67e3d9608403 | 319 | /// @return kal_circ_buf_t* Pointer to the circular buffer structure |
Jeej | 56:67e3d9608403 | 320 | //====================================================================== |
Jeej | 56:67e3d9608403 | 321 | _public kal_circ_buf_t* kal_circ_buf_alloc(u8 len, u8 dim); |
Jeej | 56:67e3d9608403 | 322 | |
Jeej | 56:67e3d9608403 | 323 | //====================================================================== |
Jeej | 56:67e3d9608403 | 324 | // kal_circ_buf_free |
Jeej | 56:67e3d9608403 | 325 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 326 | /// @brief Free circular buffer |
Jeej | 56:67e3d9608403 | 327 | /// @param circ kal_circ_buf_t* Pointer to the circular buffer structure |
Jeej | 56:67e3d9608403 | 328 | /// @return void |
Jeej | 56:67e3d9608403 | 329 | //====================================================================== |
Jeej | 56:67e3d9608403 | 330 | _public void kal_circ_buf_free(kal_circ_buf_t* circ); |
Jeej | 56:67e3d9608403 | 331 | |
Jeej | 56:67e3d9608403 | 332 | //====================================================================== |
Jeej | 56:67e3d9608403 | 333 | // kal_circ_buf_init |
Jeej | 56:67e3d9608403 | 334 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 335 | /// @brief Init the buffer with the same element |
Jeej | 56:67e3d9608403 | 336 | /// @param v s16* d-dimensional vector to write |
Jeej | 56:67e3d9608403 | 337 | /// @param circ kal_circ_buf_t* Pointer to the circular buffer structure |
Jeej | 56:67e3d9608403 | 338 | /// @return void |
Jeej | 56:67e3d9608403 | 339 | //====================================================================== |
Jeej | 56:67e3d9608403 | 340 | _public void kal_circ_buf_init(s16* v, kal_circ_buf_t* circ); |
Jeej | 56:67e3d9608403 | 341 | |
Jeej | 56:67e3d9608403 | 342 | //====================================================================== |
Jeej | 56:67e3d9608403 | 343 | // kal_circ_buf_add |
Jeej | 56:67e3d9608403 | 344 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 345 | /// @brief Add new element of type s16 in buffer, erase oldest element |
Jeej | 56:67e3d9608403 | 346 | /// @param v s16* d-dimensional vector to write |
Jeej | 56:67e3d9608403 | 347 | /// @param circ kal_circ_buf_t* Pointer to the circular buffer structure |
Jeej | 56:67e3d9608403 | 348 | /// @return void |
Jeej | 56:67e3d9608403 | 349 | //====================================================================== |
Jeej | 56:67e3d9608403 | 350 | _public void kal_circ_buf_add(s16* v, kal_circ_buf_t* circ); |
Jeej | 56:67e3d9608403 | 351 | |
Jeej | 56:67e3d9608403 | 352 | //====================================================================== |
Jeej | 56:67e3d9608403 | 353 | // kal_circ_buf_stats |
Jeej | 56:67e3d9608403 | 354 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 355 | /// @brief Mean and variance of the circular buffer |
Jeej | 56:67e3d9608403 | 356 | /// @param v s16* d-dimensional mean vector (output) |
Jeej | 56:67e3d9608403 | 357 | /// @param circ kal_circ_buf_t* Pointer to the circular buffer structure |
Jeej | 56:67e3d9608403 | 358 | /// @retval u32 variance |
Jeej | 56:67e3d9608403 | 359 | //====================================================================== |
Jeej | 56:67e3d9608403 | 360 | _public u32 kal_circ_buf_stats(s16* mean, kal_circ_buf_t* circ); |
Jeej | 56:67e3d9608403 | 361 | |
Jeej | 56:67e3d9608403 | 362 | //====================================================================== |
Jeej | 56:67e3d9608403 | 363 | // kal_lp_filter |
Jeej | 56:67e3d9608403 | 364 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 365 | /// @brief Low Pass Filter with forget factor |
Jeej | 56:67e3d9608403 | 366 | /// @param lp s16* Pointer to the LP sample |
Jeej | 56:67e3d9608403 | 367 | /// @param s s16* Pointer to the new sample |
Jeej | 56:67e3d9608403 | 368 | /// @param dim u8 Number of dimensions of the sample |
Jeej | 56:67e3d9608403 | 369 | /// @param ff u8 Forget factor |
Jeej | 56:67e3d9608403 | 370 | /// @return void |
Jeej | 56:67e3d9608403 | 371 | //====================================================================== |
Jeej | 56:67e3d9608403 | 372 | _public void kal_lp_filter(s16* lpf, s16* s, u8 dim, u8 ff); |
Jeej | 56:67e3d9608403 | 373 | |
Jeej | 56:67e3d9608403 | 374 | //====================================================================== |
Jeej | 56:67e3d9608403 | 375 | // kal_xor |
Jeej | 56:67e3d9608403 | 376 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 377 | /// @brief xor two vectors |
Jeej | 56:67e3d9608403 | 378 | /// @param buf u8* inout stream |
Jeej | 56:67e3d9608403 | 379 | /// @param iv u8* in stream to XOR |
Jeej | 56:67e3d9608403 | 380 | /// @retval void |
Jeej | 56:67e3d9608403 | 381 | //====================================================================== |
Jeej | 56:67e3d9608403 | 382 | _public void kal_xor(u8* buf, u8* iv, u16 len); |
Jeej | 56:67e3d9608403 | 383 | |
Jeej | 56:67e3d9608403 | 384 | //====================================================================== |
Jeej | 56:67e3d9608403 | 385 | // kal_sort |
Jeej | 56:67e3d9608403 | 386 | //---------------------------------------------------------------------- |
Jeej | 56:67e3d9608403 | 387 | /// @brief Sort u16 buffer from smaller to bigger error |
Jeej | 56:67e3d9608403 | 388 | /// @param inout u16* inout buffer |
Jeej | 56:67e3d9608403 | 389 | /// @param ref u16 comparison reference |
Jeej | 56:67e3d9608403 | 390 | /// @param len u8 buffer length |
Jeej | 56:67e3d9608403 | 391 | /// @return void |
Jeej | 56:67e3d9608403 | 392 | //====================================================================== |
Jeej | 56:67e3d9608403 | 393 | _public void kal_sort(u16* inout, u16 ref, u8 len); |
Jeej | 56:67e3d9608403 | 394 | |
Jeej | 56:67e3d9608403 | 395 | #endif // __KAL_MATH_H__ |