Subversion Repositories testOled

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* ----------------------------------------------------------------------
  2. * Copyright (C) 2010-2012 ARM Limited. All rights reserved.
  3. *
  4. * $Date:         17. January 2013
  5. * $Revision:     V1.4.0
  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. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. *   - Redistributions of source code must retain the above copyright
  19. *     notice, this list of conditions and the following disclaimer.
  20. *   - Redistributions in binary form must reproduce the above copyright
  21. *     notice, this list of conditions and the following disclaimer in
  22. *     the documentation and/or other materials provided with the
  23. *     distribution.
  24. *   - Neither the name of ARM LIMITED nor the names of its contributors
  25. *     may be used to endorse or promote products derived from this
  26. *     software without specific prior written permission.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  29. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  31. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  32. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  33. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  34. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  35. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  36. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  37. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  38. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  39. * POSSIBILITY OF SUCH DAMAGE.
  40. * -------------------------------------------------------------------- */
  41.  
  42. /**
  43.  * @ingroup groupExamples
  44.  */
  45.  
  46. /**
  47.  * @defgroup ClassMarks Class Marks Example
  48.  *
  49.  * \par Description:
  50.  * \par
  51.  * Demonstrates the use the Maximum, Minimum, Mean, Standard Deviation, Variance
  52.  * and Matrix functions to calculate statistical values of marks obtained in a class.
  53.  *
  54.  * \note This example also demonstrates the usage of static initialization.
  55.  *
  56.  * \par Variables Description:
  57.  * \par
  58.  * \li \c testMarks_f32 points to the marks scored by 20 students in 4 subjects
  59.  * \li \c max_marks     Maximum of all marks
  60.  * \li \c min_marks     Minimum of all marks
  61.  * \li \c mean          Mean of all marks
  62.  * \li \c var           Variance of the marks
  63.  * \li \c std           Standard deviation of the marks
  64.  * \li \c numStudents   Total number of students in the class
  65.  *
  66.  * \par CMSIS DSP Software Library Functions Used:
  67.  * \par
  68.  * - arm_mat_init_f32()
  69.  * - arm_mat_mult_f32()
  70.  * - arm_max_f32()
  71.  * - arm_min_f32()
  72.  * - arm_mean_f32()
  73.  * - arm_std_f32()
  74.  * - arm_var_f32()
  75.  *
  76.  * <b> Refer  </b>
  77.  * \link arm_class_marks_example_f32.c \endlink
  78.  *
  79.  */
  80.  
  81.  
  82. /** \example arm_class_marks_example_f32.c
  83.   */
  84. #include "arm_math.h"
  85.  
  86. #define USE_STATIC_INIT
  87.  
  88.  /* ----------------------------------------------------------------------
  89. ** Global defines
  90. ** ------------------------------------------------------------------- */
  91.  
  92. #define TEST_LENGTH_SAMPLES   (20*4)
  93.  
  94. /* ----------------------------------------------------------------------
  95. ** List of Marks scored by 20 students for 4 subjects
  96. ** ------------------------------------------------------------------- */
  97. const float32_t testMarks_f32[TEST_LENGTH_SAMPLES] =
  98. {
  99.   42.000000,  37.000000,  81.000000,  28.000000,
  100.   83.000000,  72.000000,  36.000000,  38.000000,
  101.   32.000000,  51.000000,  63.000000,  64.000000,
  102.   97.000000,  82.000000,  95.000000,  90.000000,
  103.   66.000000,  51.000000,  54.000000,  42.000000,
  104.   67.000000,  56.000000,  45.000000,  57.000000,
  105.   67.000000,  69.000000,  35.000000,  52.000000,
  106.   29.000000,  81.000000,  58.000000,  47.000000,
  107.   38.000000,  76.000000, 100.000000,  29.000000,
  108.   33.000000,  47.000000,  29.000000,  50.000000,
  109.   34.000000,  41.000000,  61.000000,  46.000000,
  110.   52.000000,  50.000000,  48.000000,  36.000000,
  111.   47.000000,  55.000000,  44.000000,  40.000000,
  112.  100.000000,  94.000000,  84.000000,  37.000000,
  113.   32.000000,  71.000000,  47.000000,  77.000000,
  114.   31.000000,  50.000000,  49.000000,  35.000000,
  115.   63.000000,  67.000000,  40.000000,  31.000000,
  116.   29.000000,  68.000000,  61.000000,  38.000000,
  117.   31.000000,  28.000000,  28.000000,  76.000000,
  118.   55.000000,  33.000000,  29.000000,  39.000000
  119. };
  120.  
  121.  
  122. /* ----------------------------------------------------------------------
  123. * Number of subjects X 1
  124. * ------------------------------------------------------------------- */
  125. const float32_t testUnity_f32[4] =
  126. {
  127.   1.000,  1.000,   1.000,  1.000
  128. };
  129.  
  130.  
  131. /* ----------------------------------------------------------------------
  132. ** f32 Output buffer
  133. ** ------------------------------------------------------------------- */
  134. static float32_t testOutput[TEST_LENGTH_SAMPLES];
  135.  
  136.  
  137. /* ------------------------------------------------------------------
  138. * Global defines
  139. *------------------------------------------------------------------- */
  140. #define   NUMSTUDENTS  20
  141. #define     NUMSUBJECTS  4
  142.  
  143. /* ------------------------------------------------------------------
  144. * Global variables
  145. *------------------------------------------------------------------- */
  146.  
  147.  uint32_t    numStudents = 20;
  148.  uint32_t    numSubjects = 4;
  149. float32_t    max_marks, min_marks, mean, std, var;
  150.  uint32_t    student_num;
  151.  
  152. /* ----------------------------------------------------------------------------------
  153. * Main f32 test function.  It returns maximum marks secured and student number
  154. * ------------------------------------------------------------------------------- */
  155.  
  156. int32_t main()
  157. {
  158.  
  159. #ifndef  USE_STATIC_INIT
  160.  
  161.   arm_matrix_instance_f32 srcA;
  162.   arm_matrix_instance_f32 srcB;
  163.   arm_matrix_instance_f32 dstC;
  164.  
  165.   /* Input and output matrices initializations */
  166.   arm_mat_init_f32(&srcA, numStudents, numSubjects, (float32_t *)testMarks_f32);
  167.   arm_mat_init_f32(&srcB, numSubjects, 1, (float32_t *)testUnity_f32);
  168.   arm_mat_init_f32(&dstC, numStudents, 1, testOutput);
  169.  
  170. #else
  171.  
  172.   /* Static Initializations of Input and output matrix sizes and array */
  173.   arm_matrix_instance_f32 srcA = {NUMSTUDENTS, NUMSUBJECTS, (float32_t *)testMarks_f32};
  174.   arm_matrix_instance_f32 srcB = {NUMSUBJECTS, 1, (float32_t *)testUnity_f32};
  175.   arm_matrix_instance_f32 dstC = {NUMSTUDENTS, 1, testOutput};
  176.  
  177. #endif
  178.  
  179.  
  180.   /* ----------------------------------------------------------------------
  181.   *Call the Matrix multiplication process function
  182.   * ------------------------------------------------------------------- */
  183.   arm_mat_mult_f32(&srcA, &srcB, &dstC);
  184.  
  185.   /* ----------------------------------------------------------------------
  186.   ** Call the Max function to calculate max marks among numStudents
  187.   ** ------------------------------------------------------------------- */
  188.   arm_max_f32(testOutput, numStudents, &max_marks, &student_num);
  189.  
  190.   /* ----------------------------------------------------------------------
  191.   ** Call the Min function to calculate min marks among numStudents
  192.   ** ------------------------------------------------------------------- */
  193.   arm_min_f32(testOutput, numStudents, &min_marks, &student_num);
  194.  
  195.   /* ----------------------------------------------------------------------
  196.   ** Call the Mean function to calculate mean
  197.   ** ------------------------------------------------------------------- */
  198.   arm_mean_f32(testOutput, numStudents, &mean);
  199.  
  200.   /* ----------------------------------------------------------------------
  201.   ** Call the std function to calculate standard deviation
  202.   ** ------------------------------------------------------------------- */
  203.   arm_std_f32(testOutput, numStudents, &std);
  204.  
  205.   /* ----------------------------------------------------------------------
  206.   ** Call the var function to calculate variance
  207.   ** ------------------------------------------------------------------- */
  208.   arm_var_f32(testOutput, numStudents, &var);
  209.  
  210.   while (1);                             /* main function does not return */
  211. }
  212.