1 /* ----------------------------------------------------------------------
2 * Copyright (C) 2010 ARM Limited. All rights reserved.
4 * $Date: 29. November 2010
7 * Project: CMSIS DSP Library
8 * Title: arm_class_marks_example_f32.c
10 * Description: Example code to calculate Minimum, Maximum
11 * Mean, std and variance of marks obtained in a class
13 * Target Processor: Cortex-M4/Cortex-M3
15 * Version 1.0.3 2010/11/29
16 * Re-organized the CMSIS folders and updated documentation.
18 * Version 1.0.1 2010/10/05 KK
19 * Production release and review comments incorporated.
21 * Version 1.0.0 2010/09/20 KK
22 * Production release and review comments incorporated.
23 * ------------------------------------------------------------------- */
26 * @ingroup groupExamples
30 * @defgroup ClassMarks Class Marks Example
34 * Demonstrates the use the Maximum, Minimum, Mean, Standard Deviation, Variance
35 * and Matrix functions to calculate statistical values of marks obtained in a class.
37 * \note This example also demonstrates the usage of static initialization.
39 * \par Variables Description:
41 * \li \c testMarks_f32 points to the marks scored by 20 students in 4 subjects
42 * \li \c max_marks Maximum of all marks
43 * \li \c min_marks Minimum of all marks
44 * \li \c mean Mean of all marks
45 * \li \c var Variance of the marks
46 * \li \c std Standard deviation of the marks
47 * \li \c numStudents Total number of students in the class
49 * \par CMSIS DSP Software Library Functions Used:
51 * - arm_mat_init_f32()
52 * - arm_mat_mult_f32()
60 * \link arm_class_marks_example_f32.c \endlink
65 /** \example arm_class_marks_example_f32.c
69 #define USE_STATIC_INIT
71 /* ----------------------------------------------------------------------
73 ** ------------------------------------------------------------------- */
75 #define TEST_LENGTH_SAMPLES (20*4)
77 /* ----------------------------------------------------------------------
78 ** List of Marks scored by 20 students for 4 subjects
79 ** ------------------------------------------------------------------- */
80 const float32_t testMarks_f32[TEST_LENGTH_SAMPLES] =
82 42.000000, 37.000000, 81.000000, 28.000000,
83 83.000000, 72.000000, 36.000000, 38.000000,
84 32.000000, 51.000000, 63.000000, 64.000000,
85 97.000000, 82.000000, 95.000000, 90.000000,
86 66.000000, 51.000000, 54.000000, 42.000000,
87 67.000000, 56.000000, 45.000000, 57.000000,
88 67.000000, 69.000000, 35.000000, 52.000000,
89 29.000000, 81.000000, 58.000000, 47.000000,
90 38.000000, 76.000000, 100.000000, 29.000000,
91 33.000000, 47.000000, 29.000000, 50.000000,
92 34.000000, 41.000000, 61.000000, 46.000000,
93 52.000000, 50.000000, 48.000000, 36.000000,
94 47.000000, 55.000000, 44.000000, 40.000000,
95 100.000000, 94.000000, 84.000000, 37.000000,
96 32.000000, 71.000000, 47.000000, 77.000000,
97 31.000000, 50.000000, 49.000000, 35.000000,
98 63.000000, 67.000000, 40.000000, 31.000000,
99 29.000000, 68.000000, 61.000000, 38.000000,
100 31.000000, 28.000000, 28.000000, 76.000000,
101 55.000000, 33.000000, 29.000000, 39.000000
105 /* ----------------------------------------------------------------------
106 * Number of subjects X 1
107 * ------------------------------------------------------------------- */
108 const float32_t testUnity_f32[4] =
110 1.000, 1.000, 1.000, 1.000
114 /* ----------------------------------------------------------------------
116 ** ------------------------------------------------------------------- */
117 static float32_t testOutput[TEST_LENGTH_SAMPLES];
120 /* ------------------------------------------------------------------
122 *------------------------------------------------------------------- */
123 #define NUMSTUDENTS 20
124 #define NUMSUBJECTS 4
126 /* ------------------------------------------------------------------
128 *------------------------------------------------------------------- */
130 uint32_t numStudents = 20;
131 uint32_t numSubjects = 4;
132 float32_t max_marks, min_marks, mean, std, var;
133 uint32_t student_num;
135 /* ----------------------------------------------------------------------------------
136 * Main f32 test function. It returns maximum marks secured and student number
137 * ------------------------------------------------------------------------------- */
142 #ifndef USE_STATIC_INIT
144 arm_matrix_instance_f32 srcA;
145 arm_matrix_instance_f32 srcB;
146 arm_matrix_instance_f32 dstC;
148 /* Input and output matrices initializations */
149 arm_mat_init_f32(&srcA, numStudents, numSubjects, (float32_t *)testMarks_f32);
150 arm_mat_init_f32(&srcB, numSubjects, 1, (float32_t *)testUnity_f32);
151 arm_mat_init_f32(&dstC, numStudents, 1, testOutput);
155 /* Static Initializations of Input and output matrix sizes and array */
156 arm_matrix_instance_f32 srcA = {NUMSTUDENTS, NUMSUBJECTS, (float32_t *)testMarks_f32};
157 arm_matrix_instance_f32 srcB = {NUMSUBJECTS, 1, (float32_t *)testUnity_f32};
158 arm_matrix_instance_f32 dstC = {NUMSTUDENTS, 1, testOutput};
163 /* ----------------------------------------------------------------------
164 *Call the Matrix multiplication process function
165 * ------------------------------------------------------------------- */
166 arm_mat_mult_f32(&srcA, &srcB, &dstC);
168 /* ----------------------------------------------------------------------
169 ** Call the Max function to calculate max marks among numStudents
170 ** ------------------------------------------------------------------- */
171 arm_max_f32(testOutput, numStudents, &max_marks, &student_num);
173 /* ----------------------------------------------------------------------
174 ** Call the Min function to calculate min marks among numStudents
175 ** ------------------------------------------------------------------- */
176 arm_min_f32(testOutput, numStudents, &min_marks, &student_num);
178 /* ----------------------------------------------------------------------
179 ** Call the Mean function to calculate mean
180 ** ------------------------------------------------------------------- */
181 arm_mean_f32(testOutput, numStudents, &mean);
183 /* ----------------------------------------------------------------------
184 ** Call the std function to calculate standard deviation
185 ** ------------------------------------------------------------------- */
186 arm_std_f32(testOutput, numStudents, &std);
188 /* ----------------------------------------------------------------------
189 ** Call the var function to calculate variance
190 ** ------------------------------------------------------------------- */
191 arm_var_f32(testOutput, numStudents, &var);
193 while(1); /* main function does not return */