Added all the F4 libraries to the project
[fw/stlink] / exampleF4 / CMSIS / DSP_Lib / Examples / arm_class_marks_example / arm_class_marks_example_f32.c
1 /* ---------------------------------------------------------------------- 
2 * Copyright (C) 2010 ARM Limited. All rights reserved.   
3 *  
4 * $Date:        29. November 2010  
5 * $Revision:    V1.0.3 
6 *  
7 * Project:          CMSIS DSP Library  
8 * Title:        arm_class_marks_example_f32.c             
9 *  
10 * Description:  Example code to calculate Minimum, Maximum 
11 *               Mean, std and variance of marks obtained in a class 
12
13 * Target Processor: Cortex-M4/Cortex-M3
14 *
15 * Version 1.0.3 2010/11/29 
16 *    Re-organized the CMSIS folders and updated documentation. 
17 *  
18 * Version 1.0.1 2010/10/05 KK 
19 *    Production release and review comments incorporated.  
20 *
21 * Version 1.0.0 2010/09/20 KK
22 *    Production release and review comments incorporated.
23 * ------------------------------------------------------------------- */ 
24  
25 /** 
26  * @ingroup groupExamples 
27  */ 
28  
29 /**    
30  * @defgroup ClassMarks Class Marks Example  
31  *
32  * \par Description: 
33  * \par
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.
36  *
37  * \note This example also demonstrates the usage of static initialization.
38  *  
39  * \par Variables Description:
40  * \par
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
48  *
49  * \par CMSIS DSP Software Library Functions Used:
50  * \par
51  * - arm_mat_init_f32()
52  * - arm_mat_mult_f32()
53  * - arm_max_f32()
54  * - arm_min_f32()
55  * - arm_mean_f32()
56  * - arm_std_f32()
57  * - arm_var_f32()
58  * 
59  * <b> Refer  </b> 
60  * \link arm_class_marks_example_f32.c \endlink
61  * 
62  */ 
63  
64  
65 /** \example arm_class_marks_example_f32.c 
66   */  
67 #include "arm_math.h" 
68  
69 #define USE_STATIC_INIT 
70  
71  /* ---------------------------------------------------------------------- 
72 ** Global defines  
73 ** ------------------------------------------------------------------- */ 
74  
75 #define TEST_LENGTH_SAMPLES     (20*4) 
76  
77 /* ---------------------------------------------------------------------- 
78 ** List of Marks scored by 20 students for 4 subjects 
79 ** ------------------------------------------------------------------- */  
80 const float32_t testMarks_f32[TEST_LENGTH_SAMPLES] =  
81 {    
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 
102 };  
103  
104  
105 /* ---------------------------------------------------------------------- 
106 * Number of subjects X 1  
107 * ------------------------------------------------------------------- */  
108 const float32_t testUnity_f32[4] =  
109 {    
110         1.000,  1.000,  1.000,  1.000 
111 }; 
112  
113  
114 /* ---------------------------------------------------------------------- 
115 ** f32 Output buffer 
116 ** ------------------------------------------------------------------- */  
117 static float32_t testOutput[TEST_LENGTH_SAMPLES]; 
118  
119  
120 /* ------------------------------------------------------------------ 
121 * Global defines  
122 *------------------------------------------------------------------- */ 
123 #define         NUMSTUDENTS  20 
124 #define     NUMSUBJECTS  4 
125  
126 /* ------------------------------------------------------------------ 
127 * Global variables  
128 *------------------------------------------------------------------- */ 
129  
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;    
134  
135 /* ---------------------------------------------------------------------------------- 
136 * Main f32 test function.  It returns maximum marks secured and student number 
137 * ------------------------------------------------------------------------------- */ 
138  
139 int32_t main() 
140
141  
142 #ifndef  USE_STATIC_INIT 
143  
144         arm_matrix_instance_f32 srcA; 
145         arm_matrix_instance_f32 srcB; 
146         arm_matrix_instance_f32 dstC;  
147  
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);  
152  
153 #else 
154  
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}; 
159  
160 #endif 
161  
162          
163         /* ---------------------------------------------------------------------- 
164         *Call the Matrix multiplication process function   
165         * ------------------------------------------------------------------- */ 
166         arm_mat_mult_f32(&srcA, &srcB, &dstC); 
167          
168         /* ---------------------------------------------------------------------- 
169         ** Call the Max function to calculate max marks among numStudents 
170         ** ------------------------------------------------------------------- */ 
171         arm_max_f32(testOutput, numStudents, &max_marks, &student_num);  
172  
173         /* ---------------------------------------------------------------------- 
174         ** Call the Min function to calculate min marks among numStudents 
175         ** ------------------------------------------------------------------- */ 
176         arm_min_f32(testOutput, numStudents, &min_marks, &student_num);  
177  
178         /* ---------------------------------------------------------------------- 
179         ** Call the Mean function to calculate mean 
180         ** ------------------------------------------------------------------- */ 
181         arm_mean_f32(testOutput, numStudents, &mean); 
182  
183         /* ---------------------------------------------------------------------- 
184         ** Call the std function to calculate standard deviation 
185         ** ------------------------------------------------------------------- */ 
186         arm_std_f32(testOutput, numStudents, &std); 
187  
188         /* ---------------------------------------------------------------------- 
189         ** Call the var function to calculate variance 
190         ** ------------------------------------------------------------------- */ 
191         arm_var_f32(testOutput, numStudents, &var); 
192  
193     while(1);                             /* main function does not return */
194
195  
196