00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "arm_math.h"
00080 static const float32_t cosTable[259] = {
00081 0.999698817729949950f, 1.000000000000000000f, 0.999698817729949950f,
00082 0.998795449733734130f, 0.997290432453155520f, 0.995184719562530520f,
00083 0.992479562759399410f, 0.989176511764526370f,
00084 0.985277652740478520f, 0.980785250663757320f, 0.975702106952667240f,
00085 0.970031261444091800f, 0.963776051998138430f, 0.956940352916717530f,
00086 0.949528157711029050f, 0.941544055938720700f,
00087 0.932992815971374510f, 0.923879504203796390f, 0.914209783077239990f,
00088 0.903989315032958980f, 0.893224298954010010f, 0.881921291351318360f,
00089 0.870086967945098880f, 0.857728600502014160f,
00090 0.844853579998016360f, 0.831469595432281490f, 0.817584812641143800f,
00091 0.803207516670227050f, 0.788346409797668460f, 0.773010432720184330f,
00092 0.757208824157714840f, 0.740951120853424070f,
00093 0.724247097969055180f, 0.707106769084930420f, 0.689540565013885500f,
00094 0.671558976173400880f, 0.653172850608825680f, 0.634393274784088130f,
00095 0.615231573581695560f, 0.595699310302734380f,
00096 0.575808167457580570f, 0.555570244789123540f, 0.534997642040252690f,
00097 0.514102756977081300f, 0.492898195981979370f, 0.471396744251251220f,
00098 0.449611335992813110f, 0.427555084228515630f,
00099 0.405241310596466060f, 0.382683426141738890f, 0.359895050525665280f,
00100 0.336889863014221190f, 0.313681751489639280f, 0.290284663438797000f,
00101 0.266712754964828490f, 0.242980182170867920f,
00102 0.219101235270500180f, 0.195090323686599730f, 0.170961886644363400f,
00103 0.146730467677116390f, 0.122410677373409270f, 0.098017141222953796f,
00104 0.073564566671848297f, 0.049067676067352295f,
00105 0.024541229009628296f, 0.000000000000000061f, -0.024541229009628296f,
00106 -0.049067676067352295f, -0.073564566671848297f, -0.098017141222953796f,
00107 -0.122410677373409270f, -0.146730467677116390f,
00108 -0.170961886644363400f, -0.195090323686599730f, -0.219101235270500180f,
00109 -0.242980182170867920f, -0.266712754964828490f, -0.290284663438797000f,
00110 -0.313681751489639280f, -0.336889863014221190f,
00111 -0.359895050525665280f, -0.382683426141738890f, -0.405241310596466060f,
00112 -0.427555084228515630f, -0.449611335992813110f, -0.471396744251251220f,
00113 -0.492898195981979370f, -0.514102756977081300f,
00114 -0.534997642040252690f, -0.555570244789123540f, -0.575808167457580570f,
00115 -0.595699310302734380f, -0.615231573581695560f, -0.634393274784088130f,
00116 -0.653172850608825680f, -0.671558976173400880f,
00117 -0.689540565013885500f, -0.707106769084930420f, -0.724247097969055180f,
00118 -0.740951120853424070f, -0.757208824157714840f, -0.773010432720184330f,
00119 -0.788346409797668460f, -0.803207516670227050f,
00120 -0.817584812641143800f, -0.831469595432281490f, -0.844853579998016360f,
00121 -0.857728600502014160f, -0.870086967945098880f, -0.881921291351318360f,
00122 -0.893224298954010010f, -0.903989315032958980f,
00123 -0.914209783077239990f, -0.923879504203796390f, -0.932992815971374510f,
00124 -0.941544055938720700f, -0.949528157711029050f, -0.956940352916717530f,
00125 -0.963776051998138430f, -0.970031261444091800f,
00126 -0.975702106952667240f, -0.980785250663757320f, -0.985277652740478520f,
00127 -0.989176511764526370f, -0.992479562759399410f, -0.995184719562530520f,
00128 -0.997290432453155520f, -0.998795449733734130f,
00129 -0.999698817729949950f, -1.000000000000000000f, -0.999698817729949950f,
00130 -0.998795449733734130f, -0.997290432453155520f, -0.995184719562530520f,
00131 -0.992479562759399410f, -0.989176511764526370f,
00132 -0.985277652740478520f, -0.980785250663757320f, -0.975702106952667240f,
00133 -0.970031261444091800f, -0.963776051998138430f, -0.956940352916717530f,
00134 -0.949528157711029050f, -0.941544055938720700f,
00135 -0.932992815971374510f, -0.923879504203796390f, -0.914209783077239990f,
00136 -0.903989315032958980f, -0.893224298954010010f, -0.881921291351318360f,
00137 -0.870086967945098880f, -0.857728600502014160f,
00138 -0.844853579998016360f, -0.831469595432281490f, -0.817584812641143800f,
00139 -0.803207516670227050f, -0.788346409797668460f, -0.773010432720184330f,
00140 -0.757208824157714840f, -0.740951120853424070f,
00141 -0.724247097969055180f, -0.707106769084930420f, -0.689540565013885500f,
00142 -0.671558976173400880f, -0.653172850608825680f, -0.634393274784088130f,
00143 -0.615231573581695560f, -0.595699310302734380f,
00144 -0.575808167457580570f, -0.555570244789123540f, -0.534997642040252690f,
00145 -0.514102756977081300f, -0.492898195981979370f, -0.471396744251251220f,
00146 -0.449611335992813110f, -0.427555084228515630f,
00147 -0.405241310596466060f, -0.382683426141738890f, -0.359895050525665280f,
00148 -0.336889863014221190f, -0.313681751489639280f, -0.290284663438797000f,
00149 -0.266712754964828490f, -0.242980182170867920f,
00150 -0.219101235270500180f, -0.195090323686599730f, -0.170961886644363400f,
00151 -0.146730467677116390f, -0.122410677373409270f, -0.098017141222953796f,
00152 -0.073564566671848297f, -0.049067676067352295f,
00153 -0.024541229009628296f, -0.000000000000000184f, 0.024541229009628296f,
00154 0.049067676067352295f, 0.073564566671848297f, 0.098017141222953796f,
00155 0.122410677373409270f, 0.146730467677116390f,
00156 0.170961886644363400f, 0.195090323686599730f, 0.219101235270500180f,
00157 0.242980182170867920f, 0.266712754964828490f, 0.290284663438797000f,
00158 0.313681751489639280f, 0.336889863014221190f,
00159 0.359895050525665280f, 0.382683426141738890f, 0.405241310596466060f,
00160 0.427555084228515630f, 0.449611335992813110f, 0.471396744251251220f,
00161 0.492898195981979370f, 0.514102756977081300f,
00162 0.534997642040252690f, 0.555570244789123540f, 0.575808167457580570f,
00163 0.595699310302734380f, 0.615231573581695560f, 0.634393274784088130f,
00164 0.653172850608825680f, 0.671558976173400880f,
00165 0.689540565013885500f, 0.707106769084930420f, 0.724247097969055180f,
00166 0.740951120853424070f, 0.757208824157714840f, 0.773010432720184330f,
00167 0.788346409797668460f, 0.803207516670227050f,
00168 0.817584812641143800f, 0.831469595432281490f, 0.844853579998016360f,
00169 0.857728600502014160f, 0.870086967945098880f, 0.881921291351318360f,
00170 0.893224298954010010f, 0.903989315032958980f,
00171 0.914209783077239990f, 0.923879504203796390f, 0.932992815971374510f,
00172 0.941544055938720700f, 0.949528157711029050f, 0.956940352916717530f,
00173 0.963776051998138430f, 0.970031261444091800f,
00174 0.975702106952667240f, 0.980785250663757320f, 0.985277652740478520f,
00175 0.989176511764526370f, 0.992479562759399410f, 0.995184719562530520f,
00176 0.997290432453155520f, 0.998795449733734130f,
00177 0.999698817729949950f, 1.000000000000000000f, 0.999698817729949950f
00178 };
00179
00186 float32_t arm_cos_f32(
00187 float32_t x)
00188 {
00189 float32_t cosVal, fract, in;
00190 uint32_t index;
00191 uint32_t tableSize = (uint32_t) TABLE_SIZE;
00192 float32_t wa, wb, wc, wd;
00193 float32_t a, b, c, d;
00194 float32_t *tablePtr;
00195 int32_t n;
00196 float32_t fractsq, fractby2, fractby6, fractby3, fractsqby2;
00197 float32_t oneminusfractby2;
00198 float32_t frby2xfrsq, frby6xfrsq;
00199
00200
00201
00202 in = x * 0.159154943092f;
00203
00204
00205 n = (int32_t) in;
00206
00207
00208 if(x < 0.0f)
00209 {
00210 n = n - 1;
00211 }
00212
00213
00214 in = in - (float32_t) n;
00215
00216
00217 index = (uint32_t) (tableSize * in);
00218
00219
00220 fract = ((float32_t) tableSize * in) - (float32_t) index;
00221
00222
00223 tablePtr = (float32_t *) & cosTable[index];
00224
00225
00226 a = tablePtr[0];
00227 b = tablePtr[1];
00228 c = tablePtr[2];
00229 d = tablePtr[3];
00230
00231
00232 fractsq = fract * fract;
00233 fractby2 = fract * 0.5f;
00234 fractby6 = fract * 0.166666667f;
00235 fractby3 = fract * 0.3333333333333f;
00236 fractsqby2 = fractsq * 0.5f;
00237 frby2xfrsq = (fractby2) * fractsq;
00238 frby6xfrsq = (fractby6) * fractsq;
00239 oneminusfractby2 = 1.0f - fractby2;
00240 wb = fractsqby2 - fractby3;
00241 wc = (fractsqby2 + fract);
00242 wa = wb - frby6xfrsq;
00243 wb = frby2xfrsq - fractsq;
00244 cosVal = wa * a;
00245 wc = wc - frby2xfrsq;
00246 wd = (frby6xfrsq) - fractby6;
00247 wb = wb + oneminusfractby2;
00248
00249
00250 cosVal = (cosVal + (b * wb)) + ((c * wc) + (d * wd));
00251
00252
00253 return (cosVal);
00254
00255 }
00256