00001 /* ---------------------------------------------------------------------- 00002 * Copyright (C) 2011 ARM Limited. All rights reserved. 00003 * 00004 * $Date: 15. December 2011 00005 * $Revision: V2.0.0 00006 * 00007 * Project: Cortex-R4 DSP Library 00008 * Title: arm_class_marks_example_f32.c 00009 * 00010 * Description: Example code to calculate Minimum, Maximum 00011 * Mean, std and variance of marks obtained in a class 00012 * 00013 * Target Processor: Cortex-R4 00014 * 00015 * Version 2.0.0 2011/12/15 00016 * Final release. 00017 * 00018 * ---------------------------------------------------------------------------- */ 00019 00062 #include "arm_math.h" 00063 00064 #define USE_STATIC_INIT 00065 00066 /* ---------------------------------------------------------------------- 00067 ** Global defines 00068 ** ------------------------------------------------------------------- */ 00069 00070 #define TEST_LENGTH_SAMPLES (20*4) 00071 00072 /* ---------------------------------------------------------------------- 00073 ** List of Marks scored by 20 students for 4 subjects 00074 ** ------------------------------------------------------------------- */ 00075 const float32_t testMarks_f32[TEST_LENGTH_SAMPLES] = 00076 { 00077 42.000000, 37.000000, 81.000000, 28.000000, 00078 83.000000, 72.000000, 36.000000, 38.000000, 00079 32.000000, 51.000000, 63.000000, 64.000000, 00080 97.000000, 82.000000, 95.000000, 90.000000, 00081 66.000000, 51.000000, 54.000000, 42.000000, 00082 67.000000, 56.000000, 45.000000, 57.000000, 00083 67.000000, 69.000000, 35.000000, 52.000000, 00084 29.000000, 81.000000, 58.000000, 47.000000, 00085 38.000000, 76.000000, 100.000000, 29.000000, 00086 33.000000, 47.000000, 29.000000, 50.000000, 00087 34.000000, 41.000000, 61.000000, 46.000000, 00088 52.000000, 50.000000, 48.000000, 36.000000, 00089 47.000000, 55.000000, 44.000000, 40.000000, 00090 100.000000, 94.000000, 84.000000, 37.000000, 00091 32.000000, 71.000000, 47.000000, 77.000000, 00092 31.000000, 50.000000, 49.000000, 35.000000, 00093 63.000000, 67.000000, 40.000000, 31.000000, 00094 29.000000, 68.000000, 61.000000, 38.000000, 00095 31.000000, 28.000000, 28.000000, 76.000000, 00096 55.000000, 33.000000, 29.000000, 39.000000 00097 }; 00098 00099 00100 /* ---------------------------------------------------------------------- 00101 * Number of subjects X 1 00102 * ------------------------------------------------------------------- */ 00103 const float32_t testUnity_f32[4] = 00104 { 00105 1.000, 1.000, 1.000, 1.000 00106 }; 00107 00108 00109 /* ---------------------------------------------------------------------- 00110 ** f32 Output buffer 00111 ** ------------------------------------------------------------------- */ 00112 static float32_t testOutput[TEST_LENGTH_SAMPLES]; 00113 00114 00115 /* ------------------------------------------------------------------ 00116 * Global defines 00117 *------------------------------------------------------------------- */ 00118 #define NUMSTUDENTS 20 00119 #define NUMSUBJECTS 4 00120 00121 /* ------------------------------------------------------------------ 00122 * Global variables 00123 *------------------------------------------------------------------- */ 00124 00125 uint32_t numStudents = 20; 00126 uint32_t numSubjects = 4; 00127 float32_t max_marks, min_marks, mean, std, var; 00128 uint32_t student_num; 00129 00130 /* ---------------------------------------------------------------------------------- 00131 * Main f32 test function. It returns maximum marks secured and student number 00132 * ------------------------------------------------------------------------------- */ 00133 00134 int32_t main() 00135 { 00136 00137 #ifndef USE_STATIC_INIT 00138 00139 arm_matrix_instance_f32 srcA; 00140 arm_matrix_instance_f32 srcB; 00141 arm_matrix_instance_f32 dstC; 00142 00143 /* Input and output matrices initializations */ 00144 arm_mat_init_f32(&srcA, numStudents, numSubjects, (float32_t *)testMarks_f32); 00145 arm_mat_init_f32(&srcB, numSubjects, 1, (float32_t *)testUnity_f32); 00146 arm_mat_init_f32(&dstC, numStudents, 1, testOutput); 00147 00148 #else 00149 00150 /* Static Initializations of Input and output matrix sizes and array */ 00151 arm_matrix_instance_f32 srcA = {NUMSTUDENTS, NUMSUBJECTS, (float32_t *)testMarks_f32}; 00152 arm_matrix_instance_f32 srcB = {NUMSUBJECTS, 1, (float32_t *)testUnity_f32}; 00153 arm_matrix_instance_f32 dstC = {NUMSTUDENTS, 1, testOutput}; 00154 00155 #endif 00156 00157 00158 /* ---------------------------------------------------------------------- 00159 *Call the Matrix multiplication process function 00160 * ------------------------------------------------------------------- */ 00161 arm_mat_mult_f32(&srcA, &srcB, &dstC); 00162 00163 /* ---------------------------------------------------------------------- 00164 ** Call the Max function to calculate max marks among numStudents 00165 ** ------------------------------------------------------------------- */ 00166 arm_max_f32(testOutput, numStudents, &max_marks, &student_num); 00167 00168 /* ---------------------------------------------------------------------- 00169 ** Call the Min function to calculate min marks among numStudents 00170 ** ------------------------------------------------------------------- */ 00171 arm_min_f32(testOutput, numStudents, &min_marks, &student_num); 00172 00173 /* ---------------------------------------------------------------------- 00174 ** Call the Mean function to calculate mean 00175 ** ------------------------------------------------------------------- */ 00176 arm_mean_f32(testOutput, numStudents, &mean); 00177 00178 /* ---------------------------------------------------------------------- 00179 ** Call the std function to calculate standard deviation 00180 ** ------------------------------------------------------------------- */ 00181 arm_std_f32(testOutput, numStudents, &std); 00182 00183 /* ---------------------------------------------------------------------- 00184 ** Call the var function to calculate variance 00185 ** ------------------------------------------------------------------- */ 00186 arm_var_f32(testOutput, numStudents, &var); 00187 00188 } 00189 00190