file_path
stringlengths
20
207
content
stringlengths
5
3.85M
size
int64
5
3.85M
lang
stringclasses
9 values
avg_line_length
float64
1.33
100
max_line_length
int64
4
993
alphanum_fraction
float64
0.26
0.93
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/jtest_test.h
#ifndef _JTEST_TEST_H_ #define _JTEST_TEST_H_ /*--------------------------------------------------------------------------------*/ /* Includes */ /*--------------------------------------------------------------------------------*/ #include <stdint.h> #include "jtest_util.h" #include "jtest_test_ret.h" /*--------------------------------------------------------------------------------*/ /* Type Definitions */ /*--------------------------------------------------------------------------------*/ /** * A struct which represents a Test in the JTEST framework. This struct is * used to enable, run, and describe the test it represents. */ typedef struct JTEST_TEST_struct { JTEST_TEST_RET_t ( * test_fn_ptr)(void); /**< Pointer to the test function. */ char * test_fn_str; /**< Name of the test function */ char * fut_str; /**< Name of the function under test. */ /** * Flags that govern how the #JTEST_TEST_t behaves. */ union { struct { unsigned enabled : 1; unsigned unused : 7; } bits; uint8_t byte; /* Access all flags at once. */ } flags; } JTEST_TEST_t; /*--------------------------------------------------------------------------------*/ /* Macros and Defines */ /*--------------------------------------------------------------------------------*/ /** * Assign a test function to the #JTEST_TEST_t struct. */ #define JTEST_TEST_SET_FN(jtest_test_ptr, fn_ptr) \ JTEST_SET_STRUCT_ATTRIBUTE(jtest_test_ptr, test_fn_ptr, fn_ptr) /** * Specify a function under test (FUT) for the #JTEST_TEST_t struct. */ #define JTEST_TEST_SET_FUT(jtest_test_ptr, str) \ JTEST_SET_STRUCT_ATTRIBUTE(jtest_test_ptr, fut_str, str) /* Macros concerning JTEST_TEST_t flags */ /*--------------------------------------------------------------------------------*/ #define JTEST_TEST_FLAG_SET 1 /**< Value of a set #JTEST_TEST_t flag. */ #define JTEST_TEST_FLAG_CLR 0 /**< Value of a cleared #JTEST_TEST_t flag. */ /** * Evaluate to the flag in #JTEST_TEST_t having flag_name. */ #define JTEST_TEST_FLAG(jtest_test_ptr, flag_name) \ ((jtest_test_ptr)->flags.bits.flag_name) /** * Dispatch macro for setting and clearing #JTEST_TEST_t flags. * * @param jtest_test_ptr Pointer to a #JTEST_TEST_t struct. * @param flag_name Name of the flag to set in #JTEST_TEST_t.flags.bits * @param xxx Vaid values: "SET" or "CLR" * * @note This function depends on JTEST_TEST_FLAG_SET and JTEST_TEST_FLAG_CLR. */ #define JTEST_TEST_XXX_FLAG(jtest_test_ptr, flag_name, xxx) \ do \ { \ JTEST_TEST_FLAG(jtest_test_ptr, flag_name) = JTEST_TEST_FLAG_##xxx ; \ } while (0) /** * Specification of #JTEST_TEST_XXX_FLAG to set #JTEST_TEST_t flags. */ #define JTEST_TEST_SET_FLAG(jtest_test_ptr, flag_name) \ JTEST_TEST_XXX_FLAG(jtest_test_ptr, flag_name, SET) /** * Specification of #JTEST_TEST_XXX_FLAG to clear #JTEST_TEST_t flags. */ #define JTEST_TEST_CLR_FLAG(jtest_test_ptr, flag_name) \ JTEST_TEST_XXX_FLAG(jtest_test_ptr, flag_name, CLR) /** * Evaluate to true if the #JTEST_TEST_t is enabled. */ #define JTEST_TEST_IS_ENABLED(jtest_test_ptr) \ (JTEST_TEST_FLAG(jtest_test_ptr, enabled) == JTEST_TEST_FLAG_SET) #endif /* _JTEST_TEST_H_ */
3,606
C
34.712871
84
0.481143
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/jtest_group.h
#ifndef _JTEST_GROUP_H_ #define _JTEST_GROUP_H_ /*--------------------------------------------------------------------------------*/ /* Includes */ /*--------------------------------------------------------------------------------*/ #include "jtest_pf.h" #include "jtest_util.h" /*--------------------------------------------------------------------------------*/ /* Type Definitions */ /*--------------------------------------------------------------------------------*/ /** * A struct which represents a group of #JTEST_TEST_t structs. This struct is * used to run the group of tests, and report on their outcomes. */ typedef struct JTEST_GROUP_struct { void (* group_fn_ptr) (void); /**< Pointer to the test group */ char * name_str; /**< Name of the group */ /* Extend the #JTEST_GROUP_t with Pass/Fail information.*/ JTEST_PF_MEMBERS; } JTEST_GROUP_t; /*--------------------------------------------------------------------------------*/ /* Macros and Defines */ /*--------------------------------------------------------------------------------*/ /** * Set the name of JTEST_GROUP_t. */ #define JTEST_GROUP_SET_NAME(group_ptr, name) \ JTEST_SET_STRUCT_ATTRIBUTE(group_ptr, name_str, name) #define JTEST_GROUP_SET_FN(group_ptr, fn_ptr) \ JTEST_SET_STRUCT_ATTRIBUTE(group_ptr, group_fn_ptr, fn_ptr) /** * Increment the number of tests passed in the JTEST_GROUP_t pointed to by * group_ptr. */ #define JTEST_GROUP_INC_PASSED(group_ptr, amount) \ JTEST_PF_INC_PASSED(group_ptr, amount) /** * Increment the number of tests failed in the JTEST_GROUP_t pointed to by * group_ptr. */ #define JTEST_GROUP_INC_FAILED(group_ptr, amount) \ JTEST_PF_INC_FAILED(group_ptr, amount) /** * Reset the pass/fail information of the #JTEST_GROUP_t pointed to by * group_ptr. */ #define JTEST_GROUP_RESET_PF(group_ptr) \ do \ { \ JTEST_PF_RESET_PASSED(group_ptr); \ JTEST_PF_RESET_FAILED(group_ptr); \ } while (0) #endif /* _JTEST_GROUP_H_ */
2,149
C
31.089552
84
0.46161
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/arr_desc/arr_desc.h
#ifndef _ARR_DESC_H_ #define _ARR_DESC_H_ /*--------------------------------------------------------------------------------*/ /* Includes */ /*--------------------------------------------------------------------------------*/ #include <stdint.h> #include <string.h> /* memset() */ #include "../util/util.h" /* CONCAT() */ /*--------------------------------------------------------------------------------*/ /* Type Definitions */ /*--------------------------------------------------------------------------------*/ /** * Array-descriptor struct. */ typedef struct ARR_DESC_struct { void * data_ptr; /* Pointer to the array contents. */ int32_t element_count; /* Number of current elements. */ int32_t element_size; /* Size of current elements in bytes. */ int32_t underlying_size; /* Size of underlying array in bytes. */ } ARR_DESC_t; /*--------------------------------------------------------------------------------*/ /* Macros and Defines */ /*--------------------------------------------------------------------------------*/ /** * Prefix of the array variable's name when creating an array and an array * descriptor at the same time. */ #define ARR_DESC_ARR_PREFIX ARR_DESC_ARR_ /** * Evaluate to the array variable's name when creating an array and an array * descriptor at the same time. */ #define ARR_DESC_ARR_NAME(name) \ CONCAT(ARR_DESC_ARR_PREFIX, name) /** * Define an #ARR_DESC_t by itself. * * @note The user must supply an array to store the data used by the * #ARR_DESC_t. */ #define ARR_DESC_INTERNAL_DEFINE(name, data_ptr, \ element_count, element_size) \ ARR_DESC_t name = { \ data_ptr, \ element_count, \ element_size, \ element_count * element_size \ } \ /** * Define both an array and an #ARR_DESC_t that describes it. * * @note Use the #CURLY() macro for the content field; it provides the curly * braces necessary for an array initialization. */ #define ARR_DESC_DEFINE(type, name, element_count, content) \ type ARR_DESC_ARR_NAME(name)[element_count] = content; \ ARR_DESC_INTERNAL_DEFINE(name, \ &ARR_DESC_ARR_NAME(name), \ element_count, \ sizeof(type)) /* Note the lacking semicolon */ /** * Create a #ARR_DESC_t which refers to a subset of the data in another. * * The new #ARR_DESC_t shares the same underlying array as the aliased * #ARR_DESC_t, but only describes a subset of the originals values. */ #define ARR_DESC_DEFINE_SUBSET(name, original, element_cnt) \ ARR_DESC_INTERNAL_DEFINE(name, \ &ARR_DESC_ARR_NAME(original), \ element_cnt, \ sizeof(ARR_DESC_ARR_NAME(original)[0]) \ ) /* Note the lacking semicolon */ /** * Creat an #ARR_DESC_t which points to the data in an existing array. * * @param start_idx Offset in array_ptr of first element. * @param element_cnt Number of elements to include in the #ARR_DESC_t. * * @example * * float my_floats[4] = {0.0f, 1.0f, 2.0f, 3.0f}; * * ARR_DESC_DEFINE_USING_ARR(my_arr_desc, my_floats, 1, 3); * * printf("Element 0: %f\n", ARR_DESC_ELT(float, 0, &my_arr_desc)); * printf("Element 1: %f\n", ARR_DESC_ELT(float, 1, &my_arr_desc)); * * Outputs: * * Element 0: 1.000000 * Element 1: 2.000000 * * @warning There are no checks in place to catch invalid start indices; This * is left to the user. */ #define ARR_DESC_DEFINE_USING_ARR(type, name, array_ptr, start_idx, element_cnt) \ ARR_DESC_INTERNAL_DEFINE( \ name, \ (type *) (array_ptr + start_idx), \ element_cnt, \ sizeof(type) \ ) /* Note the lacking semicolon*/ /** * Declare an #ARR_DESC_t object. */ #define ARR_DESC_DECLARE(name) \ extern ARR_DESC_t name /* Note the lacking semicolon */ /** * Evaluate to the number of bytes stored in the #ARR_DESC_t. */ #define ARR_DESC_BYTES(arr_desc_ptr) \ ((arr_desc_ptr)->element_count * (arr_desc_ptr)->element_size) /** * Set the contents of #ARR_DESC_t to value. */ #define ARR_DESC_MEMSET(arr_desc_ptr, value, bytes) \ do \ { \ memset((arr_desc_ptr)->data_ptr, \ value, \ BOUND(0, \ (arr_desc_ptr)->underlying_size, \ bytes) \ ); \ } while (0) /** * Perform a memcpy of 'bytes' bytes from the source #ARR_DESC_t to the * destination #ARR_DESC_t. */ #define ARR_DESC_MEMCPY(arr_desc_dest_ptr, arr_desc_src_ptr, bytes) \ do \ { \ memcpy((arr_desc_dest_ptr)->data_ptr, \ (arr_desc_src_ptr)->data_ptr, \ BOUND(0, \ (arr_desc_dest_ptr)->underlying_size, \ bytes)); \ } while (0) /** * Evaluate to true if the source #ARR_DESC_t contents will fit into the * destination #ARR_DESC_t and false otherwise. */ #define ARR_DESC_COPYABLE(arr_desc_dest_ptr, arr_desc_src_ptr) \ (ARR_DESC_BYTES(arr_desc_src_ptr) <= \ (arr_desc_dest_ptr)->underlying_size) /** * Copy all the data from the source #ARR_DESC_t to the destination * #ARR_DESC_t. * * @note If the destination #ARR_DESC_t is too small to fit the source data the * copy is aborted and nothing happens. */ #define ARR_DESC_COPY(arr_desc_dest_ptr, arr_desc_src_ptr) \ do \ { \ if (ARR_DESC_COPYABLE(arr_desc_dest_ptr, \ arr_desc_src_ptr)) \ { \ ARR_DESC_MEMCPY(arr_desc_dest_ptr, \ arr_desc_src_ptr, \ ARR_DESC_BYTES(arr_desc_src_ptr)); \ /* Update the properties*/ \ (arr_desc_dest_ptr)->element_count = \ (arr_desc_src_ptr)->element_count; \ (arr_desc_dest_ptr)->element_size = \ (arr_desc_src_ptr)->element_size; \ } \ } while (0) /** * Compare the data in two #ARR_DESC_t structs for the specified number of * bytes. */ #define ARR_DESC_MEMCMP(arr_desc_ptr_a, arr_desc_ptr_b, bytes) \ memcmp((arr_desc_ptr_a)->data_ptr, \ (arr_desc_ptr_b)->data_ptr, \ bytes) /* Note the lacking semicolon */ \ /** * Zero out the contents of the #ARR_DESC_t. */ #define ARR_DESC_ZERO(arr_desc_ptr) \ ARR_DESC_MEMSET(arr_desc_ptr, \ 0, \ (arr_desc_ptr)->underlying_size) /** * Evaluate to the data address in #ARR_DESC_t at offset. */ #define ARR_DESC_DATA_ADDR(type, arr_desc_ptr, offset) \ ((void*)(((type *) \ ((arr_desc_ptr)->data_ptr)) \ + offset)) /** * Evaluate to the element in #ARR_DESC_t with type at idx. */ #define ARR_DESC_ELT(type, idx, arr_desc_ptr) \ (*((type *) ARR_DESC_DATA_ADDR(type, \ arr_desc_ptr, \ idx))) #endif /* _ARR_DESC_H_ */
8,980
C
39.638009
84
0.412027
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/util/util.h
#ifndef _UTIL_H_ #define _UTIL_H_ /*--------------------------------------------------------------------------------*/ /* Macros and Defines */ /*--------------------------------------------------------------------------------*/ /** * Convert a symbol to a string and add a 'NewLine'. */ #define STR_NL(x) STR1_NL(x) #define STR1_NL(x) (STR2_NL(x)"\n") #define STR2_NL(x) #x /** * Convert a symbol to a string. */ #define STR(x) STR1(x) #define STR1(x) STR2(x) #define STR2(x) #x /** * Concatenate two symbols. */ #define CONCAT(a, b) CONCAT1(a, b) #define CONCAT1(a, b) CONCAT2(a, b) #define CONCAT2(a, b) a##b /** * Place curly braces around a varaible number of macro arguments. */ #define CURLY(...) {__VA_ARGS__} /** * Place parenthesis around a variable number of macro arguments. */ #define PAREN(...) (__VA_ARGS__) /* Standard min/max macros. */ #define MIN(x,y) (((x) < (y)) ? (x) : (y) ) #define MAX(x,y) (((x) > (y)) ? (x) : (y) ) /** * Bound value using low and high limits. * * Evaluate to a number in the range, endpoint inclusive. */ #define BOUND(low, high, value) \ MAX(MIN(high, value), low) #endif /* _UTIL_H_ */
1,186
C
21.396226
84
0.50253
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/opt_arg/pp_narg.h
#ifndef _PP_NARG_H_ #define _PP_NARG_H_ #define PP_NARG(...) \ PP_NARG_(__VA_ARGS__,PP_RSEQ_N()) #define PP_NARG_(...) \ PP_ARG_N(__VA_ARGS__) #define PP_ARG_N( \ _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \ _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \ _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \ _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \ _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \ _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \ _61,_62,_63,N,...) N #define PP_RSEQ_N() \ 63,62,61,60, \ 59,58,57,56,55,54,53,52,51,50, \ 49,48,47,46,45,44,43,42,41,40, \ 39,38,37,36,35,34,33,32,31,30, \ 29,28,27,26,25,24,23,22,21,20, \ 19,18,17,16,15,14,13,12,11,10, \ 9,8,7,6,5,4,3,2,1,0 #endif /* _PP_NARG_H_ */
1,157
C
43.53846
59
0.306828
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/opt_arg/opt_arg.h
#ifndef _OPT_ARG_H_ #define _OPT_ARG_H_ /*--------------------------------------------------------------------------------*/ /* Includes */ /*--------------------------------------------------------------------------------*/ #include "pp_narg.h" #include "splice.h" /* If you are Joseph Jaoudi, you have a snippet which expands into an example. If you are not Joseph, but possess his code, study the examples. If you have no examples, turn back contact Joseph. */ #endif /* _OPT_ARG_H_ */
499
C
30.249998
84
0.448898
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/Common/JTest/inc/opt_arg/splice.h
#ifndef _SPLICE_H_ #define _SPLICE_H_ #define SPLICE(a,b) SPLICE_1(a,b) #define SPLICE_1(a,b) SPLICE_2(a,b) #define SPLICE_2(a,b) a##b #endif /* _SPLICE_H_ */
161
C
16.999998
35
0.63354
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/rfft.c
#include "ref.h" #include "arm_const_structs.h" void ref_rfft_f32( arm_rfft_instance_f32 * S, float32_t * pSrc, float32_t * pDst) { uint32_t i; if (S->ifftFlagR) { for(i=0;i<S->fftLenReal*2;i++) { pDst[i] = pSrc[i]; } } else { for(i=0;i<S->fftLenReal;i++) { pDst[2*i+0] = pSrc[i]; pDst[2*i+1] = 0.0f; } } switch(S->fftLenReal) { case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, pDst, S->ifftFlagR, S->bitReverseFlagR); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, pDst, S->ifftFlagR, S->bitReverseFlagR); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, pDst, S->ifftFlagR, S->bitReverseFlagR); break; case 8192: ref_cfft_f32(&ref_cfft_sR_f32_len8192, pDst, S->ifftFlagR, S->bitReverseFlagR); break; } if (S->ifftFlagR) { //throw away the imaginary part which should be all zeros for(i=0;i<S->fftLenReal;i++) { pDst[i] = pDst[2*i]; } } } void ref_rfft_fast_f32( arm_rfft_fast_instance_f32 * S, float32_t * p, float32_t * pOut, uint8_t ifftFlag) { uint32_t i,j; if (ifftFlag) { for(i=0;i<S->fftLenRFFT;i++) { pOut[i] = p[i]; } //unpack first sample's complex part into middle sample's real part pOut[S->fftLenRFFT] = pOut[1]; pOut[S->fftLenRFFT+1] = 0; pOut[1] = 0; j=4; for(i = S->fftLenRFFT / 2 + 1;i < S->fftLenRFFT;i++) { pOut[2*i+0] = p[2*i+0 - j]; pOut[2*i+1] = -p[2*i+1 - j]; j+=4; } } else { for(i=0;i<S->fftLenRFFT;i++) { pOut[2*i+0] = p[i]; pOut[2*i+1] = 0.0f; } } switch(S->fftLenRFFT) { case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, pOut, ifftFlag, 1); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, pOut, ifftFlag, 1); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, pOut, ifftFlag, 1); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, pOut, ifftFlag, 1); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, pOut, ifftFlag, 1); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, pOut, ifftFlag, 1); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, pOut, ifftFlag, 1); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, pOut, ifftFlag, 1); break; } if (ifftFlag) { //throw away the imaginary part which should be all zeros for(i=0;i<S->fftLenRFFT;i++) { pOut[i] = pOut[2*i]; } } else { //pack last sample's real part into first sample's complex part pOut[1] = pOut[S->fftLenRFFT]; } } void ref_rfft_q31( const arm_rfft_instance_q31 * S, q31_t * pSrc, q31_t * pDst) { uint32_t i; float32_t *fDst = (float32_t*)pDst; if (S->ifftFlagR) { for(i=0;i<S->fftLenReal*2;i++) { fDst[i] = (float32_t)pSrc[i] / 2147483648.0f; } } else { for(i=0;i<S->fftLenReal;i++) { fDst[2*i+0] = (float32_t)pSrc[i] / 2147483648.0f; fDst[2*i+1] = 0.0f; } } switch(S->fftLenReal) { case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 8192: ref_cfft_f32(&ref_cfft_sR_f32_len8192, fDst, S->ifftFlagR, S->bitReverseFlagR); break; } if (S->ifftFlagR) { //throw away the imaginary part which should be all zeros for(i=0;i<S->fftLenReal;i++) { //read the float data, scale up for q31, cast to q31 pDst[i] = (q31_t)( fDst[2*i] * 2147483648.0f); } } else { for(i=0;i<S->fftLenReal;i++) { //read the float data, scale up for q31, cast to q31 pDst[i] = (q31_t)( fDst[i] * 2147483648.0f / (float32_t)S->fftLenReal); } } } void ref_rfft_q15( const arm_rfft_instance_q15 * S, q15_t * pSrc, q15_t * pDst) { uint32_t i; float32_t *fDst = (float32_t*)pDst; if (S->ifftFlagR) { for(i=0;i<S->fftLenReal*2;i++) { fDst[i] = (float32_t)pSrc[i] / 32768.0f; } } else { for(i=0;i<S->fftLenReal;i++) { //read the q15 data, cast to float, scale down for float fDst[2*i+0] = (float32_t)pSrc[i] / 32768.0f; fDst[2*i+1] = 0.0f; } } switch(S->fftLenReal) { case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fDst, S->ifftFlagR, S->bitReverseFlagR); break; case 8192: ref_cfft_f32(&ref_cfft_sR_f32_len8192, fDst, S->ifftFlagR, S->bitReverseFlagR); break; } if (S->ifftFlagR) { //throw away the imaginary part which should be all zeros for(i=0;i<S->fftLenReal;i++) { pDst[i] = (q15_t)( fDst[2*i] * 32768.0f); } } else { for(i=0;i<S->fftLenReal;i++) { pDst[i] = (q15_t)( fDst[i] * 32768.0f / (float32_t)S->fftLenReal); } } }
6,134
C
19.247525
82
0.59537
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/TransformFunctions.c
#include "cfft.c" #include "dct4.c" #include "rfft.c"
55
C
10.199998
17
0.654545
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/bitreversal.c
#include "ref.h" ;/* ;* @brief In-place bit reversal function. ;* @param[in, out] *pSrc points to the in-place buffer of unknown 32-bit data type. ;* @param[in] bitRevLen bit reversal table length ;* @param[in] *pBitRevTab points to bit reversal table. ;* @return none. ;*/ void ref_arm_bitreversal_32(uint32_t *pSrc, uint32_t bitRevLen, uint32_t *pBitRevTab) { uint32_t a,b,i,tmp; for(i=0; i<bitRevLen; i++) { a = pBitRevTab[2*i]; b = pBitRevTab[2*i + 1]; //real tmp = pSrc[a]; pSrc[a] = pSrc[b]; pSrc[b] = tmp; //complex tmp = pSrc[a+1]; pSrc[a+1] = pSrc[b+1]; pSrc[b+1] = tmp; } }
657
C
20.225806
91
0.579909
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/dct4.c
#include "ref.h" void ref_dct4_f32( const arm_dct4_instance_f32 * S, float32_t * pState, float32_t * pInlineBuffer) { uint32_t n,k; float32_t sum; float32_t pi_by_N = 3.14159265358979f / (float32_t)S->N; float32_t tmp; float32_t normalize = sqrtf(2.0f / (float32_t)S->N); for(k=0;k<S->N;k++) { sum=0.0f; tmp = ((float32_t)k + 0.5f)*pi_by_N; for(n=0;n<S->N;n++) { sum += pInlineBuffer[n] * cosf(tmp * ((float32_t)n + 0.5f)); } scratchArray[k] = normalize * sum; } for(k=0;k<S->N;k++) { pInlineBuffer[k] = scratchArray[k]; } } void ref_dct4_q31( const arm_dct4_instance_q31 * S, q31_t * pState, q31_t * pInlineBuffer) { arm_dct4_instance_f32 SS; float32_t *fSrc = (float32_t*)pInlineBuffer; uint32_t i; SS.N = S->N; for(i=0;i<S->N;i++) { //read the q31 data, cast to float, scale down for float fSrc[i] = (float32_t)pInlineBuffer[i] / 2147483648.0f; } ref_dct4_f32(&SS,(float32_t*)0,fSrc); for(i=0;i<S->N;i++) { fSrc[i] = fSrc[i] * 2147483648.0f / (float32_t)S->N ; fSrc[i] += (fSrc[i] > 0) ? 0.5f : -0.5f; pInlineBuffer[i] = (q31_t)fSrc[i]; } } void ref_dct4_q15( const arm_dct4_instance_q15 * S, q15_t * pState, q15_t * pInlineBuffer) { arm_dct4_instance_f32 SS; float32_t *fSrc = (float32_t*)pInlineBuffer; uint32_t i; SS.N = S->N; for(i=0;i<S->N;i++) { //read the q15 data, cast to float, scale down for float, place in temporary buffer scratchArray[i] = (float32_t)pInlineBuffer[i] / 32768.0f; } for(i=0;i<S->N;i++) { //copy from temp buffer to final buffer fSrc[i] = scratchArray[i]; } ref_dct4_f32(&SS,(float32_t*)0,fSrc); for(i=0;i<S->N;i++) { fSrc[i] = fSrc[i] * 32768.0f / (float32_t)S->N; fSrc[i] += (fSrc[i] > 0) ? 0.5f : -0.5f; pInlineBuffer[i] = (q15_t)fSrc[i]; } }
1,808
C
19.1
85
0.587389
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/TransformFunctions/cfft.c
#include "ref.h" #include "arm_const_structs.h" void ref_cfft_f32( const arm_cfft_instance_f32 * S, float32_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag) { int n, mmax, m, j, istep, i; float32_t wtemp, wr, wpr, wpi, wi, theta; float32_t tempr, tempi; float32_t * data = p1; uint32_t N = S->fftLen; int32_t dir = (ifftFlag) ? -1 : 1; // decrement pointer since the original version used fortran style indexing. data--; n = N << 1; j = 1; for (i = 1; i < n; i += 2) { if (j > i) { tempr = data[j]; data[j] = data[i]; data[i] = tempr; tempr = data[j+1]; data[j+1] = data[i+1]; data[i+1] = tempr; } m = n >> 1; while (m >= 2 && j > m) { j -= m; m >>= 1; } j += m; } mmax = 2; while (n > mmax) { istep = 2*mmax; theta = -6.283185307179586f/(dir*mmax); wtemp = sinf(0.5f*theta); wpr = -2.0f*wtemp*wtemp; wpi = sinf(theta); wr = 1.0f; wi = 0.0f; for (m = 1; m < mmax; m += 2) { for (i = m; i <= n; i += istep) { j =i + mmax; tempr = wr*data[j] - wi*data[j+1]; tempi = wr*data[j+1] + wi*data[j]; data[j] = data[i] - tempr; data[j+1] = data[i+1] - tempi; data[i] += tempr; data[i+1] += tempi; } wr = (wtemp = wr)*wpr - wi*wpi + wr; wi = wi*wpr + wtemp*wpi + wi; } mmax = istep; } // Inverse transform is scaled by 1/N if (ifftFlag) { data++; for(i = 0; i<2*N; i++) { data[i] /= N; } } } void ref_cfft_q31( const arm_cfft_instance_q31 * S, q31_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag) { uint32_t i; float32_t *fSrc = (float32_t*)p1; for(i=0;i<S->fftLen*2;i++) { //read the q31 data, cast to float, scale down for float fSrc[i] = (float32_t)p1[i] / 2147483648.0f; } switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, ifftFlag, bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, ifftFlag, bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, ifftFlag, bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, ifftFlag, bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, ifftFlag, bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, ifftFlag, bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, ifftFlag, bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, ifftFlag, bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, ifftFlag, bitReverseFlag); break; } if (ifftFlag) { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q31, cast to q31 p1[i] = (q31_t)( fSrc[i] * 2147483648.0f ); } } else { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q31, cast to q31 p1[i] = (q31_t)( fSrc[i] * 2147483648.0f / (float32_t)S->fftLen); } } } void ref_cfft_q15( const arm_cfft_instance_q15 * S, q15_t * pSrc, uint8_t ifftFlag, uint8_t bitReverseFlag) { uint32_t i; float32_t *fSrc = (float32_t*)pSrc; for(i=0;i<S->fftLen*2;i++) { //read the q15 data, cast to float, scale down for float, place in temporary buffer scratchArray[i] = (float32_t)pSrc[i] / 32768.0f; } for(i=0;i<S->fftLen*2;i++) { //copy from temp buffer to final buffer fSrc[i] = scratchArray[i]; } switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, ifftFlag, bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, ifftFlag, bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, ifftFlag, bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, ifftFlag, bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, ifftFlag, bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, ifftFlag, bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, ifftFlag, bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, ifftFlag, bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, ifftFlag, bitReverseFlag); break; } if (ifftFlag) { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q15, cast to q15 pSrc[i] = (q15_t)( fSrc[i] * 32768.0f ); } } else { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q15, cast to q15 pSrc[i] = (q15_t)( fSrc[i] * 32768.0f / (float32_t)S->fftLen); } } } void ref_cfft_radix2_f32( const arm_cfft_radix2_instance_f32 * S, float32_t * pSrc) { switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, pSrc, S->ifftFlag, S->bitReverseFlag); break; } } void ref_cfft_radix2_q31( const arm_cfft_radix2_instance_q31 * S, q31_t * pSrc) { uint32_t i; float32_t *fSrc = (float32_t*)pSrc; for(i=0;i<S->fftLen*2;i++) { //read the q31 data, cast to float, scale down for float fSrc[i] = (float32_t)pSrc[i] / 2147483648.0f; } switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag); break; } if (S->ifftFlag) { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q31, cast to q31 pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f ); } } else { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q31, cast to q31 pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f / (float32_t)S->fftLen); } } } void ref_cfft_radix2_q15( const arm_cfft_radix2_instance_q15 * S, q15_t * pSrc) { uint32_t i; float32_t *fSrc = (float32_t*)pSrc; for(i=0;i<S->fftLen*2;i++) { //read the q15 data, cast to float, scale down for float, place in temporary buffer scratchArray[i] = (float32_t)pSrc[i] / 32768.0f; } for(i=0;i<S->fftLen*2;i++) { //copy from temp buffer to final buffer fSrc[i] = scratchArray[i]; } switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag); break; } if (S->ifftFlag) { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q15, cast to q15 pSrc[i] = (q15_t)( fSrc[i] * 32768.0f ); } } else { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q15, cast to q15 pSrc[i] = (q15_t)( fSrc[i] * 32768.0f / (float32_t)S->fftLen); } } } void ref_cfft_radix4_f32( const arm_cfft_radix4_instance_f32 * S, float32_t * pSrc) { switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, pSrc, S->ifftFlag, S->bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, pSrc, S->ifftFlag, S->bitReverseFlag); break; } } void ref_cfft_radix4_q31( const arm_cfft_radix4_instance_q31 * S, q31_t * pSrc) { uint32_t i; float32_t *fSrc = (float32_t*)pSrc; for(i=0;i<S->fftLen*2;i++) { //read the q31 data, cast to float, scale down for float fSrc[i] = (float32_t)pSrc[i] / 2147483648.0f; } switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag); break; } if (S->ifftFlag) { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q31, cast to q31 pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f ); } } else { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q31, cast to q31 pSrc[i] = (q31_t)( fSrc[i] * 2147483648.0f / (float32_t)S->fftLen); } } } void ref_cfft_radix4_q15( const arm_cfft_radix4_instance_q15 * S, q15_t * pSrc) { uint32_t i; float32_t *fSrc = (float32_t*)pSrc; for(i=0;i<S->fftLen*2;i++) { //read the q15 data, cast to float, scale down for float, place in temporary buffer scratchArray[i] = (float32_t)pSrc[i] / 32768.0f; } for(i=0;i<S->fftLen*2;i++) { //copy from temp buffer to final buffer fSrc[i] = scratchArray[i]; } switch(S->fftLen) { case 16: ref_cfft_f32(&arm_cfft_sR_f32_len16, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 32: ref_cfft_f32(&arm_cfft_sR_f32_len32, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 64: ref_cfft_f32(&arm_cfft_sR_f32_len64, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 128: ref_cfft_f32(&arm_cfft_sR_f32_len128, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 256: ref_cfft_f32(&arm_cfft_sR_f32_len256, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 512: ref_cfft_f32(&arm_cfft_sR_f32_len512, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 1024: ref_cfft_f32(&arm_cfft_sR_f32_len1024, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 2048: ref_cfft_f32(&arm_cfft_sR_f32_len2048, fSrc, S->ifftFlag, S->bitReverseFlag); break; case 4096: ref_cfft_f32(&arm_cfft_sR_f32_len4096, fSrc, S->ifftFlag, S->bitReverseFlag); break; } if (S->ifftFlag) { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q15, cast to q15 pSrc[i] = (q15_t)( fSrc[i] * 32768.0f ); } } else { for(i=0;i<S->fftLen*2;i++) { //read the float data, scale up for q15, cast to q15 pSrc[i] = (q15_t)( fSrc[i] * 32768.0f / (float32_t)S->fftLen); } } }
13,641
C
21.774624
85
0.606627
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/Intrinsics/Intrinsics_.c
#include "intrinsics.c"
26
C
5.749999
23
0.692308
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/Intrinsics/intrinsics.c
#include "ref.h" q31_t ref__QADD8(q31_t x, q31_t y) { q31_t sum; q7_t r, s, t, u; r = (q7_t) x; s = (q7_t) y; r = ref_sat_n((q31_t) (r + s), 8); s = ref_sat_n(((q31_t) (((x << 16) >> 24) + ((y << 16) >> 24))), 8); t = ref_sat_n(((q31_t) (((x << 8) >> 24) + ((y << 8) >> 24))), 8); u = ref_sat_n(((q31_t) ((x >> 24) + (y >> 24))), 8); sum = (((q31_t) u << 24) & 0xFF000000) | (((q31_t) t << 16) & 0x00FF0000) | (((q31_t) s << 8) & 0x0000FF00) | (r & 0x000000FF); return sum; } q31_t ref__QSUB8(q31_t x, q31_t y) { q31_t sum; q31_t r, s, t, u; r = (q7_t) x; s = (q7_t) y; r = ref_sat_n((r - s), 8); s = ref_sat_n(((q31_t) (((x << 16) >> 24) - ((y << 16) >> 24))), 8) << 8; t = ref_sat_n(((q31_t) (((x << 8) >> 24) - ((y << 8) >> 24))), 8) << 16; u = ref_sat_n(((q31_t) ((x >> 24) - (y >> 24))), 8) << 24; sum = (u & 0xFF000000) | (t & 0x00FF0000) | (s & 0x0000FF00) | (r & 0x000000FF); return sum; } q31_t ref__QADD16(q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (q15_t) x; s = (q15_t) y; r = ref_sat_q15(r + s); s = (q31_t)ref_sat_q15(((q31_t) ((x >> 16) + (y >> 16)))) << 16; sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } q31_t ref__SHADD16(q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (q15_t) x; s = (q15_t) y; r = (r + s) >> 1; s = ((q31_t) (((x >> 16) + (y >> 16)) >> 1) << 16); sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } q31_t ref__QSUB16(q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (q15_t) x; s = (q15_t) y; r = ref_sat_q15(r - s); s = (q31_t)ref_sat_q15(((q31_t) ((x >> 16) - (y >> 16)))) << 16; sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } q31_t ref__SHSUB16(q31_t x, q31_t y) { q31_t diff; q31_t r, s; r = (q15_t) x; s = (q15_t) y; r = ((r >> 1) - (s >> 1)); s = (((x >> 17) - (y >> 17)) << 16); diff = (s & 0xFFFF0000) | (r & 0x0000FFFF); return diff; } q31_t ref__QASX(q31_t x, q31_t y) { q31_t sum = 0; q31_t xL, xH, yL, yH; // extract bottom halfword and sign extend xL = (q15_t)(x & 0xffff); // extract bottom halfword and sign extend yL = (q15_t)(y & 0xffff); // extract top halfword and sign extend xH = (q15_t)(x >> 16); // extract top halfword and sign extend yH = (q15_t)(y >> 16); sum = (((q31_t)ref_sat_q15(xH + yL )) << 16) | (((q31_t)ref_sat_q15(xL - yH )) & 0xffff); return sum; } q31_t ref__SHASX(q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (q15_t) x; s = (q15_t) y; r = (r - (y >> 16)) / 2; s = (((x >> 16) + s) << 15); sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } q31_t ref__QSAX(q31_t x, q31_t y) { q31_t sum = 0; q31_t xL, xH, yL, yH; // extract bottom halfword and sign extend xL = (q15_t)(x & 0xffff); // extract bottom halfword and sign extend yL = (q15_t)(y & 0xffff); // extract top halfword and sign extend xH = (q15_t)(x >> 16); // extract top halfword and sign extend yH = (q15_t)(y >> 16); sum = (((q31_t)ref_sat_q15(xH - yL )) << 16) | (((q31_t)ref_sat_q15(xL + yH )) & 0xffff); return sum; } q31_t ref__SHSAX(q31_t x, q31_t y) { q31_t sum; q31_t r, s; r = (q15_t) x; s = (q15_t) y; r = (r + (y >> 16)) / 2; s = (((x >> 16) - s) << 15); sum = (s & 0xFFFF0000) | (r & 0x0000FFFF); return sum; } q31_t ref__SMUSDX(q31_t x, q31_t y) { return ((q31_t) (((q15_t) x * (q15_t) (y >> 16)) - ((q15_t) (x >> 16) * (q15_t) y))); } q31_t ref__SMUADX(q31_t x, q31_t y) { return ((q31_t) (((q15_t) x * (q15_t) (y >> 16)) + ((q15_t) (x >> 16) * (q15_t) y))); } q31_t ref__QADD(q31_t x, q31_t y) { return ref_sat_q31((q63_t) x + y); } q31_t ref__QSUB(q31_t x, q31_t y) { return ref_sat_q31((q63_t) x - y); } q31_t ref__SMLAD(q31_t x, q31_t y, q31_t sum) { return (sum + ((q15_t) (x >> 16) * (q15_t) (y >> 16)) + ((q15_t) x * (q15_t) y)); } q31_t ref__SMLADX(q31_t x, q31_t y, q31_t sum) { return (sum + ((q15_t) (x >> 16) * (q15_t) (y)) + ((q15_t) x * (q15_t) (y >> 16))); } q31_t ref__SMLSDX(q31_t x, q31_t y, q31_t sum) { return (sum - ((q15_t) (x >> 16) * (q15_t) (y)) + ((q15_t) x * (q15_t) (y >> 16))); } q63_t ref__SMLALD(q31_t x, q31_t y, q63_t sum) { return (sum + ((q15_t) (x >> 16) * (q15_t) (y >> 16)) + ((q15_t) x * (q15_t) y)); } q63_t ref__SMLALDX(q31_t x, q31_t y, q63_t sum) { return (sum + ((q15_t) (x >> 16) * (q15_t) y)) + ((q15_t) x * (q15_t) (y >> 16)); } q31_t ref__SMUAD(q31_t x, q31_t y) { return (((x >> 16) * (y >> 16)) + (((x << 16) >> 16) * ((y << 16) >> 16))); } q31_t ref__SMUSD(q31_t x, q31_t y) { return (-((x >> 16) * (y >> 16)) + (((x << 16) >> 16) * ((y << 16) >> 16))); } q31_t ref__SXTB16(q31_t x) { return ((((x << 24) >> 24) & 0x0000FFFF) | (((x << 8) >> 8) & 0xFFFF0000)); }
4,901
C
19.51046
88
0.450928
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/mat_helper.c
#include "ref.h" float32_t ref_detrm(float32_t *pSrc, float32_t *temp, uint32_t size) { float32_t s = 1, det = 0; int i, j, m, n, c; if ( size == 1 ) { return ( pSrc[ 0 ] ); } else { det = 0; for ( c = 0;c < size;c++ ) { m = 0; n = 0; for ( i = 0;i < size;i++ ) { for ( j = 0;j < size;j++ ) { temp[ i*size + j ] = 0; if ( i != 0 && j != c ) { temp[ m*(size-1) + n ] = pSrc[ i*size + j ]; if ( n < ( size - 2 ) ) { n++; } else { n = 0; m++; } } } } det += s * ( pSrc[ c ] * ref_detrm( temp, temp + size*size, size - 1 ) ); s = -s; } } return ( det ); } void ref_cofact(float32_t *pSrc, float32_t *pDst, float32_t *temp, uint32_t size) { int p, q, m, n, i, j; if (size == 1) { pDst[0] = 1; return; } for ( q = 0;q < size;q++ ) { for ( p = 0;p < size;p++ ) { m = 0; n = 0; for ( i = 0;i < size;i++ ) { for ( j = 0;j < size;j++ ) { temp[ i*size + j ] = 0; if ( i != q && j != p ) { temp[ m*(size-1) + n ] = pSrc[ i*size + j ]; if ( n < ( size - 2 ) ) { n++; } else { n = 0; m++; } } } } pDst[ q*size + p ] = ref_pow( -1, q + p ) * ref_detrm( temp, temp + (size-1)*(size-1), size - 1 ); } } } float64_t ref_detrm64(float64_t *pSrc, float64_t *temp, uint32_t size) { float64_t s = 1, det = 0; int i, j, m, n, c; if ( size == 1 ) { return ( pSrc[ 0 ] ); } else { det = 0; for ( c = 0;c < size;c++ ) { m = 0; n = 0; for ( i = 0;i < size;i++ ) { for ( j = 0;j < size;j++ ) { temp[ i*size + j ] = 0; if ( i != 0 && j != c ) { temp[ m*(size-1) + n ] = pSrc[ i*size + j ]; if ( n < ( size - 2 ) ) { n++; } else { n = 0; m++; } } } } det += s * ( pSrc[ c ] * ref_detrm64( temp, temp + size*size, size - 1 ) ); s = -s; } } return ( det ); } void ref_cofact64(float64_t *pSrc, float64_t *pDst, float64_t *temp, uint32_t size) { int p, q, m, n, i, j; if (size == 1) { pDst[0] = 1; return; } for ( q = 0;q < size;q++ ) { for ( p = 0;p < size;p++ ) { m = 0; n = 0; for ( i = 0;i < size;i++ ) { for ( j = 0;j < size;j++ ) { temp[ i*size + j ] = 0; if ( i != q && j != p ) { temp[ m*(size-1) + n ] = pSrc[ i*size + j ]; if ( n < ( size - 2 ) ) { n++; } else { n = 0; m++; } } } } pDst[ q*size + p ] = ref_pow( -1, q + p ) * ref_detrm64( temp, temp + (size-1)*(size-1), size - 1 ); } } }
3,723
C
18.195876
109
0.262423
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/HelperFunctions.c
#include "mat_helper.c" #include "ref_helper.c"
50
C
9.199998
23
0.68
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/HelperFunctions/ref_helper.c
#include "ref.h" float32_t scratchArray[8192*2]; arm_cfft_instance_f32 ref_cfft_sR_f32_len8192 = { 8192, 0, 0, 0 }; q31_t ref_sat_n(q31_t num, uint32_t bits) { int32_t posMax, negMin; uint32_t i; posMax = 1; for (i = 0; i < (bits - 1); i++) { posMax = posMax * 2; } if (num > 0) { posMax = (posMax - 1); if (num > posMax) { num = posMax; } } else { negMin = -posMax; if (num < negMin) { num = negMin; } } return (num); } q31_t ref_sat_q31(q63_t num) { if (num > (q63_t)INT_MAX) { return INT_MAX; } else if (num < (q63_t)0xffffffff80000000ll) { return INT_MIN; } else { return (q31_t)num; } } q15_t ref_sat_q15(q31_t num) { if (num > (q31_t)SHRT_MAX) { return SHRT_MAX; } else if (num < (q31_t)0xffff8000) { return SHRT_MIN; } else { return (q15_t)num; } } q7_t ref_sat_q7(q15_t num) { if (num > (q15_t)SCHAR_MAX) { return SCHAR_MAX; } else if (num < (q15_t)0xff80) { return SCHAR_MIN; } else { return (q7_t)num; } } float32_t ref_pow(float32_t a, uint32_t b) { uint32_t i; float32_t r = a; for(i=1;i<b;i++) { r *= a; } if ( b == 0) { return 1; } return r; }
1,173
C
10.288461
66
0.543052
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/cmplx_mag.c
#include "ref.h" void ref_cmplx_mag_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples*2;i+=2) { *pDst++ = sqrtf(pSrc[i] * pSrc[i] + pSrc[i+1] * pSrc[i+1]); } } void ref_cmplx_mag_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples) { uint32_t i; q31_t acc0,acc1,out; for(i=0;i<numSamples*2;i+=2) { acc0 = (q31_t)(((q63_t)pSrc[i] * pSrc[i]) >> 33); acc1 = (q31_t)(((q63_t)pSrc[i+1] * pSrc[i+1]) >> 33); out = acc0 + acc1; *pDst++ = (q31_t)(sqrtf((float)out / 2147483648.0f) * 2147483648.0f); } } void ref_cmplx_mag_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples) { uint32_t i; q31_t acc0,acc1; q15_t out; for(i=0;i<numSamples*2;i+=2) { acc0 = pSrc[i] * pSrc[i]; acc1 = pSrc[i+1] * pSrc[i+1]; out = (q15_t) (((q63_t) acc0 + acc1) >> 17); *pDst++ = (q15_t)(sqrtf((float)out / 32768.0f) * 32768.0f); } }
914
C
17.3
71
0.557987
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/cmplx_dot_prod.c
#include "ref.h" void ref_cmplx_dot_prod_f32( float32_t * pSrcA, float32_t * pSrcB, uint32_t numSamples, float32_t * realResult, float32_t * imagResult) { float32_t sumr, sumi; uint32_t i; sumr = 0; sumi = 0; for(i=0;i<numSamples*2;i+=2) { sumr += pSrcA[i] * pSrcB[i] - pSrcA[i+1] * pSrcB[i+1]; sumi += pSrcA[i] * pSrcB[i+1] + pSrcA[i+1] * pSrcB[i]; } *realResult = sumr; *imagResult = sumi; } void ref_cmplx_dot_prod_q31( q31_t * pSrcA, q31_t * pSrcB, uint32_t numSamples, q63_t * realResult, q63_t * imagResult) { q63_t sumr, sumi; uint32_t i; sumr = 0; sumi = 0; for(i=0;i<numSamples*2;i+=2) { //shifting down 14 here to provide guard bits sumr += (((q63_t)pSrcA[i] * pSrcB[i] ) >> 14) - (((q63_t)pSrcA[i+1] * pSrcB[i+1]) >> 14); sumi += (((q63_t)pSrcA[i] * pSrcB[i+1]) >> 14) + (((q63_t)pSrcA[i+1] * pSrcB[i] ) >> 14); } *realResult = sumr; *imagResult = sumi; } void ref_cmplx_dot_prod_q15( q15_t * pSrcA, q15_t * pSrcB, uint32_t numSamples, q31_t * realResult, q31_t * imagResult) { q63_t sumr, sumi; uint32_t i; sumr = 0; sumi = 0; for(i=0;i<numSamples*2;i+=2) { sumr += (q31_t)pSrcA[i] * pSrcB[i] - (q31_t)pSrcA[i+1] * pSrcB[i+1]; sumi += (q31_t)pSrcA[i] * pSrcB[i+1] + (q31_t)pSrcA[i+1] * pSrcB[i]; } //shifting down 6 at the end here because there are already 32 guard bits available, this method is more accurate *realResult = (q31_t)(sumr >> 6); *imagResult = (q31_t)(sumi >> 6); }
1,493
C
19.465753
114
0.585399
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/cmplx_mag_squared.c
#include "ref.h" void ref_cmplx_mag_squared_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples*2;i+=2) { *pDst++ = pSrc[i] * pSrc[i] + pSrc[i+1] * pSrc[i+1]; } } void ref_cmplx_mag_squared_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples) { uint32_t i; q31_t acc0,acc1; for(i=0;i<numSamples*2;i+=2) { acc0 = (q31_t)(((q63_t)pSrc[i] * pSrc[i]) >> 33); acc1 = (q31_t)(((q63_t)pSrc[i+1] * pSrc[i+1]) >> 33); *pDst++ = acc0 + acc1; } } void ref_cmplx_mag_squared_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples) { uint32_t i; q31_t acc0,acc1; for(i=0;i<numSamples*2;i+=2) { acc0 = pSrc[i] * pSrc[i]; acc1 = pSrc[i+1] * pSrc[i+1]; *pDst++ = (q15_t) (((q63_t) acc0 + acc1) >> 17); } }
789
C
15.80851
55
0.555133
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/cmplx_mult_real.c
#include "ref.h" void ref_cmplx_mult_real_f32( float32_t * pSrcCmplx, float32_t * pSrcReal, float32_t * pCmplxDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples;i++) { pCmplxDst[2*i+0] = pSrcCmplx[2*i+0] * pSrcReal[i]; pCmplxDst[2*i+1] = pSrcCmplx[2*i+1] * pSrcReal[i]; } } void ref_cmplx_mult_real_q31( q31_t * pSrcCmplx, q31_t * pSrcReal, q31_t * pCmplxDst, uint32_t numSamples) { uint32_t i; q31_t tempR, tempI; for(i=0;i<numSamples;i++) { tempR = ((q63_t) pSrcCmplx[2*i+0] * pSrcReal[i]) >> 32; tempI = ((q63_t) pSrcCmplx[2*i+1] * pSrcReal[i]) >> 32; pCmplxDst[2*i+0] = ref_sat_n(tempR, 31) << 1; pCmplxDst[2*i+1] = ref_sat_n(tempI, 31) << 1; } } void ref_cmplx_mult_real_q15( q15_t * pSrcCmplx, q15_t * pSrcReal, q15_t * pCmplxDst, uint32_t numSamples) { uint32_t i; q31_t tempR, tempI; for(i=0;i<numSamples;i++) { tempR = ((q31_t) pSrcCmplx[2*i+0] * pSrcReal[i]) >> 15; tempI = ((q31_t) pSrcCmplx[2*i+1] * pSrcReal[i]) >> 15; pCmplxDst[2*i+0] = ref_sat_q15(tempR); pCmplxDst[2*i+1] = ref_sat_q15(tempI); } }
1,091
C
19.603773
57
0.60495
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/cmplx_mult_cmplx.c
#include "ref.h" void ref_cmplx_mult_cmplx_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples*2;i+=2) { pDst[i] = pSrcA[i] * pSrcB[i] - pSrcA[i+1] * pSrcB[i+1]; pDst[i+1] = pSrcA[i] * pSrcB[i+1] + pSrcA[i+1] * pSrcB[i]; } } void ref_cmplx_mult_cmplx_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t numSamples) { uint32_t i; q31_t mul1, mul2, mul3, mul4; for(i=0;i<numSamples*2;i+=2) { mul1 = ((q63_t)pSrcA[i] * pSrcB[i]) >> 33; mul2 = ((q63_t)pSrcA[i+1] * pSrcB[i+1]) >> 33; mul3 = ((q63_t)pSrcA[i] * pSrcB[i+1]) >> 33; mul4 = ((q63_t)pSrcA[i+1] * pSrcB[i]) >> 33; pDst[i] = mul1 - mul2; pDst[i+1] = mul3 + mul4; } } void ref_cmplx_mult_cmplx_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t numSamples) { uint32_t i; q31_t mul1, mul2, mul3, mul4; for(i=0;i<numSamples*2;i+=2) { mul1 = ((q31_t)pSrcA[i] * pSrcB[i]) >> 17; mul2 = ((q31_t)pSrcA[i+1] * pSrcB[i+1]) >> 17; mul3 = ((q31_t)pSrcA[i] * pSrcB[i+1]) >> 17; mul4 = ((q31_t)pSrcA[i+1] * pSrcB[i]) >> 17; pDst[i] = mul1 - mul2; pDst[i+1] = mul3 + mul4; } }
1,195
C
19.982456
62
0.540586
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/ComplexMathFunctions.c
#include "cmplx_conj.c" #include "cmplx_dot_prod.c" #include "cmplx_mag.c" #include "cmplx_mag_squared.c" #include "cmplx_mult_cmplx.c" #include "cmplx_mult_real.c"
167
C
17.666665
30
0.712575
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ComplexMathFunctions/cmplx_conj.c
#include "ref.h" void ref_cmplx_conj_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples*2;i+=2) { pDst[i] = pSrc[i]; pDst[i+1] = -pSrc[i+1]; } } void ref_cmplx_conj_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples*2;i+=2) { pDst[i] = pSrc[i]; pDst[i+1] = -pSrc[i+1]; } } void ref_cmplx_conj_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples) { uint32_t i; for(i=0;i<numSamples*2;i+=2) { pDst[i] = pSrc[i]; pDst[i+1] = -pSrc[i+1]; } }
568
C
12.878048
29
0.566901
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ControllerFunctions/sin_cos.c
#include "ref.h" void ref_sin_cos_f32( float32_t theta, float32_t * pSinVal, float32_t * pCosVal) { //theta is given in degrees *pSinVal = sinf(theta * 6.28318530717959f / 360.0f); *pCosVal = cosf(theta * 6.28318530717959f / 360.0f); } void ref_sin_cos_q31( q31_t theta, q31_t * pSinVal, q31_t * pCosVal) { //theta is given in the range [-1,1) to represent [-pi,pi) *pSinVal = (q31_t)(sinf((float32_t)theta * 3.14159265358979f / 2147483648.0f) * 2147483648.0f); *pCosVal = (q31_t)(cosf((float32_t)theta * 3.14159265358979f / 2147483648.0f) * 2147483648.0f); }
580
C
25.40909
96
0.667241
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ControllerFunctions/pid.c
#include "ref.h" float32_t ref_pid_f32( arm_pid_instance_f32 * S, float32_t in) { float32_t out; /* y[n] = y[n-1] + A0 * x[n] + A1 * x[n-1] + A2 * x[n-2] */ out = S->state[2] + S->A0 * in + S->A1 * S->state[0] + S->A2 * S->state[1]; /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } q31_t ref_pid_q31( arm_pid_instance_q31 * S, q31_t in) { q63_t acc; q31_t out; /* acc = A0 * x[n] */ acc = (q63_t) S->A0 * in; /* acc += A1 * x[n-1] */ acc += (q63_t) S->A1 * S->state[0]; /* acc += A2 * x[n-2] */ acc += (q63_t) S->A2 * S->state[1]; /* convert output to 1.31 format to add y[n-1] */ out = (q31_t) (acc >> 31U); /* out += y[n-1] */ out += S->state[2]; /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); } q15_t ref_pid_q15( arm_pid_instance_q15 * S, q15_t in) { q63_t acc; q15_t out; q15_t A1, A2; #if defined (ARM_MATH_DSP) #ifndef ARM_MATH_BIG_ENDIAN A2 = S->A1 >> 16; A1 = (q15_t)S->A1; #else A1 = S->A1 >> 16; A2 = (q15_t)S->A1; #endif #else A1 = S->A1; A2 = S->A2; #endif /* acc = A0 * x[n] */ acc = ((q31_t) S->A0) * in; /* acc += A1 * x[n-1] + A2 * x[n-2] */ acc += (q31_t) A1 * S->state[0]; acc += (q31_t) A2 * S->state[1]; /* acc += y[n-1] */ acc += (q31_t) S->state[2] << 15; /* saturate the output */ out = ref_sat_q15(acc >> 15); /* Update state */ S->state[1] = S->state[0]; S->state[0] = in; S->state[2] = out; /* return to application */ return (out); }
1,618
C
15.520408
76
0.493201
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/ControllerFunctions/ControllerFunctions.c
#include "pid.c" #include "sin_cos.c"
40
C
7.199999
20
0.625
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FastMathFunctions/FastMathFunctions.c
#include "cos.c" #include "sin.c" #include "sqrt.c"
54
C
8.166665
17
0.62963
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FastMathFunctions/sqrt.c
#include "ref.h" arm_status ref_sqrt_q31(q31_t in, q31_t * pOut) { *pOut = (q31_t)(sqrtf((float32_t)in / 2147483648.0f) * 2147483648.0f); return ARM_MATH_SUCCESS; } arm_status ref_sqrt_q15(q15_t in, q15_t * pOut) { *pOut = (q15_t)(sqrtf((float32_t)in / 32768.0f) * 32768.0f); return ARM_MATH_SUCCESS; }
313
C
18.624999
71
0.642173
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FastMathFunctions/cos.c
#include "ref.h" q31_t ref_cos_q31(q31_t x) { return (q31_t)(cosf((float32_t)x * 6.28318530717959f / 2147483648.0f) * 2147483648.0f); } q15_t ref_cos_q15(q15_t x) { return (q15_t)(cosf((float32_t)x * 6.28318530717959f / 32768.0f) * 32768.0f); }
249
C
19.833332
88
0.654618
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FastMathFunctions/sin.c
#include "ref.h" q31_t ref_sin_q31(q31_t x) { return (q31_t)(sinf((float32_t)x * 6.28318530717959f / 2147483648.0f) * 2147483648.0f); } q15_t ref_sin_q15(q15_t x) { return (q15_t)(sinf((float32_t)x * 6.28318530717959f / 32768.0f) * 32768.0f); }
249
C
19.833332
88
0.654618
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/SupportFunctions/fill.c
#include "ref.h" void ref_fill_f32( float32_t value, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = value; } } void ref_fill_q31( q31_t value, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = value; } } void ref_fill_q15( q15_t value, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = value; } } void ref_fill_q7( q7_t value, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = value; } }
594
C
10.018518
25
0.572391
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/SupportFunctions/copy.c
#include "ref.h" void ref_copy_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i]; } } void ref_copy_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i]; } } void ref_copy_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i]; } } void ref_copy_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i]; } }
606
C
10.240741
25
0.554455
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/SupportFunctions/fixed_to_fixed.c
#include "ref.h" void ref_q31_to_q15( q31_t * pSrc, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] >> 16; } } void ref_q31_to_q7( q31_t * pSrc, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] >> 24; } } void ref_q15_to_q31( q15_t * pSrc, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((q31_t)pSrc[i]) << 16; } } void ref_q15_to_q7( q15_t * pSrc, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] >> 8; } } void ref_q7_to_q31( q7_t * pSrc, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((q31_t)pSrc[i]) << 24; } } void ref_q7_to_q15( q7_t * pSrc, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((q15_t)pSrc[i]) << 8; } }
958
C
10.9875
35
0.533403
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/SupportFunctions/SupportFunctions.c
#include "copy.c" #include "fill.c" #include "fixed_to_fixed.c" #include "fixed_to_float.c" #include "float_to_fixed.c"
121
C
16.428569
27
0.694215
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/SupportFunctions/fixed_to_float.c
#include "ref.h" void ref_q63_to_float( q63_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((float32_t)pSrc[i]) / 9223372036854775808.0f; } } void ref_q31_to_float( q31_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((float32_t)pSrc[i]) / 2147483648.0f; } } void ref_q15_to_float( q15_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((float32_t)pSrc[i]) / 32768.0f; } } void ref_q7_to_float( q7_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ((float32_t)pSrc[i]) / 128.0f; } }
746
C
12.833333
58
0.581769
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/SupportFunctions/float_to_fixed.c
#include "ref.h" void ref_float_to_q31( float32_t * pSrc, q31_t * pDst, uint32_t blockSize) { uint32_t i; float32_t in; for(i=0;i<blockSize;i++) { in = pSrc[i]; in *= 2147483648.0f; //scale up in += in > 0.0f ? 0.5f : -0.5f; //round pDst[i] = ref_sat_q31((q63_t)in); //cast and saturate } } void ref_float_to_q15( float32_t * pSrc, q15_t * pDst, uint32_t blockSize) { uint32_t i; float32_t in; for(i=0;i<blockSize;i++) { in = pSrc[i]; in *= 32768.0f; in += in > 0.0f ? 0.5f : -0.5f; pDst[i] = ref_sat_q15((q31_t)in); } } void ref_float_to_q7( float32_t * pSrc, q7_t * pDst, uint32_t blockSize) { uint32_t i; float32_t in; for(i=0;i<blockSize;i++) { in = pSrc[i]; in *= 128.0f; in += in > 0.0f ? 0.5f : -0.5f; pDst[i] = ref_sat_q7((q15_t)in); } }
818
C
14.45283
55
0.545232
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/shift.c
#include "ref.h" void ref_shift_q31( q31_t * pSrc, int8_t shiftBits, q31_t * pDst, uint32_t blockSize) { uint32_t i; if (shiftBits < 0) { for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] << shiftBits; } } else { for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] >> -shiftBits; } } } void ref_shift_q15( q15_t * pSrc, int8_t shiftBits, q15_t * pDst, uint32_t blockSize) { uint32_t i; if (shiftBits < 0) { for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] << shiftBits; } } else { for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] >> -shiftBits; } } } void ref_shift_q7( q7_t * pSrc, int8_t shiftBits, q7_t * pDst, uint32_t blockSize) { uint32_t i; if (shiftBits < 0) { for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] << shiftBits; } } else { for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] >> -shiftBits; } } }
893
C
11.081081
35
0.529675
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/sub.c
#include "ref.h" void ref_sub_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrcA[i] - pSrcB[i]; } } void ref_sub_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q31( (q63_t)pSrcA[i] - pSrcB[i] ); } } void ref_sub_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q15( (q31_t)pSrcA[i] - pSrcB[i] ); } } void ref_sub_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q7( (q15_t)pSrcA[i] - pSrcB[i] ); } }
790
C
12.637931
54
0.558228
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/negate.c
#include "ref.h" void ref_negate_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = -pSrc[i]; } } void ref_negate_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = -pSrc[i]; } } void ref_negate_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = -pSrc[i]; } } void ref_negate_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = -pSrc[i]; } }
618
C
10.462963
25
0.556634
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/dot_prod.c
#include "ref.h" void ref_dot_prod_f32( float32_t * pSrcA, float32_t * pSrcB, uint32_t blockSize, float32_t * result) { uint32_t i; float32_t sum = 0.0f; for(i=0;i<blockSize;i++) { sum += pSrcA[i] * pSrcB[i]; } *result = sum; } void ref_dot_prod_q31( q31_t * pSrcA, q31_t * pSrcB, uint32_t blockSize, q63_t * result) { uint32_t i; q63_t sum = 0.0f; for(i=0;i<blockSize;i++) { sum += ((q63_t)pSrcA[i] * pSrcB[i]) >> 14; //16.48 } *result = sum; } void ref_dot_prod_q15( q15_t * pSrcA, q15_t * pSrcB, uint32_t blockSize, q63_t * result) { uint32_t i; q63_t sum = 0.0f; for(i=0;i<blockSize;i++) { sum += (q31_t)pSrcA[i] * pSrcB[i]; //34.30 } *result = sum; } void ref_dot_prod_q7( q7_t * pSrcA, q7_t * pSrcB, uint32_t blockSize, q31_t * result) { uint32_t i; q31_t sum = 0.0f; for(i=0;i<blockSize;i++) { sum += (q31_t)pSrcA[i] * pSrcB[i]; //18.14 } *result = sum; }
947
C
13.363636
52
0.555438
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/offset.c
#include "ref.h" void ref_offset_f32( float32_t * pSrc, float32_t offset, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] + offset; } } void ref_offset_q31( q31_t * pSrc, q31_t offset, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q31( (q63_t)pSrc[i] + offset ); } } void ref_offset_q15( q15_t * pSrc, q15_t offset, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q15( (q31_t)pSrc[i] + offset ); } } void ref_offset_q7( q7_t * pSrc, q7_t offset, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q7( (q15_t)pSrc[i] + offset ); } }
782
C
12.5
51
0.574169
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/mult.c
#include "ref.h" void ref_mult_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrcA[i] * pSrcB[i]; } } void ref_mult_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize) { uint32_t i; q63_t temp; for(i=0;i<blockSize;i++) { temp = ((q63_t)pSrcA[i] * pSrcB[i]) >> 32; temp = temp << 1; pDst[i] = ref_sat_q31(temp); } } void ref_mult_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize) { uint32_t i; q31_t temp; for(i=0;i<blockSize;i++) { temp = ((q31_t)pSrcA[i] * pSrcB[i]) >> 15; //this comment is for JD, this is specifically 15 and not 16 like the q31 case might imply. This is because CMSIS DSP lib does it this way. No other reason. pDst[i] = ref_sat_q15(temp); } } void ref_mult_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize) { uint32_t i; q15_t temp; for(i=0;i<blockSize;i++) { temp = ((q15_t)pSrcA[i] * pSrcB[i]) >> 7; pDst[i] = ref_sat_q7(temp); } }
1,074
C
15.538461
203
0.583799
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/scale.c
#include "ref.h" void ref_scale_f32( float32_t * pSrc, float32_t scale, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] * scale; } } void ref_scale_q31( q31_t * pSrc, q31_t scaleFract, int8_t shift, q31_t * pDst, uint32_t blockSize) { uint32_t i; int8_t kShift = shift + 1; /* Shift to apply after scaling */ int8_t sign = (kShift & 0x80); q63_t temp; for(i=0;i<blockSize;i++) { temp = ((q63_t) pSrc[i] * scaleFract) >> 32; if (sign) pDst[i] = temp >> -kShift; else pDst[i] = ref_sat_q31( (q63_t)temp << kShift ); } } void ref_scale_q15( q15_t * pSrc, q15_t scaleFract, int8_t shift, q15_t * pDst, uint32_t blockSize) { uint32_t i; int8_t kShift = 15 - shift; /* Shift to apply after scaling */ for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q15(((q31_t) pSrc[i] * scaleFract) >> kShift); } } void ref_scale_q7( q7_t * pSrc, q7_t scaleFract, int8_t shift, q7_t * pDst, uint32_t blockSize) { uint32_t i; int8_t kShift = 7 - shift; /* Shift to apply after scaling */ for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q7(((q15_t) pSrc[i] * scaleFract) >> kShift); } }
1,262
C
17.042857
85
0.558637
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/BasicMathFunctions.c
#include "abs.c" #include "add.c" #include "dot_prod.c" #include "mult.c" #include "negate.c" #include "offset.c" #include "scale.c" #include "shift.c" #include "sub.c"
171
C
13.333332
21
0.666667
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/add.c
#include "ref.h" void ref_add_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrcA[i] + pSrcB[i]; } } void ref_add_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q31( (q63_t)pSrcA[i] + pSrcB[i] ); } } void ref_add_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q15( (q31_t)pSrcA[i] + pSrcB[i] ); } } void ref_add_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = ref_sat_q7( (q15_t)pSrcA[i] + pSrcB[i] ); } }
790
C
12.637931
54
0.558228
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/BasicMathFunctions/abs.c
#include "ref.h" void ref_abs_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i]; } } void ref_abs_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i]; } } void ref_abs_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i]; } } void ref_abs_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize) { uint32_t i; for(i=0;i<blockSize;i++) { pDst[i] = pSrc[i] < 0 ? -pSrc[i] : pSrc[i]; } }
702
C
12.018518
45
0.535613
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_inverse.c
#include "ref.h" arm_status ref_mat_inverse_f32( const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst) { float32_t det; uint32_t i, size; arm_matrix_instance_f32 tmp; tmp.numCols = pSrc->numCols; tmp.numRows = pSrc->numRows; tmp.pData = scratchArray; det = ref_detrm(pSrc->pData,scratchArray,pSrc->numCols); size = pSrc->numCols * pSrc->numCols; ref_cofact(pSrc->pData,scratchArray,scratchArray + size,pSrc->numCols); ref_mat_trans_f32(&tmp,pDst); for(i=0;i<size;i++) { pDst->pData[i] /= det; } return ARM_MATH_SUCCESS; } arm_status ref_mat_inverse_f64( const arm_matrix_instance_f64 * pSrc, arm_matrix_instance_f64 * pDst) { float64_t det; uint32_t i, size; arm_matrix_instance_f64 tmp; tmp.numCols = pSrc->numCols; tmp.numRows = pSrc->numRows; tmp.pData = (float64_t*)scratchArray; det = ref_detrm64(pSrc->pData,(float64_t*)scratchArray,pSrc->numCols); size = pSrc->numCols * pSrc->numCols; ref_cofact64(pSrc->pData,(float64_t*)scratchArray,(float64_t*)scratchArray + size,pSrc->numCols); ref_mat_trans_f64(&tmp,pDst); for(i=0;i<size;i++) { pDst->pData[i] /= det; } return ARM_MATH_SUCCESS; }
1,183
C
19.413793
98
0.677092
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_cmplx_mult.c
#include "ref.h" arm_status ref_mat_cmplx_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst) { uint32_t r,c,i,outR,outC,innerSize; float32_t sumR,sumI; float32_t a0,b0,c0,d0; outR = pSrcA->numRows; outC = pSrcB->numCols; innerSize = pSrcA->numCols; for(r=0;r<outR;r++) { for(c=0;c<outC;c++) { sumR = 0; sumI = 0; for(i=0;i<innerSize;i++) { a0 = pSrcA->pData[2*(r*innerSize + i) + 0]; b0 = pSrcA->pData[2*(r*innerSize + i) + 1]; c0 = pSrcB->pData[2*(i*outC + c) + 0]; d0 = pSrcB->pData[2*(i*outC + c) + 1]; sumR += a0 * c0 - b0 * d0; sumI += b0 * c0 + a0 * d0; } pDst->pData[2*(r*outC + c) + 0] = sumR; pDst->pData[2*(r*outC + c) + 1] = sumI; } } return ARM_MATH_SUCCESS; } arm_status ref_mat_cmplx_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst) { uint32_t r,c,i,outR,outC,innerSize; q63_t sumR,sumI; q31_t a0,b0,c0,d0; outR = pSrcA->numRows; outC = pSrcB->numCols; innerSize = pSrcA->numCols; for(r=0;r<outR;r++) { for(c=0;c<outC;c++) { sumR = 0; sumI = 0; for(i=0;i<innerSize;i++) { a0 = pSrcA->pData[2*(r*innerSize + i) + 0]; b0 = pSrcA->pData[2*(r*innerSize + i) + 1]; c0 = pSrcB->pData[2*(i*outC + c) + 0]; d0 = pSrcB->pData[2*(i*outC + c) + 1]; sumR += (q63_t)a0 * c0 - (q63_t)b0 * d0; sumI += (q63_t)b0 * c0 + (q63_t)a0 * d0; } pDst->pData[2*(r*outC + c) + 0] = ref_sat_q31(sumR >> 31); pDst->pData[2*(r*outC + c) + 1] = ref_sat_q31(sumI >> 31); } } return ARM_MATH_SUCCESS; } arm_status ref_mat_cmplx_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst) { uint32_t r,c,i,outR,outC,innerSize; q63_t sumR,sumI; q15_t a0,b0,c0,d0; outR = pSrcA->numRows; outC = pSrcB->numCols; innerSize = pSrcA->numCols; for(r=0;r<outR;r++) { for(c=0;c<outC;c++) { sumR = 0; sumI = 0; for(i=0;i<innerSize;i++) { a0 = pSrcA->pData[2*(r*innerSize + i) + 0]; b0 = pSrcA->pData[2*(r*innerSize + i) + 1]; c0 = pSrcB->pData[2*(i*outC + c) + 0]; d0 = pSrcB->pData[2*(i*outC + c) + 1]; sumR += (q31_t)a0 * c0 - (q31_t)b0 * d0; sumI += (q31_t)b0 * c0 + (q31_t)a0 * d0; } pDst->pData[2*(r*outC + c) + 0] = ref_sat_q15(sumR >> 15); pDst->pData[2*(r*outC + c) + 1] = ref_sat_q15(sumI >> 15); } } return ARM_MATH_SUCCESS; }
2,575
C
20.647059
61
0.54835
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_trans.c
#include "ref.h" arm_status ref_mat_trans_f64( const arm_matrix_instance_f64 * pSrc, arm_matrix_instance_f64 * pDst) { uint64_t r,c; uint64_t numR = pSrc->numRows; uint64_t numC = pSrc->numCols; for(r=0;r<numR;r++) { for(c=0;c<numC;c++) { pDst->pData[c*numR + r] = pSrc->pData[r*numC + c]; } } return ARM_MATH_SUCCESS; } arm_status ref_mat_trans_f32( const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst) { uint32_t r,c; uint32_t numR = pSrc->numRows; uint32_t numC = pSrc->numCols; for(r=0;r<numR;r++) { for(c=0;c<numC;c++) { pDst->pData[c*numR + r] = pSrc->pData[r*numC + c]; } } return ARM_MATH_SUCCESS; } arm_status ref_mat_trans_q31( const arm_matrix_instance_q31 * pSrc, arm_matrix_instance_q31 * pDst) { uint32_t r,c; uint32_t numR = pSrc->numRows; uint32_t numC = pSrc->numCols; for(r=0;r<numR;r++) { for(c=0;c<numC;c++) { pDst->pData[c*numR + r] = pSrc->pData[r*numC + c]; } } return ARM_MATH_SUCCESS; } arm_status ref_mat_trans_q15( const arm_matrix_instance_q15 * pSrc, arm_matrix_instance_q15 * pDst) { uint32_t r,c; uint32_t numR = pSrc->numRows; uint32_t numC = pSrc->numCols; for(r=0;r<numR;r++) { for(c=0;c<numC;c++) { pDst->pData[c*numR + r] = pSrc->pData[r*numC + c]; } } return ARM_MATH_SUCCESS; }
1,333
C
16.102564
53
0.611403
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_add.c
#include "ref.h" arm_status ref_mat_add_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = pSrcA->pData[i] + pSrcB->pData[i]; } return ARM_MATH_SUCCESS; } arm_status ref_mat_add_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = ref_sat_q31( (q63_t)pSrcA->pData[i] + pSrcB->pData[i]); } return ARM_MATH_SUCCESS; } arm_status ref_mat_add_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = ref_sat_q15( (q31_t)pSrcA->pData[i] + pSrcB->pData[i]); } return ARM_MATH_SUCCESS; }
1,511
C
24.627118
94
0.636003
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_mult.c
#include "ref.h" arm_status ref_mat_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst) { uint32_t r,c,i,outR,outC,innerSize; float32_t sum; outR = pSrcA->numRows; outC = pSrcB->numCols; innerSize = pSrcA->numCols; for(r=0;r<outR;r++) { for(c=0;c<outC;c++) { sum = 0; for(i=0;i<innerSize;i++) { sum += pSrcA->pData[r*innerSize + i] * pSrcB->pData[i*outC + c]; } pDst->pData[r*outC + c] = sum; } } return ARM_MATH_SUCCESS; } arm_status ref_mat_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst) { uint32_t r,c,i,outR,outC,innerSize; q63_t sum; outR = pSrcA->numRows; outC = pSrcB->numCols; innerSize = pSrcA->numCols; for(r=0;r<outR;r++) { for(c=0;c<outC;c++) { sum = 0; for(i=0;i<innerSize;i++) { sum += (q63_t)(pSrcA->pData[r*innerSize + i]) * pSrcB->pData[i*outC + c]; } pDst->pData[r*outC + c] = ref_sat_q31(sum >> 31); } } return ARM_MATH_SUCCESS; } arm_status ref_mat_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst) { uint32_t r,c,i,outR,outC,innerSize; q63_t sum; outR = pSrcA->numRows; outC = pSrcB->numCols; innerSize = pSrcA->numCols; for(r=0;r<outR;r++) { for(c=0;c<outC;c++) { sum = 0; for(i=0;i<innerSize;i++) { sum += (q31_t)(pSrcA->pData[r*innerSize + i]) * pSrcB->pData[i*outC + c]; } pDst->pData[r*outC + c] = ref_sat_q15(sum >> 15); } } return ARM_MATH_SUCCESS; }
1,655
C
17
77
0.594562
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/MatrixFunctions.c
#include "mat_add.c" #include "mat_cmplx_mult.c" #include "mat_inverse.c" #include "mat_mult.c" #include "mat_scale.c" #include "mat_sub.c" #include "mat_trans.c"
165
C
15.599998
27
0.684848
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_sub.c
#include "ref.h" arm_status ref_mat_sub_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = pSrcA->pData[i] - pSrcB->pData[i]; } return ARM_MATH_SUCCESS; } arm_status ref_mat_sub_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = ref_sat_q31( (q63_t)pSrcA->pData[i] - pSrcB->pData[i]); } return ARM_MATH_SUCCESS; } arm_status ref_mat_sub_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrcA->numRows * pSrcA->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = ref_sat_q15( (q31_t)pSrcA->pData[i] - pSrcB->pData[i]); } return ARM_MATH_SUCCESS; }
1,511
C
24.627118
94
0.636003
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/MatrixFunctions/mat_scale.c
#include "ref.h" arm_status ref_mat_scale_f32( const arm_matrix_instance_f32 * pSrc, float32_t scale, arm_matrix_instance_f32 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = pSrc->pData[i] * scale; } return ARM_MATH_SUCCESS; } arm_status ref_mat_scale_q31( const arm_matrix_instance_q31 * pSrc, q31_t scale, int32_t shift, arm_matrix_instance_q31 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ int32_t totShift = shift + 1; q31_t tmp; /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; for(i=0;i<numSamples;i++) { tmp = ((q63_t)pSrc->pData[i] * scale) >> 32; pDst->pData[i] = ref_sat_q31((q63_t)tmp << totShift ); } return ARM_MATH_SUCCESS; } arm_status ref_mat_scale_q15( const arm_matrix_instance_q15 * pSrc, q15_t scale, int32_t shift, arm_matrix_instance_q15 * pDst) { uint32_t i; uint32_t numSamples; /* total number of elements in the matrix */ int32_t totShift = 15 - shift; /* Total number of samples in the input matrix */ numSamples = (uint32_t) pSrc->numRows * pSrc->numCols; for(i=0;i<numSamples;i++) { pDst->pData[i] = ref_sat_q15( ((q31_t)pSrc->pData[i] * scale) >> totShift); } return ARM_MATH_SUCCESS; }
1,565
C
23.092307
94
0.623642
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/std.c
#include "ref.h" void ref_std_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult) { uint32_t i; float32_t sum=0, sumsq=0; if (blockSize == 1) { *pResult = 0; return; } for(i=0;i<blockSize;i++) { sum += pSrc[i]; sumsq += pSrc[i] * pSrc[i]; } *pResult = sqrtf((sumsq - sum * sum / (float32_t)blockSize) / ((float32_t)blockSize - 1)); } void ref_std_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult) { uint32_t i; q63_t sum=0, sumsq=0; q31_t in; if (blockSize == 1) { *pResult = 0; return; } for(i=0;i<blockSize;i++) { in = pSrc[i] >> 8; sum += in; sumsq += (q63_t)in * in; } sumsq /= (q63_t)(blockSize - 1); sum = sum * sum / (q63_t)(blockSize * (blockSize - 1)); *pResult = (q31_t)(sqrtf((float)( (sumsq - sum) >> 15) / 2147483648.0f ) * 2147483648.0f); } void ref_std_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult) { uint32_t i; q31_t sum=0; q63_t sumsq=0; if (blockSize == 1) { *pResult = 0; return; } for(i=0;i<blockSize;i++) { sum += pSrc[i]; sumsq += (q63_t)pSrc[i] * pSrc[i]; } sumsq /= (q63_t)(blockSize - 1); sum = (q31_t)((q63_t)sum * sum / (q63_t)(blockSize * (blockSize - 1))); *pResult = (q15_t)(sqrtf((float)ref_sat_q15( (sumsq - sum) >> 15) / 32768.0f ) * 32768.0f); }
1,308
C
16.453333
92
0.551988
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/rms.c
#include "ref.h" void ref_rms_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult) { uint32_t i; float32_t sumsq=0; for(i=0;i<blockSize;i++) { sumsq += pSrc[i] * pSrc[i]; } *pResult = sqrtf(sumsq / (float32_t)blockSize); } void ref_rms_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult) { uint32_t i; uint64_t sumsq = 0; /* accumulator (can get never negative. changed type from q63 to uint64 */ q63_t tmp1; q31_t tmp2; float help_float; for(i=0;i<blockSize;i++) { sumsq += (q63_t)pSrc[i] * pSrc[i]; } tmp1 = (sumsq / (q63_t)blockSize) >> 31; tmp2 = ref_sat_q31(tmp1); /* GCC M0 problem: __aeabi_f2iz(QNAN) returns not 0 */ help_float = (sqrtf((float)tmp2 / 2147483648.0f) * 2147483648.0f); /* Checking for a NAN value in help_float */ if (((*((int *)(&help_float))) & 0x7FC00000) == 0x7FC00000) { help_float = 0; } *pResult = (q31_t)(help_float); // *pResult = (q31_t)(sqrtf((float)tmp2 / 2147483648.0f) * 2147483648.0f); } void ref_rms_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult) { uint32_t i; q63_t sumsq=0; q31_t tmp1; q15_t tmp2; for(i=0;i<blockSize;i++) { sumsq += (q63_t)pSrc[i] * pSrc[i]; } tmp1 = (sumsq / (q63_t)blockSize) >> 15; tmp2 = ref_sat_q15(tmp1); *pResult = (q15_t)(sqrtf((float)tmp2 / 32768.0f) * 32768.0f); }
1,361
C
19.636363
110
0.594416
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/min.c
#include "ref.h" void ref_min_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; float32_t min=FLT_MAX; for(i=0;i<blockSize;i++) { if (min > pSrc[i]) { min = pSrc[i]; ind = i; } } *pResult = min; *pIndex = ind; } void ref_min_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; q31_t min=INT_MAX; for(i=0;i<blockSize;i++) { if (min > pSrc[i]) { min = pSrc[i]; ind = i; } } *pResult = min; *pIndex = ind; } void ref_min_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; q15_t min=SHRT_MAX; for(i=0;i<blockSize;i++) { if (min > pSrc[i]) { min = pSrc[i]; ind = i; } } *pResult = min; *pIndex = ind; } void ref_min_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; q7_t min=SCHAR_MAX; for(i=0;i<blockSize;i++) { if (min > pSrc[i]) { min = pSrc[i]; ind = i; } } *pResult = min; *pIndex = ind; }
1,096
C
11.755814
25
0.541971
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/power.c
#include "ref.h" void ref_power_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult) { uint32_t i; float32_t sumsq=0; for(i=0;i<blockSize;i++) { sumsq += pSrc[i] * pSrc[i]; } *pResult = sumsq; } void ref_power_q31( q31_t * pSrc, uint32_t blockSize, q63_t * pResult) { uint32_t i; q63_t sumsq=0; for(i=0;i<blockSize;i++) { sumsq += ((q63_t)pSrc[i] * pSrc[i]) >> 14; } *pResult = sumsq; } void ref_power_q15( q15_t * pSrc, uint32_t blockSize, q63_t * pResult) { uint32_t i; q63_t sumsq=0; for(i=0;i<blockSize;i++) { sumsq += (q63_t)pSrc[i] * pSrc[i]; } *pResult = sumsq; } void ref_power_q7( q7_t * pSrc, uint32_t blockSize, q31_t * pResult) { uint32_t i; q31_t sumsq=0; for(i=0;i<blockSize;i++) { sumsq += (q31_t)pSrc[i] * pSrc[i]; } *pResult = sumsq; }
836
C
12.5
45
0.572967
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/StatisticsFunctions.c
#include "max.c" #include "mean.c" #include "min.c" #include "power.c" #include "rms.c" #include "std.c" #include "var.c"
123
C
12.777776
18
0.650406
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/mean.c
#include "ref.h" void ref_mean_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult) { uint32_t i; float32_t sum=0; for(i=0;i<blockSize;i++) { sum += pSrc[i]; } *pResult = sum / (float32_t)blockSize; } void ref_mean_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult) { uint32_t i; q63_t sum=0; for(i=0;i<blockSize;i++) { sum += pSrc[i]; } *pResult = (q31_t) (sum / (int32_t) blockSize); } void ref_mean_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult) { uint32_t i; q31_t sum=0; for(i=0;i<blockSize;i++) { sum += pSrc[i]; } *pResult = (q15_t) (sum / (int32_t) blockSize); } void ref_mean_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult) { uint32_t i; q31_t sum=0; for(i=0;i<blockSize;i++) { sum += pSrc[i]; } *pResult = (q7_t) (sum / (int32_t) blockSize); }
856
C
12.82258
48
0.571262
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/max.c
#include "ref.h" void ref_max_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; float32_t max=-FLT_MAX; for(i=0;i<blockSize;i++) { if (max < pSrc[i]) { max = pSrc[i]; ind = i; } } *pResult = max; *pIndex = ind; } void ref_max_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; q31_t max=INT_MIN; for(i=0;i<blockSize;i++) { if (max < pSrc[i]) { max = pSrc[i]; ind = i; } } *pResult = max; *pIndex = ind; } void ref_max_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; q15_t max=SHRT_MIN; for(i=0;i<blockSize;i++) { if (max < pSrc[i]) { max = pSrc[i]; ind = i; } } *pResult = max; *pIndex = ind; } void ref_max_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex) { uint32_t i, ind=0; q7_t max=SCHAR_MIN; for(i=0;i<blockSize;i++) { if (max < pSrc[i]) { max = pSrc[i]; ind = i; } } *pResult = max; *pIndex = ind; }
1,097
C
11.767442
25
0.541477
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/StatisticsFunctions/var.c
#include "ref.h" void ref_var_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult) { uint32_t i; float32_t sum=0, sumsq=0; if (blockSize == 1) { *pResult = 0; return; } for(i=0;i<blockSize;i++) { sum += pSrc[i]; sumsq += pSrc[i] * pSrc[i]; } *pResult = (sumsq - sum * sum / (float32_t)blockSize) / ((float32_t)blockSize - 1); } void ref_var_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult) { uint32_t i; q63_t sum=0, sumsq=0; q31_t in; if (blockSize == 1) { *pResult = 0; return; } for(i=0;i<blockSize;i++) { in = pSrc[i] >> 8; sum += in; sumsq += (q63_t)in * in; } *pResult = (sumsq - sum * sum / (q31_t)blockSize) / ((q31_t)blockSize - 1) >> 15; } void ref_var_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult) { uint32_t i; q31_t sum=0; q63_t sumsq=0; if (blockSize == 1) { *pResult = 0; return; } for(i=0;i<blockSize;i++) { sum += pSrc[i]; sumsq += (q63_t)pSrc[i] * pSrc[i]; } *pResult = (q31_t)((sumsq - (q63_t)sum * sum / (q63_t)blockSize) / ((q63_t)blockSize - 1)) >> 15; }
1,100
C
14.507042
98
0.545455
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/biquad.c
#include "ref.h" void ref_biquad_cascade_df2T_f32( const arm_biquad_cascade_df2T_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pIn = pSrc; /* source pointer */ float32_t *pOut = pDst; /* destination pointer */ float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */ float32_t acc; /* accumulator */ float32_t b0, b1, b2, a1, a2; /* Filter coefficients */ float32_t Xn; /* temporary input */ float32_t d1, d2; /* state variables */ uint32_t sample, stage = S->numStages; /* loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /*Reading the state values */ d1 = pState[0]; d2 = pState[1]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* y[n] = b0 * x[n] + d1 */ acc = (b0 * Xn) + d1; /* Store the result in the accumulator in the destination buffer. */ *pOut++ = acc; /* Every time after the output is computed state should be updated. */ /* d1 = b1 * x[n] + a1 * y[n] + d2 */ d1 = (b1 * Xn + a1 * acc) + d2; /* d2 = b2 * x[n] + a2 * y[n] */ d2 = (b2 * Xn) + (a2 * acc); /* decrement the loop counter */ sample--; } /* Store the updated state variables back into the state array */ *pState++ = d1; *pState++ = d2; /* The current stage input is given as the output to the next stage */ pIn = pDst; /*Reset the output working pointer */ pOut = pDst; /* decrement the loop counter */ stage--; } while (stage > 0U); } void ref_biquad_cascade_stereo_df2T_f32( const arm_biquad_cascade_stereo_df2T_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pIn = pSrc; /* source pointer */ float32_t *pOut = pDst; /* destination pointer */ float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */ float32_t acc1a, acc1b; /* accumulator */ float32_t b0, b1, b2, a1, a2; /* Filter coefficients */ float32_t Xn1a, Xn1b; /* temporary input */ float32_t d1a, d2a, d1b, d2b; /* state variables */ uint32_t sample, stage = S->numStages; /* loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /*Reading the state values */ d1a = pState[0]; d2a = pState[1]; d1b = pState[2]; d2b = pState[3]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn1a = *pIn++; //Channel a Xn1b = *pIn++; //Channel b /* y[n] = b0 * x[n] + d1 */ acc1a = (b0 * Xn1a) + d1a; acc1b = (b0 * Xn1b) + d1b; /* Store the result in the accumulator in the destination buffer. */ *pOut++ = acc1a; *pOut++ = acc1b; /* Every time after the output is computed state should be updated. */ /* d1 = b1 * x[n] + a1 * y[n] + d2 */ d1a = ((b1 * Xn1a) + (a1 * acc1a)) + d2a; d1b = ((b1 * Xn1b) + (a1 * acc1b)) + d2b; /* d2 = b2 * x[n] + a2 * y[n] */ d2a = (b2 * Xn1a) + (a2 * acc1a); d2b = (b2 * Xn1b) + (a2 * acc1b); /* decrement the loop counter */ sample--; } /* Store the updated state variables back into the state array */ *pState++ = d1a; *pState++ = d2a; *pState++ = d1b; *pState++ = d2b; /* The current stage input is given as the output to the next stage */ pIn = pDst; /*Reset the output working pointer */ pOut = pDst; /* decrement the loop counter */ stage--; } while (stage > 0U); } void ref_biquad_cascade_df2T_f64( const arm_biquad_cascade_df2T_instance_f64 * S, float64_t * pSrc, float64_t * pDst, uint32_t blockSize) { float64_t *pIn = pSrc; /* source pointer */ float64_t *pOut = pDst; /* destination pointer */ float64_t *pState = S->pState; /* State pointer */ float64_t *pCoeffs = S->pCoeffs; /* coefficient pointer */ float64_t acc; /* accumulator */ float64_t b0, b1, b2, a1, a2; /* Filter coefficients */ float64_t Xn; /* temporary input */ float64_t d1, d2; /* state variables */ uint32_t sample, stage = S->numStages; /* loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /*Reading the state values */ d1 = pState[0]; d2 = pState[1]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* y[n] = b0 * x[n] + d1 */ acc = (b0 * Xn) + d1; /* Store the result in the accumulator in the destination buffer. */ *pOut++ = acc; /* Every time after the output is computed state should be updated. */ /* d1 = b1 * x[n] + a1 * y[n] + d2 */ d1 = (b1 * Xn + a1 * acc) + d2; /* d2 = b2 * x[n] + a2 * y[n] */ d2 = (b2 * Xn) + (a2 * acc); /* decrement the loop counter */ sample--; } /* Store the updated state variables back into the state array */ *pState++ = d1; *pState++ = d2; /* The current stage input is given as the output to the next stage */ pIn = pDst; /*Reset the output working pointer */ pOut = pDst; /* decrement the loop counter */ stage--; } while (stage > 0U); } void ref_biquad_cascade_df1_f32( const arm_biquad_casd_df1_inst_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pIn = pSrc; /* source pointer */ float32_t *pOut = pDst; /* destination pointer */ float32_t *pState = S->pState; /* pState pointer */ const float32_t *pCoeffs = S->pCoeffs; /* coefficient pointer */ float32_t acc; /* Simulates the accumulator */ float32_t b0, b1, b2, a1, a2; /* Filter coefficients */ float32_t Xn1, Xn2, Yn1, Yn2; /* Filter pState variables */ float32_t Xn; /* temporary input */ uint32_t sample, stage = S->numStages; /* loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the pState values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; /* The variables acc holds the output value that is computed: * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ acc = (b0 * Xn) + (b1 * Xn1) + (b2 * Xn2) + (a1 * Yn1) + (a2 * Yn2); /* Store the result in the accumulator in the destination buffer. */ *pOut++ = acc; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = acc; /* decrement the loop counter */ sample--; } /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent numStages occur in-place in the output buffer */ pIn = pDst; /* Reset the output pointer */ pOut = pDst; /* decrement the loop counter */ stage--; } while (stage > 0U); } void ref_biquad_cas_df1_32x64_q31( const arm_biquad_cas_df1_32x64_ins_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pIn = pSrc; /* input pointer initialization */ q31_t *pOut = pDst; /* output pointer initialization */ q63_t *pState = S->pState; /* state pointer initialization */ const q31_t *pCoeffs = S->pCoeffs; /* coeff pointer initialization */ q63_t acc; /* accumulator */ q31_t Xn1, Xn2; /* Input Filter state variables */ q63_t Yn1, Yn2; /* Output Filter state variables */ q31_t b0, b1, b2, a1, a2; /* Filter coefficients */ q31_t Xn; /* temporary input */ int32_t shift = (int32_t) S->postShift + 1; /* Shift to be applied to the output */ uint32_t sample, stage = S->numStages; /* loop counters */ q31_t acc_l, acc_h; /* temporary output */ uint32_t uShift = ((uint32_t) S->postShift + 1U); uint32_t lShift = 32U - uShift; /* Shift to be applied to the output */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the state values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ acc = (q63_t)Xn*b0 + (q63_t)Xn1*b1 + (q63_t)Xn2*b2; /* acc += a1 * y[n-1] */ acc += mult32x64(Yn1, a1); /* acc += a2 * y[n-2] */ acc += mult32x64(Yn2, a2); /* Every time after the output is computed state should be updated. */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; /* The result is converted to 1.63, Yn1 variable is reused */ Yn1 = acc << shift; /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ acc_h = (uint32_t) acc_l >> lShift | acc_h << uShift; /* Store the output in the destination buffer in 1.31 format. */ *pOut++ = acc_h; /* decrement the loop counter */ sample--; } /* The first stage output is given as input to the second stage. */ pIn = pDst; /* Reset to destination buffer working pointer */ pOut = pDst; /* Store the updated state variables back into the pState array */ *pState++ = (q63_t) Xn1; *pState++ = (q63_t) Xn2; *pState++ = Yn1; *pState++ = Yn2; } while (--stage); } void ref_biquad_cascade_df1_q31( const arm_biquad_casd_df1_inst_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q63_t acc; /* accumulator */ uint32_t uShift = ((uint32_t) S->postShift + 1U); uint32_t lShift = 32U - uShift; /* Shift to be applied to the output */ q31_t *pIn = pSrc; /* input pointer initialization */ q31_t *pOut = pDst; /* output pointer initialization */ q31_t *pState = S->pState; /* pState pointer initialization */ const q31_t *pCoeffs = S->pCoeffs; /* coeff pointer initialization */ q31_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ q31_t b0, b1, b2, a1, a2; /* Filter coefficients */ q31_t Xn; /* temporary input */ uint32_t sample, stage = S->numStages; /* loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the state values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; /* The variables acc holds the output value that is computed: * acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ /* acc = b0 * x[n] */ acc = (q63_t) b0 *Xn; /* acc += b1 * x[n-1] */ acc += (q63_t) b1 *Xn1; /* acc += b[2] * x[n-2] */ acc += (q63_t) b2 *Xn2; /* acc += a1 * y[n-1] */ acc += (q63_t) a1 *Yn1; /* acc += a2 * y[n-2] */ acc += (q63_t) a2 *Yn2; /* The result is converted to 1.31 */ acc = acc >> lShift; /* Every time after the output is computed state should be updated. */ /* The states should be updated as: */ /* Xn2 = Xn1 */ /* Xn1 = Xn */ /* Yn2 = Yn1 */ /* Yn1 = acc */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = (q31_t) acc; /* Store the output in the destination buffer. */ *pOut++ = (q31_t) acc; /* decrement the loop counter */ sample--; } /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent stages occur in-place in the output buffer */ pIn = pDst; /* Reset to destination pointer */ pOut = pDst; /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; } while (--stage); } void ref_biquad_cascade_df1_fast_q31( const arm_biquad_casd_df1_inst_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t acc = 0; /* accumulator */ q31_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ q31_t b0, b1, b2, a1, a2; /* Filter coefficients */ q31_t *pIn = pSrc; /* input pointer initialization */ q31_t *pOut = pDst; /* output pointer initialization */ q31_t *pState = S->pState; /* pState pointer initialization */ const q31_t *pCoeffs = S->pCoeffs; /* coeff pointer initialization */ q31_t Xn; /* temporary input */ int32_t shift = (int32_t) S->postShift + 1; /* Shift to be applied to the output */ uint32_t sample, stage = S->numStages; /* loop counters */ do { /* Reading the coefficients */ b0 = *pCoeffs++; b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the state values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ mult_32x32_keep32_R(acc, b0, Xn); multAcc_32x32_keep32_R(acc, b1, Xn1); multAcc_32x32_keep32_R(acc, b2, Xn2); multAcc_32x32_keep32_R(acc, a1, Yn1); multAcc_32x32_keep32_R(acc, a2, Yn2); /* The result is converted to 1.31 */ acc <<= shift; /* Every time after the output is computed state should be updated. */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = acc; /* Store the output in the destination buffer. */ *pOut++ = acc; /* decrement the loop counter */ sample--; } /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent stages occur in-place in the output buffer */ pIn = pDst; /* Reset to destination pointer */ pOut = pDst; /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; } while (--stage); } void ref_biquad_cascade_df1_fast_q15( const arm_biquad_casd_df1_inst_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pIn = pSrc; /* Source pointer */ q15_t *pOut = pDst; /* Destination pointer */ q15_t b0, b1, b2, a1, a2; /* Filter coefficients */ q15_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ q15_t Xn; /* temporary input */ q31_t acc; /* Accumulator */ int32_t shift = (15 - (int32_t) S->postShift); /* Post shift */ q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ uint32_t sample, stage = (uint32_t) S->numStages; /* Stage loop counter */ do { /* Reading the coefficients */ b0 = *pCoeffs++; pCoeffs++; // skip the 0 coefficient b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the state values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ acc = (q31_t)b0*Xn + (q31_t)b1*Xn1 + (q31_t)b2*Xn2 + (q31_t)a1*Yn1 + (q31_t)a2*Yn2; /* The result is converted to 1.15 */ acc = ref_sat_q15(acc >> shift); /* Every time after the output is computed state should be updated. */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = (q15_t) acc; /* Store the output in the destination buffer. */ *pOut++ = (q15_t) acc; /* decrement the loop counter */ sample--; } /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent stages occur in-place in the output buffer */ pIn = pDst; /* Reset to destination pointer */ pOut = pDst; /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; } while (--stage); } void ref_biquad_cascade_df1_q15( const arm_biquad_casd_df1_inst_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pIn = pSrc; /* Source pointer */ q15_t *pOut = pDst; /* Destination pointer */ q15_t b0, b1, b2, a1, a2; /* Filter coefficients */ q15_t Xn1, Xn2, Yn1, Yn2; /* Filter state variables */ q15_t Xn; /* temporary input */ q63_t acc; /* Accumulator */ int32_t shift = (15 - (int32_t) S->postShift); /* Post shift */ q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ uint32_t sample, stage = (uint32_t) S->numStages; /* Stage loop counter */ do { /* Reading the coefficients */ b0 = *pCoeffs++; pCoeffs++; // skip the 0 coefficient b1 = *pCoeffs++; b2 = *pCoeffs++; a1 = *pCoeffs++; a2 = *pCoeffs++; /* Reading the state values */ Xn1 = pState[0]; Xn2 = pState[1]; Yn1 = pState[2]; Yn2 = pState[3]; sample = blockSize; while (sample > 0U) { /* Read the input */ Xn = *pIn++; /* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */ acc = (q31_t)b0*Xn + (q31_t)b1*Xn1 + (q31_t)b2*Xn2 + (q31_t)a1*Yn1 + (q31_t)a2*Yn2; /* The result is converted to 1.15 */ acc = ref_sat_q15(acc >> shift); /* Every time after the output is computed state should be updated. */ Xn2 = Xn1; Xn1 = Xn; Yn2 = Yn1; Yn1 = (q15_t) acc; /* Store the output in the destination buffer. */ *pOut++ = (q15_t) acc; /* decrement the loop counter */ sample--; } /* The first stage goes from the input buffer to the output buffer. */ /* Subsequent stages occur in-place in the output buffer */ pIn = pDst; /* Reset to destination pointer */ pOut = pDst; /* Store the updated state variables back into the pState array */ *pState++ = Xn1; *pState++ = Xn2; *pState++ = Yn1; *pState++ = Yn2; } while (--stage); }
23,118
C
31.379552
110
0.452461
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/fir.c
#include "ref.h" void ref_fir_f32( const arm_fir_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i; /* Loop counters */ float32_t acc; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); while (blockSize > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulates */ acc += pState[i] * pCoeffs[i]; } /* The result is store in the destination buffer. */ *pDst++ = acc; /* Advance state pointer by 1 for the next sample */ pState++; blockSize--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the starting of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy data */ for(i=0;i<numTaps-1;i++) { pStateCurnt[i] = pState[i]; } } void ref_fir_q31( const arm_fir_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i; /* Loop counter */ q63_t acc; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); while (blockSize > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulates */ acc += (q63_t)pState[i] * pCoeffs[i]; } /* The result is store in the destination buffer. */ *pDst++ = (q31_t)(acc >> 31); /* Advance state pointer by 1 for the next sample */ pState++; blockSize--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the starting of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy data */ for(i=0;i<numTaps-1;i++) { pStateCurnt[i] = pState[i]; } } void ref_fir_fast_q31( const arm_fir_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i; /* Loop counter */ q31_t acc; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); while (blockSize > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulates */ acc = (q31_t) (((((q63_t) acc) << 32) + ((q63_t) pState[i] * pCoeffs[i]) + 0x80000000LL ) >> 32); } /* The result is store in the destination buffer. */ *pDst++ = (q31_t)(acc << 1); /* Advance state pointer by 1 for the next sample */ pState++; blockSize--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the starting of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy data */ for(i=0;i<numTaps-1;i++) { pStateCurnt[i] = pState[i]; } } void ref_fir_q15( const arm_fir_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i; /* Loop counter */ q63_t acc; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); while (blockSize > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulates */ acc += (q31_t)pState[i] * pCoeffs[i]; } /* The result is store in the destination buffer. */ *pDst++ = ref_sat_q15(acc >> 15); /* Advance state pointer by 1 for the next sample */ pState++; blockSize--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the starting of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy data */ for(i=0;i<numTaps;i++) { pStateCurnt[i] = pState[i]; } } void ref_fir_fast_q15( const arm_fir_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i; /* Loop counter */ q31_t acc; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); while (blockSize > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulates */ acc += (q31_t)pState[i] * pCoeffs[i]; } /* The result is store in the destination buffer. */ *pDst++ = ref_sat_q15(acc >> 15); /* Advance state pointer by 1 for the next sample */ pState++; blockSize--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the starting of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy data */ for(i=0;i<numTaps-1;i++) { pStateCurnt[i] = pState[i]; } } void ref_fir_q7( const arm_fir_instance_q7 * S, q7_t * pSrc, q7_t * pDst, uint32_t blockSize) { q7_t *pState = S->pState; /* State pointer */ const q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q7_t *pStateCurnt; /* Points to the current sample of the state */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i; /* Loop counter */ q31_t acc; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); while (blockSize > 0U) { /* Copy one sample at a time into state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ acc = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulates */ acc += (q31_t)pState[i] * pCoeffs[i]; } /* The result is store in the destination buffer. */ *pDst++ = ref_sat_q7(acc >> 7); /* Advance state pointer by 1 for the next sample */ pState++; blockSize--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the starting of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy data */ for(i=0;i<numTaps-1;i++) { pStateCurnt[i] = pState[i]; } }
10,008
C
29.702454
104
0.553857
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/fir_decimate.c
#include "ref.h" void ref_fir_decimate_f32( const arm_fir_decimate_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t sum0; /* Accumulator */ float32_t x0, c0; /* Temporary variables to hold state and coefficient values */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i, blkCnt; /* Loop counters */ /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + numTaps - 1U; /* Total number of output samples to be computed */ blkCnt = blockSize / S->M; while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCurnt++ = *pSrc++; } while (--i); /* Set accumulator to zero */ sum0 = 0.0f; for(i=0;i<numTaps;i++) { /* Read coefficients */ c0 = pCoeffs[i]; /* Fetch 1 state variable */ x0 = pState[i]; /* Perform the multiply-accumulate */ sum0 += x0 * c0; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState += S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = sum0; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; /* Copy numTaps number of values */ i = numTaps - 1U; /* copy data */ while (i > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ i--; } } void ref_fir_decimate_q31( const arm_fir_decimate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ q63_t sum0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of taps */ uint32_t i, blkCnt; /* Loop counters */ /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + numTaps - 1U; /* Total number of output samples to be computed */ blkCnt = blockSize / S->M; while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCurnt++ = *pSrc++; } while (--i); /* Set accumulator to zero */ sum0 = 0; for(i=0;i<numTaps;i++) { /* Read coefficients */ c0 = pCoeffs[i]; /* Fetch 1 state variable */ x0 = pState[i]; /* Perform the multiply-accumulate */ sum0 += (q63_t)x0 * c0; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t) (sum0 >> 31); /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; i = numTaps - 1U; /* copy data */ while (i > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ i--; } } void ref_fir_decimate_fast_q31( const arm_fir_decimate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ q31_t sum0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of taps */ uint32_t i, blkCnt; /* Loop counters */ /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + numTaps - 1U; /* Total number of output samples to be computed */ blkCnt = blockSize / S->M; while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCurnt++ = *pSrc++; } while (--i); /* Set accumulator to zero */ sum0 = 0; for(i=0;i<numTaps;i++) { /* Read coefficients */ c0 = pCoeffs[i]; /* Fetch 1 state variable */ x0 = pState[i]; /* Perform the multiply-accumulate */ sum0 = (q31_t)((((q63_t) sum0 << 32) + ((q63_t) x0 * c0)) >> 32); } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t) (sum0 << 1); /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; i = numTaps - 1U; /* copy data */ while (i > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ i--; } } void ref_fir_decimate_q15( const arm_fir_decimate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ q63_t sum0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of taps */ uint32_t i, blkCnt; /* Loop counters */ /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + numTaps - 1U; /* Total number of output samples to be computed */ blkCnt = blockSize / S->M; while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCurnt++ = *pSrc++; } while (--i); /* Set accumulator to zero */ sum0 = 0; for(i=0;i<numTaps;i++) { /* Read coefficients */ c0 = pCoeffs[i]; /* Fetch 1 state variable */ x0 = pState[i]; /* Perform the multiply-accumulate */ sum0 += (q31_t)x0 * c0; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = ref_sat_q15(sum0 >> 15); /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; i = numTaps - 1U; /* copy data */ while (i > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ i--; } } void ref_fir_decimate_fast_q15( const arm_fir_decimate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q15_t x0, c0; /* Temporary variables to hold state and coefficient values */ q31_t sum0; /* Accumulator */ uint32_t numTaps = S->numTaps; /* Number of taps */ uint32_t i, blkCnt; /* Loop counters */ /* S->pState buffer contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + numTaps - 1U; /* Total number of output samples to be computed */ blkCnt = blockSize / S->M; while (blkCnt > 0U) { /* Copy decimation factor number of new input samples into the state buffer */ i = S->M; do { *pStateCurnt++ = *pSrc++; } while (--i); /* Set accumulator to zero */ sum0 = 0; for(i=0;i<numTaps;i++) { /* Read coefficients */ c0 = pCoeffs[i]; /* Fetch 1 state variable */ x0 = pState[i]; /* Perform the multiply-accumulate */ sum0 += x0 * c0; } /* Advance the state pointer by the decimation factor * to process the next group of decimation factor number samples */ pState = pState + S->M; /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = ref_sat_q15(sum0 >> 15); /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last numTaps - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; i = numTaps - 1U; /* copy data */ while (i > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ i--; } }
11,176
C
27.881137
117
0.552881
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/correlate.c
#include "ref.h" void ref_correlate_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst) { float32_t *pIn1 = pSrcA; /* inputA pointer */ float32_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ float32_t sum; /* Accumulator */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* The algorithm implementation is based on the lengths of the inputs. * srcB is always made to slide across srcA. * So srcBLen is always considered as shorter or equal to srcALen * But CORR(x, y) is reverse of CORR(y, x) * So, when srcBLen > srcALen, output pointer is made to point to the end of the output buffer * and a variable, inv is set to 1 * If lengths are not equal then zero pad has to be done to make the two * inputs of same length. But to improve the performance, we include zeroes * in the output instead of zero padding either of the the inputs * If srcALen > srcBLen, (srcALen - srcBLen) zeroes has to included in the * starting of the output buffer * If srcALen < srcBLen, (srcALen - srcBLen) zeroes has to included in the * ending of the output buffer * Once the zero padding is done the remaining of the output is calcualted * using convolution but with the shorter signal time shifted. */ /* Calculate the length of the remaining sequence */ tot = srcALen + srcBLen - 2U; if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ /* Initialise the pointer after zero padding */ pDst += srcALen - srcBLen; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + srcALen - 1U; /* Initialisation of the pointer after zero padding */ pDst += tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate convolution for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0.0f; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += pIn1[j] * pIn2[-((int32_t)i - j)]; } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = sum; else *pDst++ = sum; } } void ref_correlate_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst) { q31_t *pIn1 = pSrcA; /* inputA pointer */ q31_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ q63_t sum; /* Accumulators */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* Calculate the length of the remaining sequence */ tot = ((srcALen + srcBLen) - 2U); if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ j = srcALen - srcBLen; /* Initialise the pointer after zero padding */ pDst += j; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + (srcALen - 1U); /* Initialisation of the pointer after zero padding */ pDst = pDst + tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate correlation for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to correlation equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((((i - j) < srcBLen) && (j < srcALen))) { /* z[i] += x[i-j] * y[j] */ sum += ((q63_t) pIn1[j] * pIn2[-((int32_t) i - j)]); } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = (q31_t)(sum >> 31U); else *pDst++ = (q31_t)(sum >> 31U); } } void ref_correlate_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst) { q31_t *pIn1 = pSrcA; /* inputA pointer */ q31_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ q63_t sum; /* Accumulators */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* Calculate the length of the remaining sequence */ tot = ((srcALen + srcBLen) - 2U); if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ j = srcALen - srcBLen; /* Initialise the pointer after zero padding */ pDst += j; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + (srcALen - 1U); /* Initialisation of the pointer after zero padding */ pDst = pDst + tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate correlation for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to correlation equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((((i - j) < srcBLen) && (j < srcALen))) { /* z[i] += x[i-j] * y[j] */ sum = (q31_t) ((((q63_t) sum << 32) + ((q63_t) pIn1[j] * pIn2[-((int32_t) i - j)])) >> 32); } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = (q31_t)(sum << 1U); else *pDst++ = (q31_t)(sum << 1U); } } void ref_correlate_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst) { q15_t *pIn1 = pSrcA; /* inputA pointer */ q15_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ q63_t sum; /* Accumulators */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* Calculate the length of the remaining sequence */ tot = ((srcALen + srcBLen) - 2U); if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ j = srcALen - srcBLen; /* Initialise the pointer after zero padding */ pDst += j; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + (srcALen - 1U); /* Initialisation of the pointer after zero padding */ pDst = pDst + tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate convolution for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((((i - j) < srcBLen) && (j < srcALen))) { /* z[i] += x[i-j] * y[j] */ sum += ((q31_t) pIn1[j] * pIn2[-((int32_t) i - j)]); } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = (q15_t) ref_sat_q15(sum >> 15U); else *pDst++ = (q15_t) ref_sat_q15(sum >> 15U); } } void ref_correlate_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst) { q15_t *pIn1 = pSrcA; /* inputA pointer */ q15_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ q63_t sum; /* Accumulators */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* Calculate the length of the remaining sequence */ tot = ((srcALen + srcBLen) - 2U); if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ j = srcALen - srcBLen; /* Initialise the pointer after zero padding */ pDst += j; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + (srcALen - 1U); /* Initialisation of the pointer after zero padding */ pDst = pDst + tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate convolution for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((((i - j) < srcBLen) && (j < srcALen))) { /* z[i] += x[i-j] * y[j] */ sum += ((q31_t) pIn1[j] * pIn2[-((int32_t) i - j)]); } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = (q15_t)(sum >> 15U); else *pDst++ = (q15_t)(sum >> 15U); } } void ref_correlate_fast_opt_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch) { q15_t *pIn1 = pSrcA; /* inputA pointer */ q15_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ q31_t sum; /* Accumulators */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* Calculate the length of the remaining sequence */ tot = ((srcALen + srcBLen) - 2U); if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ j = srcALen - srcBLen; /* Initialise the pointer after zero padding */ pDst += j; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + (srcALen - 1U); /* Initialisation of the pointer after zero padding */ pDst = pDst + tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate convolution for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((((i - j) < srcBLen) && (j < srcALen))) { /* z[i] += x[i-j] * y[j] */ sum += ((q31_t) pIn1[j] * pIn2[-((int32_t) i - j)]); } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = (q15_t) ref_sat_q15(sum >> 15U); else *pDst++ = (q15_t) ref_sat_q15(sum >> 15U); } } void ref_correlate_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst) { q7_t *pIn1 = pSrcA; /* inputA pointer */ q7_t *pIn2 = pSrcB + (srcBLen - 1U); /* inputB pointer */ q31_t sum; /* Accumulator */ uint32_t i = 0U, j; /* loop counters */ uint32_t inv = 0U; /* Reverse order flag */ uint32_t tot = 0U; /* Length */ /* Calculate the length of the remaining sequence */ tot = ((srcALen + srcBLen) - 2U); if (srcALen > srcBLen) { /* Calculating the number of zeros to be padded to the output */ j = srcALen - srcBLen; /* Initialise the pointer after zero padding */ pDst += j; } else if (srcALen < srcBLen) { /* Initialization to inputB pointer */ pIn1 = pSrcB; /* Initialization to the end of inputA pointer */ pIn2 = pSrcA + (srcALen - 1U); /* Initialisation of the pointer after zero padding */ pDst = pDst + tot; /* Swapping the lengths */ j = srcALen; srcALen = srcBLen; srcBLen = j; /* Setting the reverse flag */ inv = 1; } /* Loop to calculate convolution for output length number of times */ for (i = 0U; i <= tot; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0U; j <= i; j++) { /* Check the array limitations */ if ((((i - j) < srcBLen) && (j < srcALen))) { /* z[i] += x[i-j] * y[j] */ sum += ((q15_t) pIn1[j] * pIn2[-((int32_t) i - j)]); } } /* Store the output in the destination buffer */ if (inv == 1) *pDst-- = (q7_t) __SSAT((sum >> 7U), 8U); else *pDst++ = (q7_t) __SSAT((sum >> 7U), 8U); } }
14,617
C
27.439689
97
0.515427
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/fir_interpolate.c
#include "ref.h" void ref_fir_interpolate_f32( const arm_fir_interpolate_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t *ptr1; /* Temporary pointer for state buffer */ const float32_t *ptr2; /* Temporary pointer for coefficient buffer */ float32_t sum; /* Accumulator */ uint32_t i, blkCnt; /* Loop counters */ uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */ /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + phaseLen - 1; /* Total number of intput samples */ blkCnt = blockSize; /* Loop over the blockSize. */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum = 0.0f; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + i - 1; /* Loop over the polyPhase length */ tapCnt = phaseLen; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ sum += *ptr1++ * *ptr2; /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Decrement the loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = sum; /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last phaseLen - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; tapCnt = phaseLen - 1U; while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_fir_interpolate_q31( const arm_fir_interpolate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ q31_t *ptr1; /* Temporary pointer for state buffer */ const q31_t *ptr2; /* Temporary pointer for coefficient buffer */ q63_t sum; /* Accumulator */ q31_t x0, c0; /* Temporary variables to hold state and coefficient values */ uint32_t i, blkCnt; /* Loop counters */ uint16_t phaseLen = S->phaseLength, tapCnt; /* Length of each polyphase filter component */ /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + (q31_t)phaseLen - 1; /* Total number of intput samples */ blkCnt = blockSize; /* Loop over the blockSize. */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum = 0; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + i - 1; tapCnt = phaseLen; while (tapCnt > 0U) { /* Read the coefficient */ c0 = *(ptr2); /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Read the input sample */ x0 = *ptr1++; /* Perform the multiply-accumulate */ sum += (q63_t) x0 *c0; /* Decrement the loop counter */ tapCnt--; } /* The result is in the accumulator, store in the destination buffer. */ *pDst++ = (q31_t)(sum >> 31); /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last phaseLen - 1 samples to the satrt of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; tapCnt = phaseLen - 1U; /* copy data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_fir_interpolate_q15( const arm_fir_interpolate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q15_t *ptr1; /* Temporary pointer for state buffer */ const q15_t *ptr2; /* Temporary pointer for coefficient buffer */ q63_t sum; /* Accumulator */ q15_t x0, c0; /* Temporary variables to hold state and coefficient values */ uint32_t i, blkCnt, tapCnt; /* Loop counters */ uint16_t phaseLen = S->phaseLength; /* Length of each polyphase filter component */ /* S->pState buffer contains previous frame (phaseLen - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = S->pState + phaseLen - 1; /* Total number of intput samples */ blkCnt = blockSize; /* Loop over the blockSize. */ while (blkCnt > 0U) { /* Copy new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Loop over the Interpolation factor. */ i = S->L; while (i > 0U) { /* Set accumulator to zero */ sum = 0; /* Initialize state pointer */ ptr1 = pState; /* Initialize coefficient pointer */ ptr2 = pCoeffs + i - 1; /* Loop over the polyPhase length */ tapCnt = (uint32_t)phaseLen; while (tapCnt > 0U) { /* Read the coefficient */ c0 = *ptr2; /* Increment the coefficient pointer by interpolation factor times. */ ptr2 += S->L; /* Read the input sample */ x0 = *ptr1++; /* Perform the multiply-accumulate */ sum += (q31_t) x0 * c0; /* Decrement the loop counter */ tapCnt--; } /* Store the result after converting to 1.15 format in the destination buffer */ *pDst++ = ref_sat_q15(sum >> 15); /* Decrement the loop counter */ i--; } /* Advance the state pointer by 1 * to process the next group of interpolation factor number samples */ pState = pState + 1; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. ** Now copy the last phaseLen - 1 samples to the start of the state buffer. ** This prepares the state buffer for the next function call. */ /* Points to the start of the state buffer */ pStateCurnt = S->pState; i = (uint32_t) phaseLen - 1U; while (i > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ i--; } }
8,667
C
28.684931
117
0.533864
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/FilteringFunctions.c
#include "biquad.c" #include "conv.c" #include "correlate.c" #include "fir.c" #include "fir_decimate.c" #include "fir_interpolate.c" #include "fir_lattice.c" #include "fir_sparse.c" #include "iir_lattice.c" #include "lms.c"
226
C
16.461537
28
0.70354
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/fir_lattice.c
#include "ref.h" void ref_fir_lattice_f32( const arm_fir_lattice_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t *pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *px; /* temporary state pointer */ const float32_t *pk; /* temporary coefficient pointer */ float32_t fcurr, fnext, gcurr, gnext; /* temporary variables */ uint32_t numStages = S->numStages; /* Length of the filter */ uint32_t blkCnt, stageCnt; /* temporary variables for counts */ pState = &S->pState[0]; blkCnt = blockSize; while (blkCnt > 0U) { /* f0(n) = x(n) */ fcurr = *pSrc++; /* Initialize coeff pointer */ pk = pCoeffs; /* Initialize state pointer */ px = pState; /* read g0(n-1) from state buffer */ gcurr = *px; /* for sample 1 processing */ /* f1(n) = f0(n) + K1 * g0(n-1) */ fnext = fcurr + ((*pk) * gcurr); /* g1(n) = f0(n) * K1 + g0(n-1) */ gnext = (fcurr * (*pk++)) + gcurr; /* save f0(n) in state buffer */ *px++ = fcurr; /* f1(n) is saved in fcurr for next stage processing */ fcurr = fnext; stageCnt = (numStages - 1U); /* stage loop */ while (stageCnt > 0U) { /* read g2(n) from state buffer */ gcurr = *px; /* save g1(n) in state buffer */ *px++ = gnext; /* Sample processing for K2, K3.... */ /* f2(n) = f1(n) + K2 * g1(n-1) */ fnext = fcurr + ((*pk) * gcurr); /* g2(n) = f1(n) * K2 + g1(n-1) */ gnext = (fcurr * (*pk++)) + gcurr; /* f1(n) is saved in fcurr1 for next stage processing */ fcurr = fnext; stageCnt--; } /* y(n) = fN(n) */ *pDst++ = fcurr; blkCnt--; } } void ref_fir_lattice_q31( const arm_fir_lattice_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t *pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *px; /* temporary state pointer */ const q31_t *pk; /* temporary coefficient pointer */ q31_t fcurr, fnext, gcurr, gnext; /* temporary variables */ uint32_t numStages = S->numStages; /* Length of the filter */ uint32_t blkCnt, stageCnt; /* temporary variables for counts */ pState = &S->pState[0]; blkCnt = blockSize; while (blkCnt > 0U) { /* f0(n) = x(n) */ fcurr = *pSrc++; /* Initialize coeff pointer */ pk = pCoeffs; /* Initialize state pointer */ px = pState; /* read g0(n-1) from state buffer */ gcurr = *px; /* for sample 1 processing */ /* f1(n) = f0(n) + K1 * g0(n-1) */ fnext = (q31_t) (((q63_t) gcurr * (*pk)) >> 31) + fcurr; /* g1(n) = f0(n) * K1 + g0(n-1) */ gnext = (q31_t) (((q63_t) fcurr * (*pk++)) >> 31) + gcurr; /* save g1(n) in state buffer */ *px++ = fcurr; /* f1(n) is saved in fcurr1 for next stage processing */ fcurr = fnext; stageCnt = (numStages - 1U); /* stage loop */ while (stageCnt > 0U) { /* read g2(n) from state buffer */ gcurr = *px; /* save g1(n) in state buffer */ *px++ = gnext; /* Sample processing for K2, K3.... */ /* f2(n) = f1(n) + K2 * g1(n-1) */ fnext = (q31_t) (((q63_t) gcurr * (*pk)) >> 31) + fcurr; /* g2(n) = f1(n) * K2 + g1(n-1) */ gnext = (q31_t) (((q63_t) fcurr * (*pk++)) >> 31) + gcurr; /* f1(n) is saved in fcurr1 for next stage processing */ fcurr = fnext; stageCnt--; } /* y(n) = fN(n) */ *pDst++ = fcurr; blkCnt--; } } void ref_fir_lattice_q15( const arm_fir_lattice_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q15_t *pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *px; /* temporary state pointer */ const q15_t *pk; /* temporary coefficient pointer */ q31_t fcurnt, fnext, gcurnt, gnext; /* temporary variables */ uint32_t numStages = S->numStages; /* Length of the filter */ uint32_t blkCnt, stageCnt; /* temporary variables for counts */ pState = &S->pState[0]; blkCnt = blockSize; while (blkCnt > 0U) { /* f0(n) = x(n) */ fcurnt = *pSrc++; /* Initialize coeff pointer */ pk = (pCoeffs); /* Initialize state pointer */ px = pState; /* read g0(n-1) from state buffer */ gcurnt = *px; /* for sample 1 processing */ /* f1(n) = f0(n) + K1 * g0(n-1) */ fnext = ((gcurnt * (*pk)) >> 15U) + fcurnt; fnext = ref_sat_q15(fnext); /* g1(n) = f0(n) * K1 + g0(n-1) */ gnext = ((fcurnt * (*pk++)) >> 15U) + gcurnt; gnext = ref_sat_q15(gnext); /* save f0(n) in state buffer */ *px++ = (q15_t) fcurnt; /* f1(n) is saved in fcurnt for next stage processing */ fcurnt = fnext; stageCnt = (numStages - 1U); /* stage loop */ while (stageCnt > 0U) { /* read g1(n-1) from state buffer */ gcurnt = *px; /* save g0(n-1) in state buffer */ *px++ = (q15_t) gnext; /* Sample processing for K2, K3.... */ /* f2(n) = f1(n) + K2 * g1(n-1) */ fnext = ((gcurnt * (*pk)) >> 15U) + fcurnt; fnext = ref_sat_q15(fnext); /* g2(n) = f1(n) * K2 + g1(n-1) */ gnext = ((fcurnt * (*pk++)) >> 15U) + gcurnt; gnext = ref_sat_q15(gnext); /* f1(n) is saved in fcurnt for next stage processing */ fcurnt = fnext; stageCnt--; } /* y(n) = fN(n) */ *pDst++ = ref_sat_q15(fcurnt); blkCnt--; } }
6,295
C
25.016529
91
0.462907
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/conv.c
#include "ref.h" void ref_conv_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst) { float32_t sum; /* Accumulator */ uint32_t i, j; /* loop counters */ /* Loop to calculate convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry out MAC operations */ sum = 0.0f; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += pSrcB[i - j] * pSrcA[j]; } } /* Store the output in the destination buffer */ pDst[i] = sum; } } arm_status ref_conv_partial_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst, uint32_t firstIndex, uint32_t numPoints) { ref_conv_f32(pSrcA,srcALen,pSrcB,srcBLen,pDst); return ARM_MATH_SUCCESS; } void ref_conv_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst) { q63_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += (q63_t) pSrcA[j] * (pSrcB[i - j]); } } /* Store the output in the destination buffer */ pDst[i] = (q31_t)(sum >> 31U); } } void ref_conv_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst) { q31_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum = (q31_t) ((((q63_t)sum << 32) + ((q63_t)pSrcA[j] * pSrcB[i - j])) >> 32); } } /* Store the output in the destination buffer */ pDst[i] = (q31_t)(sum << 1U); } } arm_status ref_conv_partial_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints) { ref_conv_q31(pSrcA,srcALen,pSrcB,srcBLen,pDst); return ARM_MATH_SUCCESS; } arm_status ref_conv_partial_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints) { ref_conv_fast_q31(pSrcA,srcALen,pSrcB,srcBLen,pDst); return ARM_MATH_SUCCESS; } void ref_conv_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst) { q63_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += (q31_t)pSrcA[j] * pSrcB[i - j]; } } /* Store the output in the destination buffer */ pDst[i] = ref_sat_q15(sum >> 15U); } } arm_status ref_conv_partial_fast_opt_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints, q15_t * pScratch1, q15_t * pScratch2) { q31_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += (q31_t)pSrcA[j] * pSrcB[i - j]; } } /* Store the output in the destination buffer */ pDst[i] = ref_sat_q15(sum >> 15U); } return ARM_MATH_SUCCESS; } void ref_conv_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst) { q31_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += (q31_t)pSrcA[j] * pSrcB[i - j]; } } /* Store the output in the destination buffer */ pDst[i] = sum >> 15U; } } void ref_conv_fast_opt_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch1, q15_t * pScratch2) { q31_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += (q31_t)pSrcA[j] * pSrcB[i - j]; } } /* Store the output in the destination buffer */ pDst[i] = ref_sat_q15(sum >> 15U); } } arm_status ref_conv_partial_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints) { ref_conv_q15(pSrcA,srcALen,pSrcB,srcBLen,pDst); return ARM_MATH_SUCCESS; } arm_status ref_conv_partial_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints) { ref_conv_fast_q15(pSrcA,srcALen,pSrcB,srcBLen,pDst); return ARM_MATH_SUCCESS; } void ref_conv_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst) { q31_t sum; /* Accumulator */ uint32_t i, j; /* loop counter */ /* Loop to calculate output of convolution for output length number of times */ for (i = 0; i < srcALen + srcBLen - 1; i++) { /* Initialize sum with zero to carry on MAC operations */ sum = 0; /* Loop to perform MAC operations according to convolution equation */ for (j = 0; j <= i; j++) { /* Check the array limitations */ if ((i - j < srcBLen) && (j < srcALen)) { /* z[i] += x[i-j] * y[j] */ sum += (q15_t)pSrcA[j] * pSrcB[i - j]; } } /* Store the output in the destination buffer */ pDst[i] = (q7_t)ref_sat_q7(sum >> 7); } } arm_status ref_conv_partial_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, uint32_t firstIndex, uint32_t numPoints) { ref_conv_q7(pSrcA,srcALen,pSrcB,srcBLen,pDst); return ARM_MATH_SUCCESS; }
8,617
C
23.552706
81
0.534061
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/fir_sparse.c
#include "ref.h" void ref_fir_sparse_f32( arm_fir_sparse_instance_f32 * S, float32_t * pSrc, float32_t * pDst, float32_t * pScratchIn, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ const float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *px; /* Scratch buffer pointer */ float32_t *py = pState; /* Temporary pointers for state buffer */ float32_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ float32_t *pOut; /* Destination pointer */ int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ uint32_t delaySize = S->maxDelay + blockSize; /* state length */ uint16_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ int32_t readIndex; /* Read index of the state buffer */ uint32_t tapCnt, blkCnt; /* loop counters */ float32_t coeff = *pCoeffs++; /* Read the first coefficient value */ /* BlockSize of Input samples are copied into the state buffer */ /* StateIndex points to the starting position to write in the state buffer */ arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1, (int32_t *) pSrc, 1, blockSize); /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer */ px = pb; /* Working pointer for destination buffer */ pOut = pDst; blkCnt = blockSize; while (blkCnt > 0U) { /* Perform Multiplications and store in destination buffer */ *pOut++ = *px++ * coeff; /* Decrement the loop counter */ blkCnt--; } /* Loop over the number of taps. */ tapCnt = (uint32_t) numTaps - 1U; while (tapCnt > 0U) { /* Load the coefficient value and * increment the coefficient buffer for the next set of state values */ coeff = *pCoeffs++; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer */ px = pb; /* Working pointer for destination buffer */ pOut = pDst; blkCnt = blockSize; while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ *pOut++ += *px++ * coeff; /* Decrement the loop counter */ blkCnt--; } /* Decrement the tap loop counter */ tapCnt--; } } void ref_fir_sparse_q31( arm_fir_sparse_instance_q31 * S, q31_t * pSrc, q31_t * pDst, q31_t * pScratchIn, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ const q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *px; /* Scratch buffer pointer */ q31_t *py = pState; /* Temporary pointers for state buffer */ q31_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ q31_t *pOut; /* Destination pointer */ q63_t out; /* Temporary output variable */ int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ uint32_t delaySize = S->maxDelay + blockSize; /* state length */ uint16_t numTaps = S->numTaps; /* Filter order */ int32_t readIndex; /* Read index of the state buffer */ uint32_t tapCnt, blkCnt; /* loop counters */ q31_t coeff = *pCoeffs++; /* Read the first coefficient value */ q31_t in; /* BlockSize of Input samples are copied into the state buffer */ /* StateIndex points to the starting position to write in the state buffer */ arm_circularWrite_f32((int32_t *) py, delaySize, &S->stateIndex, 1, (int32_t *) pSrc, 1, blockSize); /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pOut = pDst; blkCnt = blockSize; while (blkCnt > 0U) { /* Perform Multiplications and store in the destination buffer */ *pOut++ = (q31_t) (((q63_t) * px++ * coeff) >> 32); /* Decrement the loop counter */ blkCnt--; } /* Loop over the number of taps. */ tapCnt = (uint32_t) numTaps - 1U; while (tapCnt > 0U) { /* Load the coefficient value and * increment the coefficient buffer for the next set of state values */ coeff = *pCoeffs++; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (int32_t) (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_f32((int32_t *) py, delaySize, &readIndex, 1, (int32_t *) pb, (int32_t *) pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pOut = pDst; blkCnt = blockSize; while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ out = *pOut; out += ((q63_t) * px++ * coeff) >> 32; *pOut++ = (q31_t) (out); /* Decrement the loop counter */ blkCnt--; } /* Decrement the tap loop counter */ tapCnt--; } /* Working output pointer is updated */ pOut = pDst; /* Output is converted into 1.31 format. */ blkCnt = blockSize; while (blkCnt > 0U) { in = *pOut << 1; *pOut++ = in; /* Decrement the loop counter */ blkCnt--; } } void ref_fir_sparse_q15( arm_fir_sparse_instance_q15 * S, q15_t * pSrc, q15_t * pDst, q15_t * pScratchIn, q31_t * pScratchOut, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ const q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pIn = pSrc; /* Working pointer for input */ q15_t *pOut = pDst; /* Working pointer for output */ q15_t *px; /* Temporary pointers for scratch buffer */ q15_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ q15_t *py = pState; /* Temporary pointers for state buffer */ int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ uint32_t delaySize = S->maxDelay + blockSize; /* state length */ uint16_t numTaps = S->numTaps; /* Filter order */ int32_t readIndex; /* Read index of the state buffer */ uint32_t tapCnt, blkCnt; /* loop counters */ q15_t coeff = *pCoeffs++; /* Read the first coefficient value */ q31_t *pScr2 = pScratchOut; /* Working pointer for pScratchOut */ /* BlockSize of Input samples are copied into the state buffer */ /* StateIndex points to the starting position to write in the state buffer */ arm_circularWrite_q15(py, delaySize, &S->stateIndex, 1, pIn, 1, blockSize); /* Loop over the number of taps. */ tapCnt = numTaps; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_q15(py, delaySize, &readIndex, 1, pb, pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pScratchOut = pScr2; blkCnt = blockSize; while (blkCnt > 0U) { /* Perform multiplication and store in the scratch buffer */ *pScratchOut++ = ((q31_t) * px++ * coeff); /* Decrement the loop counter */ blkCnt--; } /* Loop over the number of taps. */ tapCnt = (uint32_t) numTaps - 1U; while (tapCnt > 0U) { /* Load the coefficient value and * increment the coefficient buffer for the next set of state values */ coeff = *pCoeffs++; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = (S->stateIndex - blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_q15(py, delaySize, &readIndex, 1, pb, pb, blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pScratchOut = pScr2; blkCnt = blockSize; while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ *pScratchOut++ += (q31_t) * px++ * coeff; /* Decrement the loop counter */ blkCnt--; } /* Decrement the tap loop counter */ tapCnt--; } /* All the output values are in pScratchOut buffer. Convert them into 1.15 format, saturate and store in the destination buffer. */ /* Loop over the blockSize. */ blkCnt = blockSize; while (blkCnt > 0U) { *pOut++ = (q15_t) __SSAT(*pScr2++ >> 15, 16); blkCnt--; } } void ref_fir_sparse_q7( arm_fir_sparse_instance_q7 * S, q7_t *pSrc, q7_t *pDst, q7_t *pScratchIn, q31_t * pScratchOut, uint32_t blockSize) { q7_t *pState = S->pState; /* State pointer */ const q7_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q7_t *px; /* Scratch buffer pointer */ q7_t *py = pState; /* Temporary pointers for state buffer */ q7_t *pb = pScratchIn; /* Temporary pointers for scratch buffer */ q7_t *pOut = pDst; /* Destination pointer */ int32_t *pTapDelay = S->pTapDelay; /* Pointer to the array containing offset of the non-zero tap values. */ uint32_t delaySize = S->maxDelay + blockSize; /* state length */ uint16_t numTaps = S->numTaps; /* Filter order */ int32_t readIndex; /* Read index of the state buffer */ uint32_t tapCnt, blkCnt; /* loop counters */ q7_t coeff = *pCoeffs++; /* Read the coefficient value */ q31_t *pScr2 = pScratchOut; /* Working pointer for scratch buffer of output values */ q31_t in; /* BlockSize of Input samples are copied into the state buffer */ /* StateIndex points to the starting position to write in the state buffer */ arm_circularWrite_q7(py, (int32_t) delaySize, &S->stateIndex, 1, pSrc, 1, blockSize); /* Loop over the number of taps. */ tapCnt = numTaps; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb, (int32_t) blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pScratchOut = pScr2; /* Loop over the blockSize */ blkCnt = blockSize; while (blkCnt > 0U) { /* Perform multiplication and store in the scratch buffer */ *pScratchOut++ = ((q31_t) * px++ * coeff); /* Decrement the loop counter */ blkCnt--; } /* Loop over the number of taps. */ tapCnt = (uint32_t) numTaps - 1U; while (tapCnt > 0U) { /* Load the coefficient value and * increment the coefficient buffer for the next set of state values */ coeff = *pCoeffs++; /* Read Index, from where the state buffer should be read, is calculated. */ readIndex = ((int32_t) S->stateIndex - (int32_t) blockSize) - *pTapDelay++; /* Wraparound of readIndex */ if (readIndex < 0) { readIndex += (int32_t) delaySize; } /* Working pointer for state buffer is updated */ py = pState; /* blockSize samples are read from the state buffer */ arm_circularRead_q7(py, (int32_t) delaySize, &readIndex, 1, pb, pb, (int32_t) blockSize, 1, blockSize); /* Working pointer for the scratch buffer of state values */ px = pb; /* Working pointer for scratch buffer of output values */ pScratchOut = pScr2; /* Loop over the blockSize */ blkCnt = blockSize; while (blkCnt > 0U) { /* Perform Multiply-Accumulate */ in = *pScratchOut + ((q31_t) * px++ * coeff); *pScratchOut++ = in; /* Decrement the loop counter */ blkCnt--; } /* Decrement the tap loop counter */ tapCnt--; } /* All the output values are in pScratchOut buffer. Convert them into 1.15 format, saturate and store in the destination buffer. */ /* Loop over the blockSize. */ blkCnt = blockSize; while (blkCnt > 0U) { *pOut++ = (q7_t) __SSAT(*pScr2++ >> 7, 8); /* Decrement the blockSize loop counter */ blkCnt--; } }
16,025
C
31.975309
127
0.558003
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/lms.c
#include "ref.h" void ref_lms_f32( const arm_lms_instance_f32 * S, float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t mu = S->mu; /* Adaptive factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i, blkCnt; /* Loop counters */ float32_t sum, e, d; /* accumulator, error, reference data sample */ float32_t w = 0.0f; /* weight factor */ e = 0.0f; d = 0.0f; /* S->pState points to state array which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[numTaps - 1U]); blkCnt = blockSize; while (blkCnt > 0U) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Set the accumulator to zero */ sum = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulate */ sum += pState[i] * pCoeffs[i]; } /* The result is stored in the destination buffer. */ *pOut++ = sum; /* Compute and store error */ d = *pRef++; e = d - sum; *pErr++ = e; /* Weighting factor for the LMS version */ w = e * mu; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulate */ pCoeffs[i] += w * pState[i]; } /* Advance state pointer by 1 for the next sample */ pState++; /* Decrement the loop counter */ blkCnt--; } /* Processing is complete. Now copy the last numTaps - 1 samples to the * start of the state buffer. This prepares the state buffer for the * next function call. */ for(i=0;i<numTaps-1;i++) { S->pState[i] = pState[i]; } } void ref_lms_norm_f32( arm_lms_norm_instance_f32 * S, float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize) { float32_t *pState = S->pState; /* State pointer */ float32_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ float32_t *pStateCurnt; /* Points to the current sample of the state */ float32_t mu = S->mu; /* Adaptive factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t i, blkCnt; /* Loop counters */ float32_t energy; /* Energy of the input */ float32_t sum, e, d; /* accumulator, error, reference data sample */ float32_t w, x0, in; /* weight factor, temporary variable to hold input sample and state */ /* Initializations of error, difference, Coefficient update */ e = 0.0f; d = 0.0f; w = 0.0f; energy = S->energy; x0 = S->x0; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[numTaps - 1U]); for(blkCnt = blockSize; blkCnt > 0U; blkCnt--) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc; /* Read the sample from input buffer */ in = *pSrc++; /* Update the energy calculation */ energy -= x0 * x0; energy += in * in; /* Set the accumulator to zero */ sum = 0.0f; for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulate */ sum += pState[i] * pCoeffs[i]; } /* The result in the accumulator is stored in the destination buffer. */ *pOut++ = sum; /* Compute and store error */ d = *pRef++; e = d - sum; *pErr++ = e; /* Calculation of Weighting factor for updating filter coefficients */ /* epsilon value 0.000000119209289f */ w = e * mu / (energy + 0.000000119209289f); for(i=0;i<numTaps;i++) { /* Perform the multiply-accumulate */ pCoeffs[i] += w * pState[i]; } x0 = *pState; /* Advance state pointer by 1 for the next sample */ pState++; } S->energy = energy; S->x0 = x0; /* Processing is complete. Now copy the last numTaps - 1 samples to the * start of the state buffer. This prepares the state buffer for the * next function call. */ for(i=0;i<numTaps-1;i++) { S->pState[i] = pState[i]; } } void ref_lms_q31( const arm_lms_instance_q31 * S, q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ q31_t mu = S->mu; /* Adaptive factor */ q31_t *px; /* Temporary pointer for state */ q31_t *pb; /* Temporary pointer for coefficient buffer */ uint32_t tapCnt, blkCnt; /* Loop counters */ q63_t acc; /* Accumulator */ q31_t e = 0; /* error of data sample */ q31_t alpha; /* Intermediate constant for taps update */ q31_t coef; /* Temporary variable for coef */ q31_t acc_l, acc_h; /* temporary input */ uint32_t uShift = (uint32_t)S->postShift + 1; uint32_t lShift = 32U - uShift; /* Shift to be applied to the output */ /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); for(blkCnt = blockSize; blkCnt > 0U; blkCnt--) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Initialize pState pointer */ px = pState; /* Initialize pCoeffs pointer */ pb = pCoeffs; /* Set the accumulator to zero */ acc = 0; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += (q63_t)(*px++) * (*pb++); /* Decrement the loop counter */ tapCnt--; } /* Converting the result to 1.31 format */ /* Store the result from accumulator into the destination buffer. */ /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; acc = (uint32_t)acc_l >> lShift | acc_h << uShift; *pOut++ = (q31_t)acc; /* Compute and store error */ e = *pRef++ - (q31_t)acc; *pErr++ = (q31_t)e; /* Weighting factor for the LMS version */ alpha = (q31_t)(((q63_t)e * mu) >> 31); /* Initialize pState pointer */ /* Advance state pointer by 1 for the next sample */ px = pState++; /* Initialize pCoeffs pointer */ pb = pCoeffs; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ coef = (q31_t)(((q63_t) alpha * (*px++)) >> 32); *pb = ref_sat_q31((q63_t)*pb + (coef << 1)); pb++; /* Decrement the loop counter */ tapCnt--; } } /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* Copy (numTaps - 1U) samples */ tapCnt = numTaps - 1; /* Copy the data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_lms_norm_q31( arm_lms_norm_instance_q31 * S, q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize) { q31_t *pState = S->pState; /* State pointer */ q31_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q31_t *pStateCurnt; /* Points to the current sample of the state */ q31_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ q31_t mu = S->mu; /* Adaptive factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t tapCnt, blkCnt; /* Loop counters */ q63_t energy; /* Energy of the input */ q63_t acc; /* Accumulator */ q31_t e = 0, d = 0; /* error, reference data sample */ q31_t w = 0, in; /* weight factor and state */ q31_t x0; /* temporary variable to hold input sample */ q63_t errorXmu; /* Temporary variables to store error and mu product and reciprocal of energy */ q31_t coef; /* Temporary variable for coef */ q31_t acc_l, acc_h; /* temporary input */ uint32_t uShift = ((uint32_t) S->postShift + 1U); uint32_t lShift = 32U - uShift; /* Shift to be applied to the output */ energy = S->energy; x0 = S->x0; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); for(blkCnt = blockSize; blkCnt > 0U; blkCnt--) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc; /* Initialize pState pointer */ px = pState; /* Initialize pCoeffs pointer */ pb = pCoeffs; /* Read the sample from input buffer */ in = *pSrc++; /* Update the energy calculation */ energy = (q31_t)((((q63_t)energy << 32) - (((q63_t)x0 * x0) << 1)) >> 32) & 0xffffffff; energy = (q31_t)(((((q63_t)in * in) << 1) + ((q63_t)energy << 32)) >> 32) & 0xffffffff; /* Set the accumulator to zero */ acc = 0; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += ((q63_t) (*px++)) * (*pb++); /* Decrement the loop counter */ tapCnt--; } /* Converting the result to 1.31 format */ /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; acc = (uint32_t)acc_l >> lShift | acc_h << uShift; /* Store the result from accumulator into the destination buffer. */ *pOut++ = (q31_t)acc; /* Compute and store error */ d = *pRef++; e = d - (q31_t)acc; *pErr++ = e; /* Calculation of product of (e * mu) */ errorXmu = (q63_t)e * mu; /* Weighting factor for the normalized version */ w = ref_sat_q31(errorXmu / (energy + DELTA_Q31)); /* Initialize pState pointer */ px = pState; /* Initialize coeff pointer */ pb = pCoeffs; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ /* coef is in 2.30 format */ coef = (q31_t)(((q63_t)w * (*px++)) >> 32); /* get coef in 1.31 format by left shifting */ *pb = ref_sat_q31((q63_t)*pb + (coef << 1U)); /* update coefficient buffer to next coefficient */ pb++; /* Decrement the loop counter */ tapCnt--; } /* Read the sample from state buffer */ x0 = *pState; /* Advance state pointer by 1 for the next sample */ pState++; } /* Save energy and x0 values for the next frame */ S->energy = (q31_t)energy; S->x0 = x0; /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* Loop for (numTaps - 1U) samples copy */ tapCnt = numTaps - 1; /* Copy the remaining q31_t data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_lms_q15( const arm_lms_instance_q15 * S, q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q15_t mu = S->mu; /* Adaptive factor */ q15_t *px; /* Temporary pointer for state */ q15_t *pb; /* Temporary pointer for coefficient buffer */ uint32_t tapCnt, blkCnt; /* Loop counters */ q63_t acc; /* Accumulator */ q15_t e = 0; /* error of data sample */ q15_t alpha; /* Intermediate constant for taps update */ q31_t coef; /* Teporary variable for coefficient */ q31_t acc_l, acc_h; int32_t lShift = 15 - (int32_t)S->postShift; /* Post shift */ int32_t uShift = 32 - lShift; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); for(blkCnt = blockSize; blkCnt > 0U; blkCnt--) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc++; /* Initialize pState pointer */ px = pState; /* Initialize pCoeffs pointer */ pb = pCoeffs; /* Set the accumulator to zero */ acc = 0; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += (q63_t)((q31_t)(*px++) * (*pb++)); /* Decrement the loop counter */ tapCnt--; } /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ acc = (uint32_t)acc_l >> lShift | acc_h << uShift; /* Converting the result to 1.15 format and saturate the output */ acc = ref_sat_q15(acc); /* Store the result from accumulator into the destination buffer. */ *pOut++ = (q15_t)acc; /* Compute and store error */ e = *pRef++ - (q15_t)acc; *pErr++ = (q15_t)e; /* Compute alpha i.e. intermediate constant for taps update */ alpha = (q15_t)(((q31_t)e * mu) >> 15); /* Initialize pState pointer */ /* Advance state pointer by 1 for the next sample */ px = pState++; /* Initialize pCoeffs pointer */ pb = pCoeffs; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ coef = (q31_t) * pb + (((q31_t) alpha * (*px++)) >> 15); *pb++ = (q15_t) ref_sat_q15(coef); /* Decrement the loop counter */ tapCnt--; } } /* Processing is complete. Now copy the last numTaps - 1 samples to the start of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* Copy (numTaps - 1U) samples */ tapCnt = numTaps - 1; /* Copy the data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_lms_norm_q15( arm_lms_norm_instance_q15 * S, q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize) { q15_t *pState = S->pState; /* State pointer */ q15_t *pCoeffs = S->pCoeffs; /* Coefficient pointer */ q15_t *pStateCurnt; /* Points to the current sample of the state */ q15_t *px, *pb; /* Temporary pointers for state and coefficient buffers */ q15_t mu = S->mu; /* Adaptive factor */ uint32_t numTaps = S->numTaps; /* Number of filter coefficients in the filter */ uint32_t tapCnt, blkCnt; /* Loop counters */ q31_t energy; /* Energy of the input */ q63_t acc; /* Accumulator */ q15_t e = 0, d = 0; /* error, reference data sample */ q15_t w = 0, in; /* weight factor and state */ q15_t x0; /* temporary variable to hold input sample */ q15_t errorXmu, oneByEnergy; /* Temporary variables to store error and mu product and reciprocal of energy */ //q31_t errorXmu; /* Temporary variables to store error and mu product and reciprocal of energy */ q15_t postShift; /* Post shift to be applied to weight after reciprocal calculation */ q31_t coef; /* Teporary variable for coefficient */ q31_t acc_l, acc_h; int32_t lShift = 15 - (int32_t)S->postShift; /* Post shift */ int32_t uShift = 32 - lShift; energy = S->energy; x0 = S->x0; /* S->pState points to buffer which contains previous frame (numTaps - 1) samples */ /* pStateCurnt points to the location where the new input data should be written */ pStateCurnt = &(S->pState[(numTaps - 1U)]); for(blkCnt = blockSize; blkCnt > 0U; blkCnt--) { /* Copy the new input sample into the state buffer */ *pStateCurnt++ = *pSrc; /* Initialize pState pointer */ px = pState; /* Initialize pCoeffs pointer */ pb = pCoeffs; /* Read the sample from input buffer */ in = *pSrc++; /* Update the energy calculation */ energy -= (((q31_t)x0 * x0) >> 15) & 0xffff; energy += (((q31_t)in * in) >> 15) & 0xffff; /* Set the accumulator to zero */ acc = 0; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ acc += (q31_t)*px++ * (*pb++); /* Decrement the loop counter */ tapCnt--; } /* Calc lower part of acc */ acc_l = acc & 0xffffffff; /* Calc upper part of acc */ acc_h = (acc >> 32) & 0xffffffff; /* Apply shift for lower part of acc and upper part of acc */ acc = (uint32_t) acc_l >> lShift | acc_h << uShift; /* Converting the result to 1.15 format and saturate the output */ acc = ref_sat_q15(acc); /* Store the result from accumulator into the destination buffer. */ *pOut++ = (q15_t) acc; /* Compute and store error */ d = *pRef++; e = d - (q15_t) acc; *pErr++ = e; #if 0 /* Calculation of e * mu value */ errorXmu = (q31_t) e * mu; /* Calculation of (e * mu) /energy value */ acc = errorXmu / (energy + DELTA_Q15); #endif /* Calculation of 1/energy */ postShift = arm_recip_q15((q15_t) energy + DELTA_Q15, &oneByEnergy, S->recipTable); /* Calculation of e * mu value */ errorXmu = (q15_t) (((q31_t) e * mu) >> 15); /* Calculation of (e * mu) * (1/energy) value */ acc = (((q31_t) errorXmu * oneByEnergy) >> (15 - postShift)); /* Weighting factor for the normalized version */ w = ref_sat_q15((q31_t)acc); /* Initialize pState pointer */ px = pState; /* Initialize coeff pointer */ pb = pCoeffs; /* Loop over numTaps number of values */ tapCnt = numTaps; while (tapCnt > 0U) { /* Perform the multiply-accumulate */ coef = *pb + (((q31_t)w * (*px++)) >> 15); *pb++ = ref_sat_q15(coef); /* Decrement the loop counter */ tapCnt--; } /* Read the sample from state buffer */ x0 = *pState; /* Advance state pointer by 1 for the next sample */ pState = pState + 1U; } /* Save energy and x0 values for the next frame */ S->energy = (q15_t)energy; S->x0 = x0; /* Processing is complete. Now copy the last numTaps - 1 samples to the satrt of the state buffer. This prepares the state buffer for the next function call. */ /* Points to the start of the pState buffer */ pStateCurnt = S->pState; /* copy (numTaps - 1U) data */ tapCnt = numTaps - 1; /* copy data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } }
21,467
C
29.844828
129
0.539759
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/src/FilteringFunctions/iir_lattice.c
#include "ref.h" void ref_iir_lattice_f32( const arm_iir_lattice_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize) { float32_t fcurr, fnext = 0, gcurr, gnext; /* Temporary variables for lattice stages */ float32_t acc; /* Accumlator */ uint32_t blkCnt, tapCnt; /* temporary variables for counts */ float32_t *px1, *px2, *pk, *pv; /* temporary pointers for state and coef */ uint32_t numStages = S->numStages; /* number of stages */ float32_t *pState; /* State pointer */ float32_t *pStateCurnt; /* State current pointer */ blkCnt = blockSize; pState = &S->pState[0]; /* Sample processing */ while (blkCnt > 0U) { /* Read Sample from input buffer */ /* fN(n) = x(n) */ fcurr = *pSrc++; /* Initialize state read pointer */ px1 = pState; /* Initialize state write pointer */ px2 = pState; /* Set accumulator to zero */ acc = 0.0f; /* Initialize Ladder coeff pointer */ pv = &S->pvCoeffs[0]; /* Initialize Reflection coeff pointer */ pk = &S->pkCoeffs[0]; /* Process sample for numStages */ tapCnt = numStages; while (tapCnt > 0U) { gcurr = *px1++; /* Process sample for last taps */ fnext = fcurr - (*pk) * gcurr; gnext = fnext * (*pk++) + gcurr; /* Output samples for last taps */ acc += gnext * (*pv++); *px2++ = gnext; fcurr = fnext; /* Decrementing loop counter */ tapCnt--; } /* y(n) += g0(n) * v0 */ acc += fnext * (*pv); *px2++ = fnext; /* write out into pDst */ *pDst++ = acc; /* Advance the state pointer by 1 to process the next group of samples */ pState = pState + 1U; blkCnt--; } /* Processing is complete. Now copy last S->numStages samples to start of the buffer for the preperation of next frame process */ /* Points to the start of the state buffer */ pStateCurnt = &S->pState[0]; pState = &S->pState[blockSize]; tapCnt = numStages; /* Copy the data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_iir_lattice_q31( const arm_iir_lattice_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize) { q31_t fcurr, fnext = 0, gcurr = 0, gnext; /* Temporary variables for lattice stages */ q63_t acc; /* Accumlator */ uint32_t blkCnt, tapCnt; /* Temporary variables for counts */ q31_t *px1, *px2, *pk, *pv; /* Temporary pointers for state and coef */ uint32_t numStages = S->numStages; /* number of stages */ q31_t *pState; /* State pointer */ q31_t *pStateCurnt; /* State current pointer */ blkCnt = blockSize; pState = &S->pState[0]; /* Sample processing */ while (blkCnt > 0U) { /* Read Sample from input buffer */ /* fN(n) = x(n) */ fcurr = *pSrc++; /* Initialize state read pointer */ px1 = pState; /* Initialize state write pointer */ px2 = pState; /* Set accumulator to zero */ acc = 0; /* Initialize Ladder coeff pointer */ pv = &S->pvCoeffs[0]; /* Initialize Reflection coeff pointer */ pk = &S->pkCoeffs[0]; tapCnt = numStages; while (tapCnt > 0U) { gcurr = *px1++; /* Process sample */ /* fN-1(n) = fN(n) - kN * gN-1(n-1) */ fnext = ref_sat_q31(((q63_t) fcurr - ((q31_t) (((q63_t) gcurr * (*pk)) >> 31)))); /* gN(n) = kN * fN-1(n) + gN-1(n-1) */ gnext = ref_sat_q31(((q63_t) gcurr + ((q31_t) (((q63_t) fnext * (*pk++)) >> 31)))); /* Output samples */ /* y(n) += gN(n) * vN */ acc += ((q63_t) gnext * *pv++); /* write gN-1(n-1) into state for next sample processing */ *px2++ = gnext; /* Update f values for next coefficient processing */ fcurr = fnext; tapCnt--; } /* y(n) += g0(n) * v0 */ acc += (q63_t) fnext *(*pv++); *px2++ = fnext; /* write out into pDst */ *pDst++ = (q31_t) (acc >> 31U); /* Advance the state pointer by 1 to process the next group of samples */ pState = pState + 1U; blkCnt--; } /* Processing is complete. Now copy last S->numStages samples to start of the buffer for the preperation of next frame process */ /* Points to the start of the state buffer */ pStateCurnt = &S->pState[0]; pState = &S->pState[blockSize]; tapCnt = numStages; /* Copy the remaining q31_t data */ while (tapCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ tapCnt--; } } void ref_iir_lattice_q15( const arm_iir_lattice_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize) { q31_t fcurr, fnext = 0, gcurr = 0, gnext; /* Temporary variables for lattice stages */ uint32_t stgCnt; /* Temporary variables for counts */ q63_t acc; /* Accumlator */ uint32_t blkCnt, tapCnt; /* Temporary variables for counts */ q15_t *px1, *px2, *pk, *pv; /* temporary pointers for state and coef */ uint32_t numStages = S->numStages; /* number of stages */ q15_t *pState; /* State pointer */ q15_t *pStateCurnt; /* State current pointer */ q15_t out; /* Temporary variable for output */ blkCnt = blockSize; pState = &S->pState[0]; /* Sample processing */ while (blkCnt > 0U) { /* Read Sample from input buffer */ /* fN(n) = x(n) */ fcurr = *pSrc++; /* Initialize state read pointer */ px1 = pState; /* Initialize state write pointer */ px2 = pState; /* Set accumulator to zero */ acc = 0; /* Initialize Ladder coeff pointer */ pv = &S->pvCoeffs[0]; /* Initialize Reflection coeff pointer */ pk = &S->pkCoeffs[0]; tapCnt = numStages; while (tapCnt > 0U) { gcurr = *px1++; /* Process sample */ /* fN-1(n) = fN(n) - kN * gN-1(n-1) */ fnext = fcurr - ((gcurr * (*pk)) >> 15); fnext = ref_sat_q15(fnext); /* gN(n) = kN * fN-1(n) + gN-1(n-1) */ gnext = ((fnext * (*pk++)) >> 15) + gcurr; gnext = ref_sat_q15(gnext); /* Output samples */ /* y(n) += gN(n) * vN */ acc += (q31_t) ((gnext * (*pv++))); /* write gN(n) into state for next sample processing */ *px2++ = (q15_t) gnext; /* Update f values for next coefficient processing */ fcurr = fnext; tapCnt--; } /* y(n) += g0(n) * v0 */ acc += (q31_t) ((fnext * (*pv++))); out = ref_sat_q15(acc >> 15); *px2++ = (q15_t) fnext; /* write out into pDst */ *pDst++ = out; /* Advance the state pointer by 1 to process the next group of samples */ pState = pState + 1U; blkCnt--; } /* Processing is complete. Now copy last S->numStages samples to start of the buffer for the preperation of next frame process */ /* Points to the start of the state buffer */ pStateCurnt = &S->pState[0]; pState = &S->pState[blockSize]; stgCnt = numStages; /* copy data */ while (stgCnt > 0U) { *pStateCurnt++ = *pState++; /* Decrement the loop counter */ stgCnt--; } }
7,629
C
27.05147
97
0.520121
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/DSP_Lib_TestSuite/RefLibs/inc/ref.h
#ifndef _REF_H #define _REF_H #include <math.h> #include <stdint.h> #include "arm_math.h" #ifdef __cplusplus extern "C" { #endif #ifndef PI #define PI 3.14159265358979f #endif /** * @brief 8-bit fractional data type in 1.7 format. */ // typedef int8_t q7_t; /** * @brief 16-bit fractional data type in 1.15 format. */ // typedef int16_t q15_t; /** * @brief 32-bit fractional data type in 1.31 format. */ // typedef int32_t q31_t; /** * @brief 64-bit fractional data type in 1.63 format. */ // typedef int64_t q63_t; /** * @brief 32-bit floating-point type definition. */ // typedef float float32_t; /** * @brief 64-bit floating-point type definition. */ // typedef double float64_t; /** * @brief Error status returned by some functions in the library. */ typedef enum { REF_Q7 = 0, REF_Q15, REF_Q31, REF_F32, } dataType; #ifndef FLT_MAX #define FLT_MAX 3.40282347e+38F #endif #define DBL_MAX 1.79769313486231571e+308 #ifndef FLT_MIN #define FLT_MIN 1.175494351e-38F #endif #define DBL_MIN 2.22507385850720138e-308 #define SCHAR_MIN (-128) /* mimimum value for an object of type signed char */ #define SCHAR_MAX 127 /* maximum value for an object of type signed char */ #define UCHAR_MAX 255 /* maximum value for an object of type unsigned char */ #define SHRT_MIN (-0x8000) /* minimum value for an object of type short int */ #define SHRT_MAX 0x7fff /* maximum value for an object of type short int */ #define USHRT_MAX 65535 /* maximum value for an object of type unsigned short int */ #define INT_MIN (~0x7fffffff) /* -2147483648 and 0x80000000 are unsigned */ /* minimum value for an object of type int */ #define INT_MAX 0x7fffffff /* maximum value for an object of type int */ #define UINT_MAX 0xffffffffU /* maximum value for an object of type unsigned int */ #define LONG_MIN (~0x7fffffffL) /* minimum value for an object of type long int */ #define LONG_MAX 0x7fffffffL /* maximum value for an object of type long int */ #define ULONG_MAX 0xffffffffUL /* maximum value for an object of type unsigned long int */ /* * Ref Lib Global Variables */ extern float32_t scratchArray[]; extern arm_cfft_instance_f32 ref_cfft_sR_f32_len8192; /* * Ref Lib Functions */ /* * Helper Functions */ q31_t ref_sat_n(q31_t num, uint32_t bits); q31_t ref_sat_q31(q63_t num); q15_t ref_sat_q15(q31_t num); q7_t ref_sat_q7(q15_t num); float32_t ref_pow(float32_t a, uint32_t b); extern float32_t tempMatrixArray[]; float32_t ref_detrm(float32_t *pSrc, float32_t *temp, uint32_t size); void ref_cofact(float32_t *pSrc, float32_t *pDst, float32_t *temp, uint32_t size); float64_t ref_detrm64(float64_t *pSrc, float64_t *temp, uint32_t size); void ref_cofact64(float64_t *pSrc, float64_t *pDst, float64_t *temp, uint32_t size); /* * Basic Math Functions */ void ref_abs_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_abs_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_abs_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_abs_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize); void ref_add_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); void ref_add_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); void ref_add_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); void ref_add_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); void ref_dot_prod_f32( float32_t * pSrcA, float32_t * pSrcB, uint32_t blockSize, float32_t * result); void ref_dot_prod_q31( q31_t * pSrcA, q31_t * pSrcB, uint32_t blockSize, q63_t * result); void ref_dot_prod_q15( q15_t * pSrcA, q15_t * pSrcB, uint32_t blockSize, q63_t * result); void ref_dot_prod_q7( q7_t * pSrcA, q7_t * pSrcB, uint32_t blockSize, q31_t * result); void ref_mult_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); void ref_mult_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); void ref_mult_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); void ref_mult_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); void ref_negate_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_negate_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_negate_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_negate_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize); void ref_offset_f32( float32_t * pSrc, float32_t offset, float32_t * pDst, uint32_t blockSize); void ref_offset_q31( q31_t * pSrc, q31_t offset, q31_t * pDst, uint32_t blockSize); void ref_offset_q15( q15_t * pSrc, q15_t offset, q15_t * pDst, uint32_t blockSize); void ref_offset_q7( q7_t * pSrc, q7_t offset, q7_t * pDst, uint32_t blockSize); void ref_scale_f32( float32_t * pSrc, float32_t scale, float32_t * pDst, uint32_t blockSize); void ref_scale_q31( q31_t * pSrc, q31_t scaleFract, int8_t shift, q31_t * pDst, uint32_t blockSize); void ref_scale_q15( q15_t * pSrc, q15_t scaleFract, int8_t shift, q15_t * pDst, uint32_t blockSize); void ref_scale_q7( q7_t * pSrc, q7_t scaleFract, int8_t shift, q7_t * pDst, uint32_t blockSize); void ref_shift_q31( q31_t * pSrc, int8_t shiftBits, q31_t * pDst, uint32_t blockSize); void ref_shift_q15( q15_t * pSrc, int8_t shiftBits, q15_t * pDst, uint32_t blockSize); void ref_shift_q7( q7_t * pSrc, int8_t shiftBits, q7_t * pDst, uint32_t blockSize); void ref_sub_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t blockSize); void ref_sub_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t blockSize); void ref_sub_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t blockSize); void ref_sub_q7( q7_t * pSrcA, q7_t * pSrcB, q7_t * pDst, uint32_t blockSize); /* * Complex Math Functions */ void ref_cmplx_conj_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples); void ref_cmplx_conj_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples); void ref_cmplx_conj_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples); void ref_cmplx_dot_prod_f32( float32_t * pSrcA, float32_t * pSrcB, uint32_t numSamples, float32_t * realResult, float32_t * imagResult); void ref_cmplx_dot_prod_q31( q31_t * pSrcA, q31_t * pSrcB, uint32_t numSamples, q63_t * realResult, q63_t * imagResult); void ref_cmplx_dot_prod_q15( q15_t * pSrcA, q15_t * pSrcB, uint32_t numSamples, q31_t * realResult, q31_t * imagResult); void ref_cmplx_mag_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples); void ref_cmplx_mag_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples); void ref_cmplx_mag_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples); void ref_cmplx_mag_squared_f32( float32_t * pSrc, float32_t * pDst, uint32_t numSamples); void ref_cmplx_mag_squared_q31( q31_t * pSrc, q31_t * pDst, uint32_t numSamples); void ref_cmplx_mag_squared_q15( q15_t * pSrc, q15_t * pDst, uint32_t numSamples); void ref_cmplx_mult_cmplx_f32( float32_t * pSrcA, float32_t * pSrcB, float32_t * pDst, uint32_t numSamples); void ref_cmplx_mult_cmplx_q31( q31_t * pSrcA, q31_t * pSrcB, q31_t * pDst, uint32_t numSamples); void ref_cmplx_mult_cmplx_q15( q15_t * pSrcA, q15_t * pSrcB, q15_t * pDst, uint32_t numSamples); void ref_cmplx_mult_real_f32( float32_t * pSrcCmplx, float32_t * pSrcReal, float32_t * pCmplxDst, uint32_t numSamples); void ref_cmplx_mult_real_q31( q31_t * pSrcCmplx, q31_t * pSrcReal, q31_t * pCmplxDst, uint32_t numSamples); void ref_cmplx_mult_real_q15( q15_t * pSrcCmplx, q15_t * pSrcReal, q15_t * pCmplxDst, uint32_t numSamples); /* * Controller Functions */ void ref_sin_cos_f32( float32_t theta, float32_t * pSinVal, float32_t * pCosVal); void ref_sin_cos_q31( q31_t theta, q31_t * pSinVal, q31_t * pCosVal); float32_t ref_pid_f32( arm_pid_instance_f32 * S, float32_t in); q31_t ref_pid_q31( arm_pid_instance_q31 * S, q31_t in); q15_t ref_pid_q15( arm_pid_instance_q15 * S, q15_t in); /* * Fast Math Functions */ #define ref_sin_f32(a) sinf(a) q31_t ref_sin_q31(q31_t x); q15_t ref_sin_q15(q15_t x); #define ref_cos_f32(a) cosf(a) q31_t ref_cos_q31(q31_t x); q15_t ref_cos_q15(q15_t x); arm_status ref_sqrt_q31(q31_t in, q31_t * pOut); arm_status ref_sqrt_q15(q15_t in, q15_t * pOut); /* * Filtering Functions */ void ref_biquad_cascade_df2T_f32( const arm_biquad_cascade_df2T_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_biquad_cascade_stereo_df2T_f32( const arm_biquad_cascade_stereo_df2T_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_biquad_cascade_df2T_f64( const arm_biquad_cascade_df2T_instance_f64 * S, float64_t * pSrc, float64_t * pDst, uint32_t blockSize); void ref_biquad_cascade_df1_f32( const arm_biquad_casd_df1_inst_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_biquad_cas_df1_32x64_q31( const arm_biquad_cas_df1_32x64_ins_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_biquad_cascade_df1_q31( const arm_biquad_casd_df1_inst_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_biquad_cascade_df1_fast_q31( const arm_biquad_casd_df1_inst_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_biquad_cascade_df1_fast_q15( const arm_biquad_casd_df1_inst_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_biquad_cascade_df1_q15( const arm_biquad_casd_df1_inst_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_conv_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst); arm_status ref_conv_partial_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst, uint32_t firstIndex, uint32_t numPoints); void ref_conv_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); void ref_conv_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); arm_status ref_conv_partial_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints); arm_status ref_conv_partial_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst, uint32_t firstIndex, uint32_t numPoints); void ref_conv_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); #define ref_conv_opt_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ pScratch1, pScratch2) \ ref_conv_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst) void ref_conv_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); void ref_conv_fast_opt_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch1, q15_t * pScratch2); arm_status ref_conv_partial_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints); #define ref_conv_partial_opt_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ firstIndex, numPoints, \ pScratch1, pScratch2) \ ref_conv_partial_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ firstIndex, numPoints) arm_status ref_conv_partial_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints); arm_status ref_conv_partial_fast_opt_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, uint32_t firstIndex, uint32_t numPoints, q15_t * pScratch1, q15_t * pScratch2); void ref_conv_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst); #define ref_conv_opt_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ pScratch1, pScratch2) \ ref_conv_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst) arm_status ref_conv_partial_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst, uint32_t firstIndex, uint32_t numPoints); #define ref_conv_partial_opt_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ firstIndex, numPoints, \ pScratch1, pScratch2) \ ref_conv_partial_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ firstIndex, numPoints) void ref_correlate_f32( float32_t * pSrcA, uint32_t srcALen, float32_t * pSrcB, uint32_t srcBLen, float32_t * pDst); void ref_correlate_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); void ref_correlate_fast_q31( q31_t * pSrcA, uint32_t srcALen, q31_t * pSrcB, uint32_t srcBLen, q31_t * pDst); void ref_correlate_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); #define ref_correlate_opt_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ pScratch1) \ ref_correlate_q15(pSrcA, srcALen, pSrcB, srcBLen, pDst) void ref_correlate_fast_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst); void ref_correlate_fast_opt_q15( q15_t * pSrcA, uint32_t srcALen, q15_t * pSrcB, uint32_t srcBLen, q15_t * pDst, q15_t * pScratch); void ref_correlate_q7( q7_t * pSrcA, uint32_t srcALen, q7_t * pSrcB, uint32_t srcBLen, q7_t * pDst); #define ref_correlate_opt_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst, \ pScratch1, pScratch2) \ ref_correlate_q7(pSrcA, srcALen, pSrcB, srcBLen, pDst) void ref_fir_f32( const arm_fir_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_fir_q31( const arm_fir_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_fir_fast_q31( const arm_fir_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_fir_q15( const arm_fir_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_fir_fast_q15( const arm_fir_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_fir_q7( const arm_fir_instance_q7 * S, q7_t * pSrc, q7_t * pDst, uint32_t blockSize); void ref_fir_decimate_f32( const arm_fir_decimate_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_fir_decimate_q31( const arm_fir_decimate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_fir_decimate_fast_q31( const arm_fir_decimate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_fir_decimate_q15( const arm_fir_decimate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_fir_decimate_fast_q15( const arm_fir_decimate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_fir_lattice_f32( const arm_fir_lattice_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_fir_lattice_q31( const arm_fir_lattice_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_fir_lattice_q15( const arm_fir_lattice_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_fir_sparse_f32( arm_fir_sparse_instance_f32 * S, float32_t * pSrc, float32_t * pDst, float32_t * pScratchIn, uint32_t blockSize); void ref_fir_sparse_q31( arm_fir_sparse_instance_q31 * S, q31_t * pSrc, q31_t * pDst, q31_t * pScratchIn, uint32_t blockSize); void ref_fir_sparse_q15( arm_fir_sparse_instance_q15 * S, q15_t * pSrc, q15_t * pDst, q15_t * pScratchIn, q31_t * pScratchOut, uint32_t blockSize); void ref_fir_sparse_q7( arm_fir_sparse_instance_q7 * S, q7_t *pSrc, q7_t *pDst, q7_t *pScratchIn, q31_t * pScratchOut, uint32_t blockSize); void ref_iir_lattice_f32( const arm_iir_lattice_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_iir_lattice_q31( const arm_iir_lattice_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_iir_lattice_q15( const arm_iir_lattice_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_lms_f32( const arm_lms_instance_f32 * S, float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize); void ref_lms_norm_f32( arm_lms_norm_instance_f32 * S, float32_t * pSrc, float32_t * pRef, float32_t * pOut, float32_t * pErr, uint32_t blockSize); void ref_lms_q31( const arm_lms_instance_q31 * S, q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize); void ref_lms_norm_q31( arm_lms_norm_instance_q31 * S, q31_t * pSrc, q31_t * pRef, q31_t * pOut, q31_t * pErr, uint32_t blockSize); void ref_lms_q15( const arm_lms_instance_q15 * S, q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize); void ref_lms_norm_q15( arm_lms_norm_instance_q15 * S, q15_t * pSrc, q15_t * pRef, q15_t * pOut, q15_t * pErr, uint32_t blockSize); void ref_fir_interpolate_f32( const arm_fir_interpolate_instance_f32 * S, float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_fir_interpolate_q31( const arm_fir_interpolate_instance_q31 * S, q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_fir_interpolate_q15( const arm_fir_interpolate_instance_q15 * S, q15_t * pSrc, q15_t * pDst, uint32_t blockSize); /* * Matrix Functions */ arm_status ref_mat_cmplx_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); arm_status ref_mat_cmplx_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); arm_status ref_mat_cmplx_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); arm_status ref_mat_inverse_f32( const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst); arm_status ref_mat_inverse_f64( const arm_matrix_instance_f64 * pSrc, arm_matrix_instance_f64 * pDst); arm_status ref_mat_mult_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); arm_status ref_mat_mult_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); /* Alias for testing purposes*/ #define ref_mat_mult_fast_q31 ref_mat_mult_q31 arm_status ref_mat_mult_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); /* Alias for testing purposes*/ #define ref_mat_mult_fast_q15 ref_mat_mult_q15 arm_status ref_mat_scale_f32( const arm_matrix_instance_f32 * pSrc, float32_t scale, arm_matrix_instance_f32 * pDst); arm_status ref_mat_scale_q31( const arm_matrix_instance_q31 * pSrc, q31_t scale, int32_t shift, arm_matrix_instance_q31 * pDst); arm_status ref_mat_scale_q15( const arm_matrix_instance_q15 * pSrc, q15_t scale, int32_t shift, arm_matrix_instance_q15 * pDst); arm_status ref_mat_sub_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); arm_status ref_mat_sub_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); arm_status ref_mat_sub_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); arm_status ref_mat_trans_f64( const arm_matrix_instance_f64 * pSrc, arm_matrix_instance_f64 * pDst); arm_status ref_mat_trans_f32( const arm_matrix_instance_f32 * pSrc, arm_matrix_instance_f32 * pDst); arm_status ref_mat_trans_q31( const arm_matrix_instance_q31 * pSrc, arm_matrix_instance_q31 * pDst); arm_status ref_mat_trans_q15( const arm_matrix_instance_q15 * pSrc, arm_matrix_instance_q15 * pDst); arm_status ref_mat_add_f32( const arm_matrix_instance_f32 * pSrcA, const arm_matrix_instance_f32 * pSrcB, arm_matrix_instance_f32 * pDst); arm_status ref_mat_add_q31( const arm_matrix_instance_q31 * pSrcA, const arm_matrix_instance_q31 * pSrcB, arm_matrix_instance_q31 * pDst); arm_status ref_mat_add_q15( const arm_matrix_instance_q15 * pSrcA, const arm_matrix_instance_q15 * pSrcB, arm_matrix_instance_q15 * pDst); /* * Statistics Functions */ void ref_max_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex); void ref_max_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex); void ref_max_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex); void ref_max_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex); void ref_mean_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); void ref_mean_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); void ref_mean_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); void ref_mean_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult); void ref_min_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult, uint32_t * pIndex); void ref_min_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult, uint32_t * pIndex); void ref_min_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult, uint32_t * pIndex); void ref_min_q7( q7_t * pSrc, uint32_t blockSize, q7_t * pResult, uint32_t * pIndex); void ref_power_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); void ref_power_q31( q31_t * pSrc, uint32_t blockSize, q63_t * pResult); void ref_power_q15( q15_t * pSrc, uint32_t blockSize, q63_t * pResult); void ref_power_q7( q7_t * pSrc, uint32_t blockSize, q31_t * pResult); void ref_rms_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); void ref_rms_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); void ref_rms_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); void ref_std_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); void ref_std_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); void ref_std_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); void ref_var_f32( float32_t * pSrc, uint32_t blockSize, float32_t * pResult); void ref_var_q31( q31_t * pSrc, uint32_t blockSize, q31_t * pResult); void ref_var_q15( q15_t * pSrc, uint32_t blockSize, q15_t * pResult); /* * Support Functions */ void ref_copy_f32( float32_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_copy_q31( q31_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_copy_q15( q15_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_copy_q7( q7_t * pSrc, q7_t * pDst, uint32_t blockSize); void ref_fill_f32( float32_t value, float32_t * pDst, uint32_t blockSize); void ref_fill_q31( q31_t value, q31_t * pDst, uint32_t blockSize); void ref_fill_q15( q15_t value, q15_t * pDst, uint32_t blockSize); void ref_fill_q7( q7_t value, q7_t * pDst, uint32_t blockSize); void ref_q31_to_q15( q31_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_q31_to_q7( q31_t * pSrc, q7_t * pDst, uint32_t blockSize); void ref_q15_to_q31( q15_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_q15_to_q7( q15_t * pSrc, q7_t * pDst, uint32_t blockSize); void ref_q7_to_q31( q7_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_q7_to_q15( q7_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_q63_to_float( q63_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_q31_to_float( q31_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_q15_to_float( q15_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_q7_to_float( q7_t * pSrc, float32_t * pDst, uint32_t blockSize); void ref_float_to_q31( float32_t * pSrc, q31_t * pDst, uint32_t blockSize); void ref_float_to_q15( float32_t * pSrc, q15_t * pDst, uint32_t blockSize); void ref_float_to_q7( float32_t * pSrc, q7_t * pDst, uint32_t blockSize); /* * Transform Functions */ void ref_cfft_f32( const arm_cfft_instance_f32 * S, float32_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag); void ref_cfft_q31( const arm_cfft_instance_q31 * S, q31_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag); void ref_cfft_q15( const arm_cfft_instance_q15 * S, q15_t * p1, uint8_t ifftFlag, uint8_t bitReverseFlag); void ref_cfft_radix2_f32( const arm_cfft_radix2_instance_f32 * S, float32_t * pSrc); void ref_cfft_radix2_q31( const arm_cfft_radix2_instance_q31 * S, q31_t * pSrc); void ref_cfft_radix2_q15( const arm_cfft_radix2_instance_q15 * S, q15_t * pSrc); void ref_cfft_radix4_f32( const arm_cfft_radix4_instance_f32 * S, float32_t * pSrc); void ref_cfft_radix4_q31( const arm_cfft_radix4_instance_q31 * S, q31_t * pSrc); void ref_cfft_radix4_q15( const arm_cfft_radix4_instance_q15 * S, q15_t * pSrc); void ref_rfft_f32( arm_rfft_instance_f32 * S, float32_t * pSrc, float32_t * pDst); void ref_rfft_fast_f32( arm_rfft_fast_instance_f32 * S, float32_t * p, float32_t * pOut, uint8_t ifftFlag); void ref_rfft_q31( const arm_rfft_instance_q31 * S, q31_t * pSrc, q31_t * pDst); void ref_rfft_q15( const arm_rfft_instance_q15 * S, q15_t * pSrc, q15_t * pDst); void ref_dct4_f32( const arm_dct4_instance_f32 * S, float32_t * pState, float32_t * pInlineBuffer); void ref_dct4_q31( const arm_dct4_instance_q31 * S, q31_t * pState, q31_t * pInlineBuffer); void ref_dct4_q15( const arm_dct4_instance_q15 * S, q15_t * pState, q15_t * pInlineBuffer); /* * Intrinsics */ q31_t ref__QADD8(q31_t x, q31_t y); q31_t ref__QSUB8(q31_t x, q31_t y); q31_t ref__QADD16(q31_t x, q31_t y); q31_t ref__SHADD16(q31_t x, q31_t y); q31_t ref__QSUB16(q31_t x, q31_t y); q31_t ref__SHSUB16(q31_t x, q31_t y); q31_t ref__QASX(q31_t x, q31_t y); q31_t ref__SHASX(q31_t x, q31_t y); q31_t ref__QSAX(q31_t x, q31_t y); q31_t ref__SHSAX(q31_t x, q31_t y); q31_t ref__SMUSDX(q31_t x, q31_t y); q31_t ref__SMUADX(q31_t x, q31_t y); q31_t ref__QADD(q31_t x, q31_t y); q31_t ref__QSUB(q31_t x, q31_t y); q31_t ref__SMLAD(q31_t x, q31_t y, q31_t sum); q31_t ref__SMLADX(q31_t x, q31_t y, q31_t sum); q31_t ref__SMLSDX(q31_t x, q31_t y, q31_t sum); q63_t ref__SMLALD(q31_t x, q31_t y, q63_t sum); q63_t ref__SMLALDX(q31_t x, q31_t y, q63_t sum); q31_t ref__SMUAD(q31_t x, q31_t y); q31_t ref__SMUSD(q31_t x, q31_t y); q31_t ref__SXTB16(q31_t x); #ifdef __cplusplus } #endif #endif
27,872
C
18.880884
84
0.644625
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/boot/RTE_Components.h
#ifndef RTE_COMPONENTS_H #define RTE_COMPONENTS_H #endif /* RTE_COMPONENTS_H */
81
C
15.399997
29
0.728395
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/math_helper.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 b * * Project: CMSIS DSP Library * * Title: math_helper.c * * Description: Definition of all helper functions required. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- * Include standard header files * -------------------------------------------------------------------- */ #include<math.h> /* ---------------------------------------------------------------------- * Include project header files * -------------------------------------------------------------------- */ #include "math_helper.h" /** * @brief Caluclation of SNR * @param[in] pRef Pointer to the reference buffer * @param[in] pTest Pointer to the test buffer * @param[in] buffSize total number of samples * @return SNR * The function Caluclates signal to noise ratio for the reference output * and test output */ float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize) { float EnergySignal = 0.0, EnergyError = 0.0; uint32_t i; float SNR; int temp; int *test; for (i = 0; i < buffSize; i++) { /* Checking for a NAN value in pRef array */ test = (int *)(&pRef[i]); temp = *test; if (temp == 0x7FC00000) { return(0); } /* Checking for a NAN value in pTest array */ test = (int *)(&pTest[i]); temp = *test; if (temp == 0x7FC00000) { return(0); } EnergySignal += pRef[i] * pRef[i]; EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]); } /* Checking for a NAN value in EnergyError */ test = (int *)(&EnergyError); temp = *test; if (temp == 0x7FC00000) { return(0); } SNR = 10 * log10 (EnergySignal / EnergyError); return (SNR); } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q15 (q15_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Converts float to fixed in q12.20 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to outputbuffer * @param[in] numSamples number of samples in the input buffer * @return none * The function converts floating point values to fixed point(q12.20) values */ void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1048576.0f corresponds to pow(2, 20) */ pOut[i] = (q31_t) (pIn[i] * 1048576.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 1.0) { pOut[i] = 0x000FFFFF; } } } /** * @brief Compare MATLAB Reference Output and ARM Test output * @param[in] pIn Pointer to Ref buffer * @param[in] pOut Pointer to Test buffer * @param[in] numSamples number of samples in the buffer * @return maximum difference */ uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t *pOut, uint32_t numSamples) { uint32_t i; int32_t diff, diffCrnt = 0; uint32_t maxDiff = 0; for (i = 0; i < numSamples; i++) { diff = pIn[i] - pOut[i]; diffCrnt = (diff > 0) ? diff : -diff; if (diffCrnt > maxDiff) { maxDiff = diffCrnt; } } return(maxDiff); } /** * @brief Compare MATLAB Reference Output and ARM Test output * @param[in] pIn Pointer to Ref buffer * @param[in] pOut Pointer to Test buffer * @param[in] numSamples number of samples in the buffer * @return maximum difference */ uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; int32_t diff, diffCrnt = 0; uint32_t maxDiff = 0; for (i = 0; i < numSamples; i++) { diff = pIn[i] - pOut[i]; diffCrnt = (diff > 0) ? diff : -diff; if (diffCrnt > maxDiff) { maxDiff = diffCrnt; } } return(maxDiff); } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q31 (q31_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q7 (q7_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Caluclates number of guard bits * @param[in] num_adds number of additions * @return guard bits * The function Caluclates the number of guard bits * depending on the numtaps */ uint32_t arm_calc_guard_bits (uint32_t num_adds) { uint32_t i = 1, j = 0; if (num_adds == 1) { return (0); } while (i < num_adds) { i = i * 2; j++; } return (j); } /** * @brief Apply guard bits to buffer * @param[in,out] pIn pointer to input buffer * @param[in] numSamples number of samples in the input buffer * @param[in] guard_bits guard bits * @return none */ void arm_apply_guard_bits (float32_t *pIn, uint32_t numSamples, uint32_t guard_bits) { uint32_t i; for (i = 0; i < numSamples; i++) { pIn[i] = pIn[i] * arm_calc_2pow(guard_bits); } } /** * @brief Calculates pow(2, numShifts) * @param[in] numShifts number of shifts * @return pow(2, numShifts) */ uint32_t arm_calc_2pow(uint32_t numShifts) { uint32_t i, val = 1; for (i = 0; i < numShifts; i++) { val = val * 2; } return(val); } /** * @brief Converts float to fixed q14 * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q14 (float *pIn, q15_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 16384.0f corresponds to pow(2, 14) */ pOut[i] = (q15_t) (pIn[i] * 16384.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 2.0) { pOut[i] = 0x7FFF; } } } /** * @brief Converts float to fixed q30 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q30 (float *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1073741824.0f corresponds to pow(2, 30) */ pOut[i] = (q31_t) (pIn[i] * 1073741824.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 2.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Converts float to fixed q30 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q29 (float *pIn, q31_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1073741824.0f corresponds to pow(2, 30) */ pOut[i] = (q31_t) (pIn[i] * 536870912.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 4.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Converts float to fixed q28 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q28 (float *pIn, q31_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 268435456.0f corresponds to pow(2, 28) */ pOut[i] = (q31_t) (pIn[i] * 268435456.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 8.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Clip the float values to +/- 1 * @param[in,out] pIn input buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_clip_f32 (float *pIn, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { if (pIn[i] > 1.0f) { pIn[i] = 1.0; } else if ( pIn[i] < -1.0f) { pIn[i] = -1.0; } } }
11,228
C
23.044968
77
0.583363
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/math_helper.h
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2013 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * * Title: math_helper.h * * Description: Prototypes of all helper functions required. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ #include "arm_math.h" #ifndef MATH_HELPER_H #define MATH_HELPER_H float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize); void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples); void arm_provide_guard_bits_q15(q15_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_provide_guard_bits_q31(q31_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_float_to_q14(float *pIn, q15_t *pOut, uint32_t numSamples); void arm_float_to_q29(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_float_to_q28(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_float_to_q30(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_clip_f32(float *pIn, uint32_t numSamples); uint32_t arm_calc_guard_bits(uint32_t num_adds); void arm_apply_guard_bits (float32_t * pIn, uint32_t numSamples, uint32_t guard_bits); uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples); uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t *pOut, uint32_t numSamples); uint32_t arm_calc_2pow(uint32_t guard_bits); #endif
3,022
C
46.234374
91
0.705824
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/arm_convolution_example_f32.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * Title: arm_convolution_example_f32.c * * Description: Example code demonstrating Convolution of two input signals using fft. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /** * @ingroup groupExamples */ /** * @defgroup ConvolutionExample Convolution Example * * \par Description: * \par * Demonstrates the convolution theorem with the use of the Complex FFT, Complex-by-Complex * Multiplication, and Support Functions. * * \par Algorithm: * \par * The convolution theorem states that convolution in the time domain corresponds to * multiplication in the frequency domain. Therefore, the Fourier transform of the convoution of * two signals is equal to the product of their individual Fourier transforms. * The Fourier transform of a signal can be evaluated efficiently using the Fast Fourier Transform (FFT). * \par * Two input signals, <code>a[n]</code> and <code>b[n]</code>, with lengths \c n1 and \c n2 respectively, * are zero padded so that their lengths become \c N, which is greater than or equal to <code>(n1+n2-1)</code> * and is a power of 4 as FFT implementation is radix-4. * The convolution of <code>a[n]</code> and <code>b[n]</code> is obtained by taking the FFT of the input * signals, multiplying the Fourier transforms of the two signals, and taking the inverse FFT of * the multiplied result. * \par * This is denoted by the following equations: * <pre> A[k] = FFT(a[n],N) * B[k] = FFT(b[n],N) * conv(a[n], b[n]) = IFFT(A[k] * B[k], N)</pre> * where <code>A[k]</code> and <code>B[k]</code> are the N-point FFTs of the signals <code>a[n]</code> * and <code>b[n]</code> respectively. * The length of the convolved signal is <code>(n1+n2-1)</code>. * * \par Block Diagram: * \par * \image html Convolution.gif * * \par Variables Description: * \par * \li \c testInputA_f32 points to the first input sequence * \li \c srcALen length of the first input sequence * \li \c testInputB_f32 points to the second input sequence * \li \c srcBLen length of the second input sequence * \li \c outLen length of convolution output sequence, <code>(srcALen + srcBLen - 1)</code> * \li \c AxB points to the output array where the product of individual FFTs of inputs is stored. * * \par CMSIS DSP Software Library Functions Used: * \par * - arm_fill_f32() * - arm_copy_f32() * - arm_cfft_radix4_init_f32() * - arm_cfft_radix4_f32() * - arm_cmplx_mult_cmplx_f32() * * <b> Refer </b> * \link arm_convolution_example_f32.c \endlink * */ /** \example arm_convolution_example_f32.c */ #include "arm_math.h" #include "math_helper.h" /* ---------------------------------------------------------------------- * Defines each of the tests performed * ------------------------------------------------------------------- */ #define MAX_BLOCKSIZE 128 #define DELTA (0.000001f) #define SNR_THRESHOLD 90 /* ---------------------------------------------------------------------- * Declare I/O buffers * ------------------------------------------------------------------- */ float32_t Ak[MAX_BLOCKSIZE]; /* Input A */ float32_t Bk[MAX_BLOCKSIZE]; /* Input B */ float32_t AxB[MAX_BLOCKSIZE * 2]; /* Output */ /* ---------------------------------------------------------------------- * Test input data for Floating point Convolution example for 32-blockSize * Generated by the MATLAB randn() function * ------------------------------------------------------------------- */ float32_t testInputA_f32[64] = { -0.808920, 1.357369, 1.180861, -0.504544, 1.762637, -0.703285, 1.696966, 0.620571, -0.151093, -0.100235, -0.872382, -0.403579, -0.860749, -0.382648, -1.052338, 0.128113, -0.646269, 1.093377, -2.209198, 0.471706, 0.408901, 1.266242, 0.598252, 1.176827, -0.203421, 0.213596, -0.851964, -0.466958, 0.021841, -0.698938, -0.604107, 0.461778, -0.318219, 0.942520, 0.577585, 0.417619, 0.614665, 0.563679, -1.295073, -0.764437, 0.952194, -0.859222, -0.618554, -2.268542, -1.210592, 1.655853, -2.627219, -0.994249, -1.374704, 0.343799, 0.025619, 1.227481, -0.708031, 0.069355, -1.845228, -1.570886, 1.010668, -1.802084, 1.630088, 1.286090, -0.161050, -0.940794, 0.367961, 0.291907 }; float32_t testInputB_f32[64] = { 0.933724, 0.046881, 1.316470, 0.438345, 0.332682, 2.094885, 0.512081, 0.035546, 0.050894, -2.320371, 0.168711, -1.830493, -0.444834, -1.003242, -0.531494, -1.365600, -0.155420, -0.757692, -0.431880, -0.380021, 0.096243, -0.695835, 0.558850, -1.648962, 0.020369, -0.363630, 0.887146, 0.845503, -0.252864, -0.330397, 1.269131, -1.109295, -1.027876, 0.135940, 0.116721, -0.293399, -1.349799, 0.166078, -0.802201, 0.369367, -0.964568, -2.266011, 0.465178, 0.651222, -0.325426, 0.320245, -0.784178, -0.579456, 0.093374, 0.604778, -0.048225, 0.376297, -0.394412, 0.578182, -1.218141, -1.387326, 0.692462, -0.631297, 0.153137, -0.638952, 0.635474, -0.970468, 1.334057, -0.111370 }; const float testRefOutput_f32[127] = { -0.818943, 1.229484, -0.533664, 1.016604, 0.341875, -1.963656, 5.171476, 3.478033, 7.616361, 6.648384, 0.479069, 1.792012, -1.295591, -7.447818, 0.315830, -10.657445, -2.483469, -6.524236, -7.380591, -3.739005, -8.388957, 0.184147, -1.554888, 3.786508, -1.684421, 5.400610, -1.578126, 7.403361, 8.315999, 2.080267, 11.077776, 2.749673, 7.138962, 2.748762, 0.660363, 0.981552, 1.442275, 0.552721, -2.576892, 4.703989, 0.989156, 8.759344, -0.564825, -3.994680, 0.954710, -5.014144, 6.592329, 1.599488, -13.979146, -0.391891, -4.453369, -2.311242, -2.948764, 1.761415, -0.138322, 10.433007, -2.309103, 4.297153, 8.535523, 3.209462, 8.695819, 5.569919, 2.514304, 5.582029, 2.060199, 0.642280, 7.024616, 1.686615, -6.481756, 1.343084, -3.526451, 1.099073, -2.965764, -0.173723, -4.111484, 6.528384, -6.965658, 1.726291, 1.535172, 11.023435, 2.338401, -4.690188, 1.298210, 3.943885, 8.407885, 5.168365, 0.684131, 1.559181, 1.859998, 2.852417, 8.574070, -6.369078, 6.023458, 11.837963, -6.027632, 4.469678, -6.799093, -2.674048, 6.250367, -6.809971, -3.459360, 9.112410, -2.711621, -1.336678, 1.564249, -1.564297, -1.296760, 8.904013, -3.230109, 6.878013, -7.819823, 3.369909, -1.657410, -2.007358, -4.112825, 1.370685, -3.420525, -6.276605, 3.244873, -3.352638, 1.545372, 0.902211, 0.197489, -1.408732, 0.523390, 0.348440, 0 }; /* ---------------------------------------------------------------------- * Declare Global variables * ------------------------------------------------------------------- */ uint32_t srcALen = 64; /* Length of Input A */ uint32_t srcBLen = 64; /* Length of Input B */ uint32_t outLen; /* Length of convolution output */ float32_t snr; /* output SNR */ int32_t main(void) { arm_status status; /* Status of the example */ arm_cfft_radix4_instance_f32 cfft_instance; /* CFFT Structure instance */ /* CFFT Structure instance pointer */ arm_cfft_radix4_instance_f32 *cfft_instance_ptr = (arm_cfft_radix4_instance_f32*) &cfft_instance; /* output length of convolution */ outLen = srcALen + srcBLen - 1; /* Initialise the fft input buffers with all zeros */ arm_fill_f32(0.0, Ak, MAX_BLOCKSIZE); arm_fill_f32(0.0, Bk, MAX_BLOCKSIZE); /* Copy the input values to the fft input buffers */ arm_copy_f32(testInputA_f32, Ak, MAX_BLOCKSIZE/2); arm_copy_f32(testInputB_f32, Bk, MAX_BLOCKSIZE/2); /* Initialize the CFFT function to compute 64 point fft */ status = arm_cfft_radix4_init_f32(cfft_instance_ptr, 64, 0, 1); /* Transform input a[n] from time domain to frequency domain A[k] */ arm_cfft_radix4_f32(cfft_instance_ptr, Ak); /* Transform input b[n] from time domain to frequency domain B[k] */ arm_cfft_radix4_f32(cfft_instance_ptr, Bk); /* Complex Multiplication of the two input buffers in frequency domain */ arm_cmplx_mult_cmplx_f32(Ak, Bk, AxB, MAX_BLOCKSIZE/2); /* Initialize the CIFFT function to compute 64 point ifft */ status = arm_cfft_radix4_init_f32(cfft_instance_ptr, 64, 1, 1); /* Transform the multiplication output from frequency domain to time domain, that gives the convolved output */ arm_cfft_radix4_f32(cfft_instance_ptr, AxB); /* SNR Calculation */ snr = arm_snr_f32((float32_t *)testRefOutput_f32, AxB, srcALen + srcBLen - 1); /* Compare the SNR with threshold to test whether the computed output is matched with the reference output values. */ if ( snr > SNR_THRESHOLD) { status = ARM_MATH_SUCCESS; } if ( status != ARM_MATH_SUCCESS) { while (1); } while (1); /* main function does not return */ } /** \endlink */
10,854
C
42.770161
110
0.611572
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/RTE/Device/ARMCM3/system_ARMCM3.c
/**************************************************************************//** * @file system_ARMCM3.c * @brief CMSIS Device System Source File for * ARMCM3 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM3.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,428
C
34.202898
80
0.422158
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/RTE/Device/ARMCM0/system_ARMCM0.c
/**************************************************************************//** * @file system_ARMCM0.c * @brief CMSIS Device System Source File for * ARMCM0 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM0.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { SystemCoreClock = SYSTEM_CLOCK; }
2,063
C
35.210526
80
0.435773
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/RTE/Device/ARMCM4_FP/system_ARMCM4.c
/**************************************************************************//** * @file system_ARMCM4.c * @brief CMSIS Device System Source File for * ARMCM4 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined (ARMCM4) #include "ARMCM4.h" #elif defined (ARMCM4_FP) #include "ARMCM4_FP.h" #else #error device not specified! #endif /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined (__FPU_USED) && (__FPU_USED == 1U) SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ (3U << 11U*2U) ); /* enable CP11 Full Access */ #endif #ifdef UNALIGNED_SUPPORT_DISABLE SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,829
C
32.690476
80
0.444327
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_convolution_example/RTE/Device/ARMCM7_SP/system_ARMCM7.c
/**************************************************************************//** * @file system_ARMCM7.c * @brief CMSIS Device System Source File for * ARMCM7 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined (ARMCM7) #include "ARMCM7.h" #elif defined (ARMCM7_SP) #include "ARMCM7_SP.h" #elif defined (ARMCM7_DP) #include "ARMCM7_DP.h" #else #error device not specified! #endif /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined (__FPU_USED) && (__FPU_USED == 1U) SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ (3U << 11U*2U) ); /* enable CP11 Full Access */ #endif #ifdef UNALIGNED_SUPPORT_DISABLE SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,880
C
32.5
80
0.448611
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/arm_graphic_equalizer_example_q31.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * Title: arm_graphic_equalizer_example_q31.c * * Description: Example showing an audio graphic equalizer constructed * out of Biquad filters. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /** * @ingroup groupExamples */ /** * @defgroup GEQ5Band Graphic Audio Equalizer Example * * \par Description: * \par * This example demonstrates how a 5-band graphic equalizer can be constructed * using the Biquad cascade functions. * A graphic equalizer is used in audio applications to vary the tonal quality * of the audio. * * \par Block Diagram: * \par * The design is based on a cascade of 5 filter sections. * \image html GEQ_signalflow.gif * Each filter section is 4th order and consists of a cascade of two Biquads. * Each filter has a nominal gain of 0 dB (1.0 in linear units) and * boosts or cuts signals within a specific frequency range. * The edge frequencies between the 5 bands are 100, 500, 2000, and 6000 Hz. * Each band has an adjustable boost or cut in the range of +/- 9 dB. * For example, the band that extends from 500 to 2000 Hz has the response shown below: * \par * \image html GEQ_bandresponse.gif * \par * With 1 dB steps, each filter has a total of 19 different settings. * The filter coefficients for all possible 19 settings were precomputed * in MATLAB and stored in a table. With 5 different tables, there are * a total of 5 x 19 = 95 different 4th order filters. * All 95 responses are shown below: * \par * \image html GEQ_allbandresponse.gif * \par * Each 4th order filter has 10 coefficents for a grand total of 950 different filter * coefficients that must be tabulated. The input and output data is in Q31 format. * For better noise performance, the two low frequency bands are implemented using the high * precision 32x64-bit Biquad filters. The remaining 3 high frequency bands use standard * 32x32-bit Biquad filters. The input signal used in the example is a logarithmic chirp. * \par * \image html GEQ_inputchirp.gif * \par * The array <code>bandGains</code> specifies the gain in dB to apply in each band. * For example, if <code>bandGains={0, -3, 6, 4, -6};</code> then the output signal will be: * \par * \image html GEQ_outputchirp.gif * \par * \note The output chirp signal follows the gain or boost of each band. * \par * * \par Variables Description: * \par * \li \c testInput_f32 points to the input data * \li \c testRefOutput_f32 points to the reference output data * \li \c testOutput points to the test output data * \li \c inputQ31 temporary input buffer * \li \c outputQ31 temporary output buffer * \li \c biquadStateBand1Q31 points to state buffer for band1 * \li \c biquadStateBand2Q31 points to state buffer for band2 * \li \c biquadStateBand3Q31 points to state buffer for band3 * \li \c biquadStateBand4Q31 points to state buffer for band4 * \li \c biquadStateBand5Q31 points to state buffer for band5 * \li \c coeffTable points to coefficient buffer for all bands * \li \c gainDB gain buffer which has gains applied for all the bands * * \par CMSIS DSP Software Library Functions Used: * \par * - arm_biquad_cas_df1_32x64_init_q31() * - arm_biquad_cas_df1_32x64_q31() * - arm_biquad_cascade_df1_init_q31() * - arm_biquad_cascade_df1_q31() * - arm_scale_q31() * - arm_scale_f32() * - arm_float_to_q31() * - arm_q31_to_float() * * <b> Refer </b> * \link arm_graphic_equalizer_example_q31.c \endlink * */ /** \example arm_graphic_equalizer_example_q31.c */ #include "arm_math.h" #include "math_helper.h" /* Length of the overall data in the test */ #define TESTLENGTH 320 /* Block size for the underlying processing */ #define BLOCKSIZE 32 /* Total number of blocks to run */ #define NUMBLOCKS (TESTLENGTH/BLOCKSIZE) /* Number of 2nd order Biquad stages per filter */ #define NUMSTAGES 2 #define SNR_THRESHOLD_F32 98 /* ------------------------------------------------------------------- * External Declarations for Input and Output buffers * ------------------------------------------------------------------- */ extern float32_t testInput_f32[TESTLENGTH]; static float32_t testOutput[TESTLENGTH]; extern float32_t testRefOutput_f32[TESTLENGTH]; /* ---------------------------------------------------------------------- ** Q31 state buffers for Band1, Band2, Band3, Band4, Band5 ** ------------------------------------------------------------------- */ static q63_t biquadStateBand1Q31[4 * 2]; static q63_t biquadStateBand2Q31[4 * 2]; static q31_t biquadStateBand3Q31[4 * 2]; static q31_t biquadStateBand4Q31[4 * 2]; static q31_t biquadStateBand5Q31[4 * 2]; /* ---------------------------------------------------------------------- ** Q31 input and output buffers ** ------------------------------------------------------------------- */ q31_t inputQ31[BLOCKSIZE]; q31_t outputQ31[BLOCKSIZE]; /* ---------------------------------------------------------------------- ** Entire coefficient table. There are 10 coefficients per 4th order Biquad ** cascade filter. The first 10 coefficients correspond to the -9 dB gain ** setting of band 1; the next 10 coefficient correspond to the -8 dB gain ** setting of band 1; and so on. There are 10*19=190 coefficients in total ** for band 1 (gains = -9, -8, -7, ..., 9). After this come the 190 coefficients ** for band 2. ** ** The coefficients are in Q29 format and require a postShift of 2. ** ------------------------------------------------------------------- */ const q31_t coeffTable[950] = { /* Band 1, -9 dB gain */ 535576962, -1071153923, 535576962, 1073741824, -536870912, 535576962, -1063501998, 527979313, 1060865294, -524146981, /* Band 1, -8 dB gain */ 535723226, -1071446451, 535723226, 1073741824, -536870912, 535723226, -1063568947, 527903217, 1061230578, -524503778, 535868593, -1071737186, 535868593, 1073741824, -536870912, 535868593, -1063627467, 527819780, 1061585502, -524850686, 536013181, -1072026363, 536013181, 1073741824, -536870912, 536013181, -1063677598, 527728935, 1061930361, -525187972, 536157109, -1072314217, 536157109, 1073741824, -536870912, 536157109, -1063719372, 527630607, 1062265438, -525515897, 536300492, -1072600983, 536300492, 1073741824, -536870912, 536300492, -1063752815, 527524720, 1062591011, -525834716, 536443447, -1072886894, 536443447, 1073741824, -536870912, 536443447, -1063777945, 527411186, 1062907350, -526144676, 536586091, -1073172183, 536586091, 1073741824, -536870912, 536586091, -1063794775, 527289917, 1063214717, -526446017, 536728541, -1073457082, 536728541, 1073741824, -536870912, 536728541, -1063803308, 527160815, 1063513366, -526738975, 536870912, -1073741824, 536870912, 1073741824, -536870912, 536870912, -1063803543, 527023777, 1063803543, -527023777, 537013321, -1074026642, 537013321, 1073741824, -536870912, 537013321, -1063795470, 526878696, 1064085490, -527300648, 537155884, -1074311768, 537155884, 1073741824, -536870912, 537155884, -1063779073, 526725455, 1064359439, -527569803, 537298718, -1074597435, 537298718, 1073741824, -536870912, 537298718, -1063754328, 526563934, 1064625617, -527831454, 537441939, -1074883878, 537441939, 1073741824, -536870912, 537441939, -1063721205, 526394005, 1064884245, -528085806, 537585666, -1075171331, 537585666, 1073741824, -536870912, 537585666, -1063679666, 526215534, 1065135536, -528333059, 537730015, -1075460030, 537730015, 1073741824, -536870912, 537730015, -1063629666, 526028380, 1065379699, -528573409, 537875106, -1075750212, 537875106, 1073741824, -536870912, 537875106, -1063571152, 525832396, 1065616936, -528807045, 538021057, -1076042114, 538021057, 1073741824, -536870912, 538021057, -1063504065, 525627429, 1065847444, -529034151, 538167989, -1076335977, 538167989, 1073741824, -536870912, 538167989, -1063428338, 525413317, 1066071412, -529254907, /* Band 2, -9 dB gain */ 531784976, -1055497692, 523873415, 1066213307, -529420241, 531784976, -1040357886, 509828014, 1028908252, -494627367, /* Band 2, -8 dB gain */ 532357636, -1056601982, 524400080, 1066115844, -529326645, 532357636, -1040623406, 509562600, 1030462237, -496062122, 532927392, -1057707729, 524931110, 1066024274, -529239070, 532927392, -1040848253, 509262081, 1031969246, -497457090, 533494678, -1058816094, 525467240, 1065939047, -529157961, 533494678, -1041032161, 508925950, 1033429976, -498812573, 534059929, -1059928204, 526009170, 1065860582, -529083734, 534059929, -1041174868, 508553717, 1034845124, -500128887, 534623580, -1061045148, 526557561, 1065789260, -529016764, 534623580, -1041276126, 508144920, 1036215393, -501406373, 535186068, -1062167969, 527113032, 1065725420, -528957385, 535186068, -1041335703, 507699125, 1037541500, -502645399, 535747827, -1063297666, 527676151, 1065669351, -528905879, 535747827, -1041353386, 507215934, 1038824183, -503846368, 536309295, -1064435183, 528247436, 1065621289, -528862476, 536309295, -1041328990, 506694984, 1040064203, -505009724, 536870912, -1065581413, 528827349, 1065581413, -528827349, 536870912, -1041262354, 506135953, 1041262354, -506135953, 537433117, -1066737194, 529416295, 1065549847, -528800610, 537433117, -1041153346, 505538564, 1042419457, -507225588, 537996352, -1067903307, 530014622, 1065526651, -528782316, 537996352, -1041001864, 504902578, 1043536370, -508279208, 538561061, -1069080480, 530622620, 1065511830, -528772462, 538561061, -1040807833, 504227800, 1044613981, -509297437, 539127690, -1070269387, 531240527, 1065505333, -528770987, 539127690, -1040571205, 503514074, 1045653211, -510280946, 539696690, -1071470656, 531868525, 1065507054, -528777778, 539696690, -1040291951, 502761277, 1046655011, -511230450, 540268512, -1072684867, 532506750, 1065516837, -528792672, 540268512, -1039970063, 501969320, 1047620358, -512146700, 540843613, -1073912567, 533155297, 1065534483, -528815459, 540843613, -1039605542, 501138139, 1048550251, -513030484, 541422451, -1075154268, 533814224, 1065559750, -528845892, 541422451, -1039198394, 500267687, 1049445708, -513882621, 542005489, -1076410460, 534483561, 1065592362, -528883686, 542005489, -1038748624, 499357932, 1050307760, -514703956, 518903861, -1001986830, 486725277, 1037235801, -502367695, 518903861, -945834422, 446371043, 902366163, -400700571, 520899989, -1005630916, 488289126, 1036926846, -502147311, 520899989, -946490935, 445581846, 907921945, -404936158, 522893209, -1009290002, 489869792, 1036650484, -501961419, 522893209, -947006359, 444685310, 913306106, -409075225, 524884763, -1012968199, 491470256, 1036407567, -501810737, 524884763, -947377809, 443679533, 918521018, -413116221, 526875910, -1016669649, 493093518, 1036198712, -501695739, 526875910, -947602324, 442562672, 923569247, -417057897, 528867927, -1020398503, 494742575, 1036024293, -501616651, 528867927, -947676875, 441332970, 928453558, -420899319, 530862111, -1024158905, 496420407, 1035884447, -501573457, 530862111, -947598385, 439988777, 933176909, -424639872, 532859778, -1027954970, 498129955, 1035779077, -501565907, 532859778, -947363742, 438528571, 937742446, -428279254, 534862260, -1031790763, 499874098, 1035707863, -501593525, 534862260, -946969823, 436950987, 942153486, -431817474, 536870912, -1035670279, 501655630, 1035670279, -501655630, 536870912, -946413508, 435254839, 946413508, -435254839, 538887107, -1039597419, 503477238, 1035665609, -501751354, 538887107, -945691703, 433439146, 950526127, -438591937, 540912240, -1043575967, 505341475, 1035692963, -501879659, 540912240, -944801359, 431503152, 954495080, -441829621, 542947726, -1047609569, 507250741, 1035751307, -502039364, 542947726, -943739490, 429446349, 958324201, -444968987, 544995000, -1051701717, 509207261, 1035839473, -502229165, 544995000, -942503190, 427268492, 962017400, -448011351, 547055523, -1055855728, 511213065, 1035956193, -502447657, 547055523, -941089647, 424969617, 965578640, -450958226, 549130774, -1060074734, 513269973, 1036100110, -502693359, 549130774, -939496155, 422550049, 969011913, -453811298, 551222259, -1064361672, 515379585, 1036269804, -502964731, 551222259, -937720119, 420010407, 972321228, -456572401, 553331507, -1068719280, 517543273, 1036463810, -503260192, 553331507, -935759057, 417351601, 975510582, -459243495, 555460072, -1073150100, 519762181, 1036680633, -503578144, 555460072, -933610600, 414574832, 978583948, -461826644, 494084017, -851422604, 404056273, 930151631, -423619864, 494084017, -673714108, 339502486, 561843007, -265801750, 498713542, -859177141, 406587077, 929211656, -423786402, 498713542, -673274906, 338185129, 573719128, -272222942, 503369016, -867012190, 409148384, 928362985, -424054784, 503369016, -672533059, 336693984, 585290277, -278599028, 508052536, -874935599, 411746438, 927604291, -424422151, 508052536, -671478538, 335026905, 596558312, -284920289, 512766286, -882955583, 414387826, 926933782, -424885216, 512766286, -670100998, 333182045, 607525792, -291177811, 517512534, -891080712, 417079474, 926349262, -425440318, 517512534, -668389789, 331157902, 618195914, -297363485, 522293635, -899319903, 419828635, 925848177, -426083491, 522293635, -666333963, 328953368, 628572440, -303470012, 527112032, -907682405, 422642886, 925427679, -426810526, 527112032, -663922286, 326567785, 638659631, -309490882, 531970251, -916177781, 425530105, 925084675, -427617023, 531970251, -661143261, 324000998, 648462180, -315420352, 536870912, -924815881, 428498454, 924815881, -428498454, 536870912, -657985147, 321253420, 657985147, -321253420, 541816719, -933606817, 431556352, 924617870, -429450209, 541816719, -654435997, 318326093, 667233900, -326985786, 546810467, -942560921, 434712438, 924487114, -430467639, 546810467, -650483688, 315220754, 676214053, -332613816, 551855042, -951688708, 437975532, 924420027, -431546101, 551855042, -646115970, 311939896, 684931422, -338134495, 556953421, -961000826, 441354588, 924413001, -432680993, 556953421, -641320513, 308486839, 693391970, -343545389, 562108672, -970508005, 444858642, 924462435, -433867780, 562108672, -636084967, 304865786, 701601770, -348844597, 567323959, -980220994, 448496743, 924564764, -435102022, 567323959, -630397020, 301081886, 709566963, -354030710, 572602539, -990150500, 452277894, 924716482, -436379394, 572602539, -624244471, 297141281, 717293726, -359102767, 577947763, -1000307125, 456210977, 924914158, -437695705, 577947763, -617615296, 293051155, 724788245, -364060214, 583363084, -1010701292, 460304674, 925154455, -439046908, 583363084, -610497723, 288819761, 732056685, -368902865, 387379495, -506912469, 196933274, 840112184, -347208270, 387379495, 506912469, 196933274, -840112184, -347208270, 401658082, -532275898, 207149427, 833765363, -343175316, 401658082, 532275898, 207149427, -833765363, -343175316, 416472483, -558722695, 217902617, 827270154, -339107319, 416472483, 558722695, 217902617, -827270154, -339107319, 431841949, -586290861, 229212798, 820624988, -335007540, 431841949, 586290861, 229212798, -820624988, -335007540, 447786335, -615019650, 241100489, 813828443, -330879528, 447786335, 615019650, 241100489, -813828443, -330879528, 464326111, -644949597, 253586805, 806879270, -326727141, 464326111, 644949597, 253586805, -806879270, -326727141, 481482377, -676122557, 266693475, 799776409, -322554559, 481482377, 676122557, 266693475, -799776409, -322554559, 499276882, -708581728, 280442865, 792519013, -318366296, 499276882, 708581728, 280442865, -792519013, -318366296, 517732032, -742371685, 294857996, 785106465, -314167221, 517732032, 742371685, 294857996, -785106465, -314167221, 536870912, -777538408, 309962566, 777538408, -309962566, 536870912, 777538408, 309962566, -777538408, -309962566, 556717294, -814129313, 325780968, 769814766, -305757943, 556717294, 814129313, 325780968, -769814766, -305757943, 577295658, -852193284, 342338310, 761935777, -301559360, 577295658, 852193284, 342338310, -761935777, -301559360, 598631206, -891780698, 359660433, 753902014, -297373230, 598631206, 891780698, 359660433, -753902014, -297373230, 620749877, -932943463, 377773927, 745714425, -293206383, 620749877, 932943463, 377773927, -745714425, -293206383, 643678365, -975735041, 396706151, 737374355, -289066077, 643678365, 975735041, 396706151, -737374355, -289066077, 667444134, -1020210487, 416485252, 728883588, -284960004, 667444134, 1020210487, 416485252, -728883588, -284960004, 692075438, -1066426476, 437140179, 720244375, -280896294, 692075438, 1066426476, 437140179, -720244375, -280896294, 717601336, -1114441339, 458700704, 711459472, -276883515, 717601336, 1114441339, 458700704, -711459472, -276883515, 744051710, -1164315096, 481197437, 702532174, -272930673, 744051710, 1164315096, 481197437, -702532174, -272930673 }; /* ---------------------------------------------------------------------- ** Desired gains, in dB, per band ** ------------------------------------------------------------------- */ int gainDB[5] = {0, -3, 6, 4, -6}; float32_t snr; /* ---------------------------------------------------------------------- * Graphic equalizer Example * ------------------------------------------------------------------- */ int32_t main(void) { float32_t *inputF32, *outputF32; arm_biquad_cas_df1_32x64_ins_q31 S1; arm_biquad_cas_df1_32x64_ins_q31 S2; arm_biquad_casd_df1_inst_q31 S3; arm_biquad_casd_df1_inst_q31 S4; arm_biquad_casd_df1_inst_q31 S5; int i; int32_t status; inputF32 = &testInput_f32[0]; outputF32 = &testOutput[0]; /* Initialize the state and coefficient buffers for all Biquad sections */ arm_biquad_cas_df1_32x64_init_q31(&S1, NUMSTAGES, (q31_t *) &coeffTable[190*0 + 10*(gainDB[0] + 9)], &biquadStateBand1Q31[0], 2); arm_biquad_cas_df1_32x64_init_q31(&S2, NUMSTAGES, (q31_t *) &coeffTable[190*1 + 10*(gainDB[1] + 9)], &biquadStateBand2Q31[0], 2); arm_biquad_cascade_df1_init_q31(&S3, NUMSTAGES, (q31_t *) &coeffTable[190*2 + 10*(gainDB[2] + 9)], &biquadStateBand3Q31[0], 2); arm_biquad_cascade_df1_init_q31(&S4, NUMSTAGES, (q31_t *) &coeffTable[190*3 + 10*(gainDB[3] + 9)], &biquadStateBand4Q31[0], 2); arm_biquad_cascade_df1_init_q31(&S5, NUMSTAGES, (q31_t *) &coeffTable[190*4 + 10*(gainDB[4] + 9)], &biquadStateBand5Q31[0], 2); /* Call the process functions and needs to change filter coefficients for varying the gain of each band */ for(i=0; i < NUMBLOCKS; i++) { /* ---------------------------------------------------------------------- ** Convert block of input data from float to Q31 ** ------------------------------------------------------------------- */ arm_float_to_q31(inputF32 + (i*BLOCKSIZE), inputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Scale down by 1/8. This provides additional headroom so that the ** graphic EQ can apply gain. ** ------------------------------------------------------------------- */ arm_scale_q31(inputQ31, 0x7FFFFFFF, -3, inputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Call the Q31 Biquad Cascade DF1 32x64 process function for band1, band2 ** ------------------------------------------------------------------- */ arm_biquad_cas_df1_32x64_q31(&S1, inputQ31, outputQ31, BLOCKSIZE); arm_biquad_cas_df1_32x64_q31(&S2, outputQ31, outputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Call the Q31 Biquad Cascade DF1 process function for band3, band4, band5 ** ------------------------------------------------------------------- */ arm_biquad_cascade_df1_q31(&S3, outputQ31, outputQ31, BLOCKSIZE); arm_biquad_cascade_df1_q31(&S4, outputQ31, outputQ31, BLOCKSIZE); arm_biquad_cascade_df1_q31(&S5, outputQ31, outputQ31, BLOCKSIZE); /* ---------------------------------------------------------------------- ** Convert Q31 result back to float ** ------------------------------------------------------------------- */ arm_q31_to_float(outputQ31, outputF32 + (i * BLOCKSIZE), BLOCKSIZE); /* ---------------------------------------------------------------------- ** Scale back up ** ------------------------------------------------------------------- */ arm_scale_f32(outputF32 + (i * BLOCKSIZE), 8.0f, outputF32 + (i * BLOCKSIZE), BLOCKSIZE); }; snr = arm_snr_f32(testRefOutput_f32, testOutput, TESTLENGTH); if (snr < SNR_THRESHOLD_F32) { status = ARM_MATH_TEST_FAILURE; } else { status = ARM_MATH_SUCCESS; } /* ---------------------------------------------------------------------- ** Loop here if the signal does not match the reference output. ** ------------------------------------------------------------------- */ if ( status != ARM_MATH_SUCCESS) { while (1); } while (1); /* main function does not return */ } /** \endlink */
22,948
C
54.701456
119
0.674307
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/math_helper.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 b * * Project: CMSIS DSP Library * * Title: math_helper.c * * Description: Definition of all helper functions required. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- * Include standard header files * -------------------------------------------------------------------- */ #include<math.h> /* ---------------------------------------------------------------------- * Include project header files * -------------------------------------------------------------------- */ #include "math_helper.h" /** * @brief Caluclation of SNR * @param[in] pRef Pointer to the reference buffer * @param[in] pTest Pointer to the test buffer * @param[in] buffSize total number of samples * @return SNR * The function Caluclates signal to noise ratio for the reference output * and test output */ float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize) { float EnergySignal = 0.0, EnergyError = 0.0; uint32_t i; float SNR; int temp; int *test; for (i = 0; i < buffSize; i++) { /* Checking for a NAN value in pRef array */ test = (int *)(&pRef[i]); temp = *test; if (temp == 0x7FC00000) { return(0); } /* Checking for a NAN value in pTest array */ test = (int *)(&pTest[i]); temp = *test; if (temp == 0x7FC00000) { return(0); } EnergySignal += pRef[i] * pRef[i]; EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]); } /* Checking for a NAN value in EnergyError */ test = (int *)(&EnergyError); temp = *test; if (temp == 0x7FC00000) { return(0); } SNR = 10 * log10 (EnergySignal / EnergyError); return (SNR); } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q15 (q15_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Converts float to fixed in q12.20 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to outputbuffer * @param[in] numSamples number of samples in the input buffer * @return none * The function converts floating point values to fixed point(q12.20) values */ void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1048576.0f corresponds to pow(2, 20) */ pOut[i] = (q31_t) (pIn[i] * 1048576.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 1.0) { pOut[i] = 0x000FFFFF; } } } /** * @brief Compare MATLAB Reference Output and ARM Test output * @param[in] pIn Pointer to Ref buffer * @param[in] pOut Pointer to Test buffer * @param[in] numSamples number of samples in the buffer * @return maximum difference */ uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t *pOut, uint32_t numSamples) { uint32_t i; int32_t diff, diffCrnt = 0; uint32_t maxDiff = 0; for (i = 0; i < numSamples; i++) { diff = pIn[i] - pOut[i]; diffCrnt = (diff > 0) ? diff : -diff; if (diffCrnt > maxDiff) { maxDiff = diffCrnt; } } return(maxDiff); } /** * @brief Compare MATLAB Reference Output and ARM Test output * @param[in] pIn Pointer to Ref buffer * @param[in] pOut Pointer to Test buffer * @param[in] numSamples number of samples in the buffer * @return maximum difference */ uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; int32_t diff, diffCrnt = 0; uint32_t maxDiff = 0; for (i = 0; i < numSamples; i++) { diff = pIn[i] - pOut[i]; diffCrnt = (diff > 0) ? diff : -diff; if (diffCrnt > maxDiff) { maxDiff = diffCrnt; } } return(maxDiff); } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q31 (q31_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q7 (q7_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Caluclates number of guard bits * @param[in] num_adds number of additions * @return guard bits * The function Caluclates the number of guard bits * depending on the numtaps */ uint32_t arm_calc_guard_bits (uint32_t num_adds) { uint32_t i = 1, j = 0; if (num_adds == 1) { return (0); } while (i < num_adds) { i = i * 2; j++; } return (j); } /** * @brief Apply guard bits to buffer * @param[in,out] pIn pointer to input buffer * @param[in] numSamples number of samples in the input buffer * @param[in] guard_bits guard bits * @return none */ void arm_apply_guard_bits (float32_t *pIn, uint32_t numSamples, uint32_t guard_bits) { uint32_t i; for (i = 0; i < numSamples; i++) { pIn[i] = pIn[i] * arm_calc_2pow(guard_bits); } } /** * @brief Calculates pow(2, numShifts) * @param[in] numShifts number of shifts * @return pow(2, numShifts) */ uint32_t arm_calc_2pow(uint32_t numShifts) { uint32_t i, val = 1; for (i = 0; i < numShifts; i++) { val = val * 2; } return(val); } /** * @brief Converts float to fixed q14 * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q14 (float *pIn, q15_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 16384.0f corresponds to pow(2, 14) */ pOut[i] = (q15_t) (pIn[i] * 16384.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 2.0) { pOut[i] = 0x7FFF; } } } /** * @brief Converts float to fixed q30 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q30 (float *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1073741824.0f corresponds to pow(2, 30) */ pOut[i] = (q31_t) (pIn[i] * 1073741824.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 2.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Converts float to fixed q30 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q29 (float *pIn, q31_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1073741824.0f corresponds to pow(2, 30) */ pOut[i] = (q31_t) (pIn[i] * 536870912.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 4.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Converts float to fixed q28 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q28 (float *pIn, q31_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 268435456.0f corresponds to pow(2, 28) */ pOut[i] = (q31_t) (pIn[i] * 268435456.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 8.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Clip the float values to +/- 1 * @param[in,out] pIn input buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_clip_f32 (float *pIn, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { if (pIn[i] > 1.0f) { pIn[i] = 1.0; } else if ( pIn[i] < -1.0f) { pIn[i] = -1.0; } } }
11,228
C
23.044968
77
0.583363
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/math_helper.h
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2013 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * * Title: math_helper.h * * Description: Prototypes of all helper functions required. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ #include "arm_math.h" #ifndef MATH_HELPER_H #define MATH_HELPER_H float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize); void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples); void arm_provide_guard_bits_q15(q15_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_provide_guard_bits_q31(q31_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_float_to_q14(float *pIn, q15_t *pOut, uint32_t numSamples); void arm_float_to_q29(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_float_to_q28(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_float_to_q30(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_clip_f32(float *pIn, uint32_t numSamples); uint32_t arm_calc_guard_bits(uint32_t num_adds); void arm_apply_guard_bits (float32_t * pIn, uint32_t numSamples, uint32_t guard_bits); uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples); uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t *pOut, uint32_t numSamples); uint32_t arm_calc_2pow(uint32_t guard_bits); #endif
3,022
C
46.234374
91
0.705824
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/RTE/Device/ARMCM3/system_ARMCM3.c
/**************************************************************************//** * @file system_ARMCM3.c * @brief CMSIS Device System Source File for * ARMCM3 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM3.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,428
C
34.202898
80
0.422158
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/RTE/Device/ARMCM0/system_ARMCM0.c
/**************************************************************************//** * @file system_ARMCM0.c * @brief CMSIS Device System Source File for * ARMCM0 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM0.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { SystemCoreClock = SYSTEM_CLOCK; }
2,063
C
35.210526
80
0.435773
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/RTE/Device/ARMCM4_FP/system_ARMCM4.c
/**************************************************************************//** * @file system_ARMCM4.c * @brief CMSIS Device System Source File for * ARMCM4 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined (ARMCM4) #include "ARMCM4.h" #elif defined (ARMCM4_FP) #include "ARMCM4_FP.h" #else #error device not specified! #endif /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined (__FPU_USED) && (__FPU_USED == 1U) SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ (3U << 11U*2U) ); /* enable CP11 Full Access */ #endif #ifdef UNALIGNED_SUPPORT_DISABLE SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,829
C
32.690476
80
0.444327
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_graphic_equalizer_example/RTE/Device/ARMCM7_SP/system_ARMCM7.c
/**************************************************************************//** * @file system_ARMCM7.c * @brief CMSIS Device System Source File for * ARMCM7 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined (ARMCM7) #include "ARMCM7.h" #elif defined (ARMCM7_SP) #include "ARMCM7_SP.h" #elif defined (ARMCM7_DP) #include "ARMCM7_DP.h" #else #error device not specified! #endif /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined (__FPU_USED) && (__FPU_USED == 1U) SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ (3U << 11U*2U) ); /* enable CP11 Full Access */ #endif #ifdef UNALIGNED_SUPPORT_DISABLE SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,880
C
32.5
80
0.448611
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_variance_example/arm_variance_example_f32.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * Title: arm_variance_example_f32.c * * Description: Example code demonstrating variance calculation of input sequence. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /** * @ingroup groupExamples */ /** * @defgroup VarianceExample Variance Example * * \par Description: * \par * Demonstrates the use of Basic Math and Support Functions to calculate the variance of an * input sequence with N samples. Uniformly distributed white noise is taken as input. * * \par Algorithm: * \par * The variance of a sequence is the mean of the squared deviation of the sequence from its mean. * \par * This is denoted by the following equation: * <pre> variance = ((x[0] - x') * (x[0] - x') + (x[1] - x') * (x[1] - x') + ... + * (x[n-1] - x') * (x[n-1] - x')) / (N-1)</pre> * where, <code>x[n]</code> is the input sequence, <code>N</code> is the number of input samples, and * <code>x'</code> is the mean value of the input sequence, <code>x[n]</code>. * \par * The mean value <code>x'</code> is defined as: * <pre> x' = (x[0] + x[1] + ... + x[n-1]) / N</pre> * * \par Block Diagram: * \par * \image html Variance.gif * * * \par Variables Description: * \par * \li \c testInput_f32 points to the input data * \li \c wire1, \c wir2, \c wire3 temporary buffers * \li \c blockSize number of samples processed at a time * \li \c refVarianceOut reference variance value * * \par CMSIS DSP Software Library Functions Used: * \par * - arm_dot_prod_f32() * - arm_mult_f32() * - arm_sub_f32() * - arm_fill_f32() * - arm_copy_f32() * * <b> Refer </b> * \link arm_variance_example_f32.c \endlink * */ /** \example arm_variance_example_f32.c */ #include <math.h> #include "arm_math.h" /* ---------------------------------------------------------------------- * Defines each of the tests performed * ------------------------------------------------------------------- */ #define MAX_BLOCKSIZE 32 #define DELTA (0.000001f) /* ---------------------------------------------------------------------- * Declare I/O buffers * ------------------------------------------------------------------- */ float32_t wire1[MAX_BLOCKSIZE]; float32_t wire2[MAX_BLOCKSIZE]; float32_t wire3[MAX_BLOCKSIZE]; /* ---------------------------------------------------------------------- * Test input data for Floating point Variance example for 32-blockSize * Generated by the MATLAB randn() function * ------------------------------------------------------------------- */ float32_t testInput_f32[32] = { -0.432564811528221, -1.665584378238097, 0.125332306474831, 0.287676420358549, -1.146471350681464, 1.190915465642999, 1.189164201652103, -0.037633276593318, 0.327292361408654, 0.174639142820925, -0.186708577681439, 0.725790548293303, -0.588316543014189, 2.183185818197101, -0.136395883086596, 0.113931313520810, 1.066768211359189, 0.059281460523605, -0.095648405483669, -0.832349463650022, 0.294410816392640, -1.336181857937804, 0.714324551818952, 1.623562064446271, -0.691775701702287, 0.857996672828263, 1.254001421602532, -1.593729576447477, -1.440964431901020, 0.571147623658178, -0.399885577715363, 0.689997375464345 }; /* ---------------------------------------------------------------------- * Declare Global variables * ------------------------------------------------------------------- */ uint32_t blockSize = 32; float32_t refVarianceOut = 0.903941793931839; /* ---------------------------------------------------------------------- * Variance calculation test * ------------------------------------------------------------------- */ int32_t main(void) { arm_status status; float32_t mean, oneByBlockSize; float32_t variance; float32_t diff; status = ARM_MATH_SUCCESS; #if defined(FILEIO) printf("START\n"); #endif /* Calculation of mean value of input */ /* x' = 1/blockSize * (x(0)* 1 + x(1) * 1 + ... + x(n-1) * 1) */ /* Fill wire1 buffer with 1.0 value */ arm_fill_f32(1.0, wire1, blockSize); /* Calculate the dot product of wire1 and wire2 */ /* (x(0)* 1 + x(1) * 1 + ...+ x(n-1) * 1) */ arm_dot_prod_f32(testInput_f32, wire1, blockSize, &mean); /* Calculation of 1/blockSize */ oneByBlockSize = 1.0 / (blockSize); /* 1/blockSize * (x(0)* 1 + x(1) * 1 + ... + x(n-1) * 1) */ arm_mult_f32(&mean, &oneByBlockSize, &mean, 1); /* Calculation of variance value of input */ /* (1/blockSize) * (x(0) - x') * (x(0) - x') + (x(1) - x') * (x(1) - x') + ... + (x(n-1) - x') * (x(n-1) - x') */ /* Fill wire2 with mean value x' */ arm_fill_f32(mean, wire2, blockSize); /* wire3 contains (x-x') */ arm_sub_f32(testInput_f32, wire2, wire3, blockSize); /* wire2 contains (x-x') */ arm_copy_f32(wire3, wire2, blockSize); /* (x(0) - x') * (x(0) - x') + (x(1) - x') * (x(1) - x') + ... + (x(n-1) - x') * (x(n-1) - x') */ arm_dot_prod_f32(wire2, wire3, blockSize, &variance); /* Calculation of 1/blockSize */ oneByBlockSize = 1.0 / (blockSize - 1); /* Calculation of variance */ arm_mult_f32(&variance, &oneByBlockSize, &variance, 1); /* absolute value of difference between ref and test */ diff = fabsf(refVarianceOut - variance); /* Comparison of variance value with reference */ if (diff > DELTA) { status = ARM_MATH_TEST_FAILURE; } #if !defined(FILEIO) if ( status != ARM_MATH_SUCCESS) { while (1); } while (1); /* main function does not return */ #else if (status == ARM_MATH_SUCCESS) { printf("SUCCESS\n"); } else { printf("FAILURE\n"); } #endif } /** \endlink */
7,428
C
31.871681
129
0.582795
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_variance_example/RTE/Device/ARMCM3/system_ARMCM3.c
/**************************************************************************//** * @file system_ARMCM3.c * @brief CMSIS Device System Source File for * ARMCM3 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM3.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,428
C
34.202898
80
0.422158
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_variance_example/RTE/Device/ARMCM0/system_ARMCM0.c
/**************************************************************************//** * @file system_ARMCM0.c * @brief CMSIS Device System Source File for * ARMCM0 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM0.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { SystemCoreClock = SYSTEM_CLOCK; }
2,063
C
35.210526
80
0.435773
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_variance_example/RTE/Device/ARMCM4_FP/system_ARMCM4.c
/**************************************************************************//** * @file system_ARMCM4.c * @brief CMSIS Device System Source File for * ARMCM4 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined (ARMCM4) #include "ARMCM4.h" #elif defined (ARMCM4_FP) #include "ARMCM4_FP.h" #else #error device not specified! #endif /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined (__FPU_USED) && (__FPU_USED == 1U) SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ (3U << 11U*2U) ); /* enable CP11 Full Access */ #endif #ifdef UNALIGNED_SUPPORT_DISABLE SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,829
C
32.690476
80
0.444327
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_variance_example/RTE/Device/ARMCM7_SP/system_ARMCM7.c
/**************************************************************************//** * @file system_ARMCM7.c * @brief CMSIS Device System Source File for * ARMCM7 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #if defined (ARMCM7) #include "ARMCM7.h" #elif defined (ARMCM7_SP) #include "ARMCM7_SP.h" #elif defined (ARMCM7_DP) #include "ARMCM7_DP.h" #else #error device not specified! #endif /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif #if defined (__FPU_USED) && (__FPU_USED == 1U) SCB->CPACR |= ((3U << 10U*2U) | /* enable CP10 Full Access */ (3U << 11U*2U) ); /* enable CP11 Full Access */ #endif #ifdef UNALIGNED_SUPPORT_DISABLE SCB->CCR |= SCB_CCR_UNALIGN_TRP_Msk; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,880
C
32.5
80
0.448611
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_linear_interp_example/math_helper.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 b * * Project: CMSIS DSP Library * * Title: math_helper.c * * Description: Definition of all helper functions required. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- * Include standard header files * -------------------------------------------------------------------- */ #include<math.h> /* ---------------------------------------------------------------------- * Include project header files * -------------------------------------------------------------------- */ #include "math_helper.h" /** * @brief Caluclation of SNR * @param[in] pRef Pointer to the reference buffer * @param[in] pTest Pointer to the test buffer * @param[in] buffSize total number of samples * @return SNR * The function Caluclates signal to noise ratio for the reference output * and test output */ float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize) { float EnergySignal = 0.0, EnergyError = 0.0; uint32_t i; float SNR; int temp; int *test; for (i = 0; i < buffSize; i++) { /* Checking for a NAN value in pRef array */ test = (int *)(&pRef[i]); temp = *test; if (temp == 0x7FC00000) { return(0); } /* Checking for a NAN value in pTest array */ test = (int *)(&pTest[i]); temp = *test; if (temp == 0x7FC00000) { return(0); } EnergySignal += pRef[i] * pRef[i]; EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]); } /* Checking for a NAN value in EnergyError */ test = (int *)(&EnergyError); temp = *test; if (temp == 0x7FC00000) { return(0); } SNR = 10 * log10 (EnergySignal / EnergyError); return (SNR); } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q15 (q15_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Converts float to fixed in q12.20 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to outputbuffer * @param[in] numSamples number of samples in the input buffer * @return none * The function converts floating point values to fixed point(q12.20) values */ void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1048576.0f corresponds to pow(2, 20) */ pOut[i] = (q31_t) (pIn[i] * 1048576.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 1.0) { pOut[i] = 0x000FFFFF; } } } /** * @brief Compare MATLAB Reference Output and ARM Test output * @param[in] pIn Pointer to Ref buffer * @param[in] pOut Pointer to Test buffer * @param[in] numSamples number of samples in the buffer * @return maximum difference */ uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t *pOut, uint32_t numSamples) { uint32_t i; int32_t diff, diffCrnt = 0; uint32_t maxDiff = 0; for (i = 0; i < numSamples; i++) { diff = pIn[i] - pOut[i]; diffCrnt = (diff > 0) ? diff : -diff; if (diffCrnt > maxDiff) { maxDiff = diffCrnt; } } return(maxDiff); } /** * @brief Compare MATLAB Reference Output and ARM Test output * @param[in] pIn Pointer to Ref buffer * @param[in] pOut Pointer to Test buffer * @param[in] numSamples number of samples in the buffer * @return maximum difference */ uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; int32_t diff, diffCrnt = 0; uint32_t maxDiff = 0; for (i = 0; i < numSamples; i++) { diff = pIn[i] - pOut[i]; diffCrnt = (diff > 0) ? diff : -diff; if (diffCrnt > maxDiff) { maxDiff = diffCrnt; } } return(maxDiff); } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q31 (q31_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Provide guard bits for Input buffer * @param[in,out] input_buf Pointer to input buffer * @param[in] blockSize block Size * @param[in] guard_bits guard bits * @return none * The function Provides the guard bits for the buffer * to avoid overflow */ void arm_provide_guard_bits_q7 (q7_t * input_buf, uint32_t blockSize, uint32_t guard_bits) { uint32_t i; for (i = 0; i < blockSize; i++) { input_buf[i] = input_buf[i] >> guard_bits; } } /** * @brief Caluclates number of guard bits * @param[in] num_adds number of additions * @return guard bits * The function Caluclates the number of guard bits * depending on the numtaps */ uint32_t arm_calc_guard_bits (uint32_t num_adds) { uint32_t i = 1, j = 0; if (num_adds == 1) { return (0); } while (i < num_adds) { i = i * 2; j++; } return (j); } /** * @brief Apply guard bits to buffer * @param[in,out] pIn pointer to input buffer * @param[in] numSamples number of samples in the input buffer * @param[in] guard_bits guard bits * @return none */ void arm_apply_guard_bits (float32_t *pIn, uint32_t numSamples, uint32_t guard_bits) { uint32_t i; for (i = 0; i < numSamples; i++) { pIn[i] = pIn[i] * arm_calc_2pow(guard_bits); } } /** * @brief Calculates pow(2, numShifts) * @param[in] numShifts number of shifts * @return pow(2, numShifts) */ uint32_t arm_calc_2pow(uint32_t numShifts) { uint32_t i, val = 1; for (i = 0; i < numShifts; i++) { val = val * 2; } return(val); } /** * @brief Converts float to fixed q14 * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q14 (float *pIn, q15_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 16384.0f corresponds to pow(2, 14) */ pOut[i] = (q15_t) (pIn[i] * 16384.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 2.0) { pOut[i] = 0x7FFF; } } } /** * @brief Converts float to fixed q30 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q30 (float *pIn, q31_t * pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1073741824.0f corresponds to pow(2, 30) */ pOut[i] = (q31_t) (pIn[i] * 1073741824.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 2.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Converts float to fixed q30 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q29 (float *pIn, q31_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 1073741824.0f corresponds to pow(2, 30) */ pOut[i] = (q31_t) (pIn[i] * 536870912.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 4.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Converts float to fixed q28 format * @param[in] pIn pointer to input buffer * @param[out] pOut pointer to output buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_float_to_q28 (float *pIn, q31_t *pOut, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { /* 268435456.0f corresponds to pow(2, 28) */ pOut[i] = (q31_t) (pIn[i] * 268435456.0f); pOut[i] += pIn[i] > 0 ? 0.5 : -0.5; if (pIn[i] == (float) 8.0) { pOut[i] = 0x7FFFFFFF; } } } /** * @brief Clip the float values to +/- 1 * @param[in,out] pIn input buffer * @param[in] numSamples number of samples in the buffer * @return none * The function converts floating point values to fixed point values */ void arm_clip_f32 (float *pIn, uint32_t numSamples) { uint32_t i; for (i = 0; i < numSamples; i++) { if (pIn[i] > 1.0f) { pIn[i] = 1.0; } else if ( pIn[i] < -1.0f) { pIn[i] = -1.0; } } }
11,228
C
23.044968
77
0.583363
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_linear_interp_example/arm_linear_interp_example_f32.c
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2012 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * Title: arm_linear_interp_example_f32.c * * Description: Example code demonstrating usage of sin function * and uses linear interpolation to get higher precision * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ /** * @ingroup groupExamples */ /** * @defgroup LinearInterpExample Linear Interpolate Example * * <b> CMSIS DSP Software Library -- Linear Interpolate Example </b> * * <b> Description </b> * This example demonstrates usage of linear interpolate modules and fast math modules. * Method 1 uses fast math sine function to calculate sine values using cubic interpolation and method 2 uses * linear interpolation function and results are compared to reference output. * Example shows linear interpolation function can be used to get higher precision compared to fast math sin calculation. * * \par Block Diagram: * \par * \image html linearInterpExampleMethod1.gif "Method 1: Sine caluclation using fast math" * \par * \image html linearInterpExampleMethod2.gif "Method 2: Sine caluclation using interpolation function" * * \par Variables Description: * \par * \li \c testInputSin_f32 points to the input values for sine calculation * \li \c testRefSinOutput32_f32 points to the reference values caculated from sin() matlab function * \li \c testOutput points to output buffer calculation from cubic interpolation * \li \c testLinIntOutput points to output buffer calculation from linear interpolation * \li \c snr1 Signal to noise ratio for reference and cubic interpolation output * \li \c snr2 Signal to noise ratio for reference and linear interpolation output * * \par CMSIS DSP Software Library Functions Used: * \par * - arm_sin_f32() * - arm_linear_interp_f32() * * <b> Refer </b> * \link arm_linear_interp_example_f32.c \endlink * */ /** \example arm_linear_interp_example_f32.c */ #include "arm_math.h" #include "math_helper.h" #define SNR_THRESHOLD 90 #define TEST_LENGTH_SAMPLES 10 #define XSPACING (0.00005f) /* ---------------------------------------------------------------------- * Test input data for F32 SIN function * Generated by the MATLAB rand() function * randn('state', 0) * xi = (((1/4.18318581819710)* randn(blockSize, 1) * 2* pi)); * --------------------------------------------------------------------*/ float32_t testInputSin_f32[TEST_LENGTH_SAMPLES] = { -0.649716504673081170, -2.501723745497831200, 0.188250329003310100, 0.432092748487532540, -1.722010988459680800, 1.788766476323060600, 1.786136060975809500, -0.056525543169408797, 0.491596272728153760, 0.262309671126153390 }; /*------------------------------------------------------------------------------ * Reference out of SIN F32 function for Block Size = 10 * Calculated from sin(testInputSin_f32) *------------------------------------------------------------------------------*/ float32_t testRefSinOutput32_f32[TEST_LENGTH_SAMPLES] = { -0.604960695383043530, -0.597090287967934840, 0.187140422442966500, 0.418772124875992690, -0.988588831792106880, 0.976338412038794010, 0.976903856413481100, -0.056495446835214236, 0.472033731854734240, 0.259311907228582830 }; /*------------------------------------------------------------------------------ * Method 1: Test out Buffer Calculated from Cubic Interpolation *------------------------------------------------------------------------------*/ float32_t testOutput[TEST_LENGTH_SAMPLES]; /*------------------------------------------------------------------------------ * Method 2: Test out buffer Calculated from Linear Interpolation *------------------------------------------------------------------------------*/ float32_t testLinIntOutput[TEST_LENGTH_SAMPLES]; /*------------------------------------------------------------------------------ * External table used for linear interpolation *------------------------------------------------------------------------------*/ extern float arm_linear_interep_table[188495]; /* ---------------------------------------------------------------------- * Global Variables for caluclating SNR's for Method1 & Method 2 * ------------------------------------------------------------------- */ float32_t snr1; float32_t snr2; /* ---------------------------------------------------------------------------- * Calculation of Sine values from Cubic Interpolation and Linear interpolation * ---------------------------------------------------------------------------- */ int32_t main(void) { uint32_t i; arm_status status; arm_linear_interp_instance_f32 S = {188495, -3.141592653589793238, XSPACING, &arm_linear_interep_table[0]}; /*------------------------------------------------------------------------------ * Method 1: Test out Calculated from Cubic Interpolation *------------------------------------------------------------------------------*/ for(i=0; i< TEST_LENGTH_SAMPLES; i++) { testOutput[i] = arm_sin_f32(testInputSin_f32[i]); } /*------------------------------------------------------------------------------ * Method 2: Test out Calculated from Cubic Interpolation and Linear interpolation *------------------------------------------------------------------------------*/ for(i=0; i< TEST_LENGTH_SAMPLES; i++) { testLinIntOutput[i] = arm_linear_interp_f32(&S, testInputSin_f32[i]); } /*------------------------------------------------------------------------------ * SNR calculation for method 1 *------------------------------------------------------------------------------*/ snr1 = arm_snr_f32(testRefSinOutput32_f32, testOutput, 2); /*------------------------------------------------------------------------------ * SNR calculation for method 2 *------------------------------------------------------------------------------*/ snr2 = arm_snr_f32(testRefSinOutput32_f32, testLinIntOutput, 2); /*------------------------------------------------------------------------------ * Initialise status depending on SNR calculations *------------------------------------------------------------------------------*/ if ( snr2 > snr1) { status = ARM_MATH_SUCCESS; } else { status = ARM_MATH_TEST_FAILURE; } /* ---------------------------------------------------------------------- ** Loop here if the signals fail the PASS check. ** This denotes a test failure ** ------------------------------------------------------------------- */ if ( status != ARM_MATH_SUCCESS) { while (1); } while (1); /* main function does not return */ } /** \endlink */
8,528
C
40.604878
121
0.529667
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_linear_interp_example/math_helper.h
/* ---------------------------------------------------------------------- * Copyright (C) 2010-2013 ARM Limited. All rights reserved. * * $Date: 17. January 2013 * $Revision: V1.4.0 * * Project: CMSIS DSP Library * * Title: math_helper.h * * Description: Prototypes of all helper functions required. * * Target Processor: Cortex-M4/Cortex-M3 * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * - Neither the name of ARM LIMITED nor the names of its contributors * may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * -------------------------------------------------------------------- */ #include "arm_math.h" #ifndef MATH_HELPER_H #define MATH_HELPER_H float arm_snr_f32(float *pRef, float *pTest, uint32_t buffSize); void arm_float_to_q12_20(float *pIn, q31_t * pOut, uint32_t numSamples); void arm_provide_guard_bits_q15(q15_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_provide_guard_bits_q31(q31_t *input_buf, uint32_t blockSize, uint32_t guard_bits); void arm_float_to_q14(float *pIn, q15_t *pOut, uint32_t numSamples); void arm_float_to_q29(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_float_to_q28(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_float_to_q30(float *pIn, q31_t *pOut, uint32_t numSamples); void arm_clip_f32(float *pIn, uint32_t numSamples); uint32_t arm_calc_guard_bits(uint32_t num_adds); void arm_apply_guard_bits (float32_t * pIn, uint32_t numSamples, uint32_t guard_bits); uint32_t arm_compare_fixed_q15(q15_t *pIn, q15_t * pOut, uint32_t numSamples); uint32_t arm_compare_fixed_q31(q31_t *pIn, q31_t *pOut, uint32_t numSamples); uint32_t arm_calc_2pow(uint32_t guard_bits); #endif
3,022
C
46.234374
91
0.705824
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_linear_interp_example/RTE/Device/ARMCM3/system_ARMCM3.c
/**************************************************************************//** * @file system_ARMCM3.c * @brief CMSIS Device System Source File for * ARMCM3 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM3.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- Externals *----------------------------------------------------------------------------*/ #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) extern uint32_t __Vectors; #endif /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { #if defined (__VTOR_PRESENT) && (__VTOR_PRESENT == 1U) SCB->VTOR = (uint32_t) &__Vectors; #endif SystemCoreClock = SYSTEM_CLOCK; }
2,428
C
34.202898
80
0.422158
Tbarkin121/GuardDog/stm32/MotorDrive/LegDay/Drivers/CMSIS/DSP/Examples/ARM/arm_linear_interp_example/RTE/Device/ARMCM0/system_ARMCM0.c
/**************************************************************************//** * @file system_ARMCM0.c * @brief CMSIS Device System Source File for * ARMCM0 Device * @version V5.3.1 * @date 09. July 2018 ******************************************************************************/ /* * Copyright (c) 2009-2018 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. * You may obtain a copy of the License at * * www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an AS IS BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "ARMCM0.h" /*---------------------------------------------------------------------------- Define clocks *----------------------------------------------------------------------------*/ #define XTAL (50000000UL) /* Oscillator frequency */ #define SYSTEM_CLOCK (XTAL / 2U) /*---------------------------------------------------------------------------- System Core Clock Variable *----------------------------------------------------------------------------*/ uint32_t SystemCoreClock = SYSTEM_CLOCK; /* System Core Clock Frequency */ /*---------------------------------------------------------------------------- System Core Clock update function *----------------------------------------------------------------------------*/ void SystemCoreClockUpdate (void) { SystemCoreClock = SYSTEM_CLOCK; } /*---------------------------------------------------------------------------- System initialization function *----------------------------------------------------------------------------*/ void SystemInit (void) { SystemCoreClock = SYSTEM_CLOCK; }
2,063
C
35.210526
80
0.435773