arm variance example f32 8c source


CMSIS DSP Software Library: arm_variance_example_f32.c Source File Main Page Modules Data Structures Files Examples File List Globals arm_variance_example_f32.c Go to the documentation of this file.00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2010 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 29. November 2010 00005 * $Revision: V1.0.3 00006 * 00007 * Project: CMSIS DSP Library 00008 * Title: arm_variance_example_f32.c 00009 * 00010 * Description: Example code demonstrating variance calculation of input sequence. 00011 * 00012 * Target Processor: Cortex-M4/Cortex-M3 00013 * 00014 * 00015 * Version 1.0.3 2010/11/29 00016 * Re-organized the CMSIS folders and updated documentation. 00017 * 00018 * Version 1.0.1 2010/10/05 KK 00019 * Production release and review comments incorporated. 00020 * 00021 * Version 1.0.0 2010/09/20 KK 00022 * Production release and review comments incorporated. 00023 * ------------------------------------------------------------------- */ 00024 00077 #include <math.h> 00078 #include "arm_math.h" 00079 00080 /* ---------------------------------------------------------------------- 00081 * Defines each of the tests performed 00082 * ------------------------------------------------------------------- */ 00083 #define MAX_BLOCKSIZE 32 00084 #define DELTA (0.000001f) 00085 00086 00087 /* ---------------------------------------------------------------------- 00088 * Declare I/O buffers 00089 * ------------------------------------------------------------------- */ 00090 float32_t wire1[MAX_BLOCKSIZE]; 00091 float32_t wire2[MAX_BLOCKSIZE]; 00092 float32_t wire3[MAX_BLOCKSIZE]; 00093 00094 /* ---------------------------------------------------------------------- 00095 * Test input data for Floating point Variance example for 32-blockSize 00096 * Generated by the MATLAB randn() function 00097 * ------------------------------------------------------------------- */ 00098 00099 float32_t testInput_f32[32] = 00100 { 00101 -0.432564811528221, -1.665584378238097, 0.125332306474831, 0.287676420358549, 00102 -1.146471350681464, 1.190915465642999, 1.189164201652103, -0.037633276593318, 00103 0.327292361408654, 0.174639142820925, -0.186708577681439, 0.725790548293303, 00104 -0.588316543014189, 2.183185818197101, -0.136395883086596, 0.113931313520810, 00105 1.066768211359189, 0.059281460523605, -0.095648405483669, -0.832349463650022, 00106 0.294410816392640, -1.336181857937804, 0.714324551818952, 1.623562064446271, 00107 -0.691775701702287, 0.857996672828263, 1.254001421602532, -1.593729576447477, 00108 -1.440964431901020, 0.571147623658178, -0.399885577715363, 0.689997375464345 00109 00110 }; 00111 00112 /* ---------------------------------------------------------------------- 00113 * Declare Global variables 00114 * ------------------------------------------------------------------- */ 00115 uint32_t blockSize = 32; 00116 float32_t refVarianceOut = 0.903941793931839; 00117 00118 /* ---------------------------------------------------------------------- 00119 * Variance calculation test 00120 * ------------------------------------------------------------------- */ 00121 00122 int32_t main(void) 00123 { 00124 arm_status status; 00125 float32_t mean, oneByBlockSize; 00126 float32_t variance; 00127 float32_t diff; 00128 00129 status = ARM_MATH_SUCCESS; 00130 00131 /* Calculation of mean value of input */ 00132 00133 /* x' = 1/blockSize * (x(0)* 1 + x(1) * 1 + ... + x(n-1) * 1) */ 00134 00135 /* Fill wire1 buffer with 1.0 value */ 00136 arm_fill_f32(1.0, wire1, blockSize); 00137 00138 /* Calculate the dot product of wire1 and wire2 */ 00139 /* (x(0)* 1 + x(1) * 1 + ...+ x(n-1) * 1) */ 00140 arm_dot_prod_f32(testInput_f32, wire1, blockSize, &mean); 00141 00142 /* Calculation of 1/blockSize */ 00143 oneByBlockSize = 1.0 / (blockSize); 00144 00145 /* 1/blockSize * (x(0)* 1 + x(1) * 1 + ... + x(n-1) * 1) */ 00146 arm_mult_f32(&mean, &oneByBlockSize, &mean, 1); 00147 00148 00149 /* Calculation of variance value of input */ 00150 00151 /* (1/blockSize) * (x(0) - x') * (x(0) - x') + (x(1) - x') * (x(1) - x') + ... + (x(n-1) - x') * (x(n-1) - x') */ 00152 00153 /* Fill wire2 with mean value x' */ 00154 arm_fill_f32(mean, wire2, blockSize); 00155 00156 /* wire3 contains (x-x') */ 00157 arm_sub_f32(testInput_f32, wire2, wire3, blockSize); 00158 00159 /* wire2 contains (x-x') */ 00160 arm_copy_f32(wire3, wire2, blockSize); 00161 00162 /* (x(0) - x') * (x(0) - x') + (x(1) - x') * (x(1) - x') + ... + (x(n-1) - x') * (x(n-1) - x') */ 00163 arm_dot_prod_f32(wire2, wire3, blockSize, &variance); 00164 00165 /* Calculation of 1/blockSize */ 00166 oneByBlockSize = 1.0 / (blockSize - 1); 00167 00168 /* Calculation of variance */ 00169 arm_mult_f32(&variance, &oneByBlockSize, &variance, 1); 00170 00171 /* absolute value of difference between ref and test */ 00172 diff = fabsf(refVarianceOut - variance); 00173 00174 /* Comparison of variance value with reference */ 00175 if(diff > DELTA) 00176 { 00177 status = ARM_MATH_TEST_FAILURE; 00178 } 00179 00180 if( status != ARM_MATH_SUCCESS) 00181 { 00182 while(1); 00183 } 00184 } 00185  All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines Generated on Mon Nov 29 2010 17:19:57 for CMSIS DSP Software Library by  1.7.2

Wyszukiwarka

Podobne podstrony:
arm variance example ?2?
arm dotproduct example ?2? source
arm fir example ?2? source
arm convolution example ?2? source
arm matrix example ?2? source
arm linear interp example ?2? source
arm signal converge example ?2? source
arm class marks example ?2? source
arm sin cos example ?2? source
arm sin cos example ?2? source
arm ?t bin example ?2? source
arm matrix example ?2?
arm cmplx mag ?2? source
arm fir interpolate ?2? source
arm mat trans ?2? source
arm fir lattice ?2? source
arm variance example?2? example
arm mat ?d ?2? source
arm mat sub ?2? source

więcej podobnych podstron