CMSIS DSP library

Dependents:   KL25Z_FFT_Demo Hat_Board_v5_1 KL25Z_FFT_Demo_tony KL25Z_FFT_Demo_tony ... more

Fork of mbed-dsp by mbed official

Revision:
2:da51fb522205
Parent:
1:fdd22bb7aa52
Child:
3:7a284390b0ce
--- a/cmsis_dsp/SupportFunctions/math_helper.c	Wed Nov 28 12:30:09 2012 +0000
+++ b/cmsis_dsp/SupportFunctions/math_helper.c	Thu May 30 17:10:11 2013 +0100
@@ -2,13 +2,13 @@
 * Copyright (C) 2010 ARM Limited. All rights reserved.  
 *  
 * $Date:        29. November 2010  
-* $Revision:     V1.0.3  
+* $Revision: 	V1.0.3  
 *  
-* Project:         CMSIS DSP Library 
+* Project: 	    CMSIS DSP Library 
 *
-* Title:        math_helper.c
+* Title:	    math_helper.c
 *
-* Description:    Definition of all helper functions required.  
+* Description:	Definition of all helper functions required.  
 *  
 * Target Processor: Cortex-M4/Cortex-M3
 *  
@@ -29,21 +29,21 @@
 * -------------------------------------------------------------------- */
 
 /* ----------------------------------------------------------------------
-*        Include standard header files  
+*		Include standard header files  
 * -------------------------------------------------------------------- */
 #include<math.h>
 
 /* ----------------------------------------------------------------------
-*        Include project header files  
+*		Include project header files  
 * -------------------------------------------------------------------- */
 #include "math_helper.h"
 
 /** 
  * @brief  Caluclation of SNR
- * @param  float*     Pointer to the reference buffer
- * @param  float*    Pointer to the test buffer
- * @param  uint32_t    total number of samples
- * @return float    SNR
+ * @param  float* 	Pointer to the reference buffer
+ * @param  float*	Pointer to the test buffer
+ * @param  uint32_t	total number of samples
+ * @return float	SNR
  * The function Caluclates signal to noise ratio for the reference output 
  * and test output 
  */
@@ -58,36 +58,36 @@
 
   for (i = 0; i < buffSize; i++)
     {
-       /* Checking for a NAN value in pRef array */
-      test =   (int *)(&pRef[i]);
+ 	  /* Checking for a NAN value in pRef array */
+	  test =   (int *)(&pRef[i]);
       temp =  *test;
 
-      if(temp == 0x7FC00000)
-      {
-              return(0);
-      }
+	  if(temp == 0x7FC00000)
+	  {
+	  		return(0);
+	  }
 
-      /* Checking for a NAN value in pTest array */
-      test =   (int *)(&pTest[i]);
+	  /* Checking for a NAN value in pTest array */
+	  test =   (int *)(&pTest[i]);
       temp =  *test;
 
-      if(temp == 0x7FC00000)
-      {
-              return(0);
-      }
+	  if(temp == 0x7FC00000)
+	  {
+	  		return(0);
+	  }
       EnergySignal += pRef[i] * pRef[i];
       EnergyError += (pRef[i] - pTest[i]) * (pRef[i] - pTest[i]); 
     }
 
-    /* Checking for a NAN value in EnergyError */
-    test =   (int *)(&EnergyError);
+	/* Checking for a NAN value in EnergyError */
+	test =   (int *)(&EnergyError);
     temp =  *test;
 
     if(temp == 0x7FC00000)
     {
-          return(0);
+  		return(0);
     }
-    
+	
 
   SNR = 10 * log10 (EnergySignal / EnergyError);
 
@@ -98,9 +98,9 @@
 
 /** 
  * @brief  Provide guard bits for Input buffer
- * @param  q15_t*         Pointer to input buffer
- * @param  uint32_t     blockSize
- * @param  uint32_t     guard_bits
+ * @param  q15_t* 	    Pointer to input buffer
+ * @param  uint32_t 	blockSize
+ * @param  uint32_t 	guard_bits
  * @return none
  * The function Provides the guard bits for the buffer 
  * to avoid overflow 
@@ -119,7 +119,7 @@
 
 /** 
  * @brief  Converts float to fixed in q12.20 format
- * @param  uint32_t     number of samples in the buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none
  * The function converts floating point values to fixed point(q12.20) values 
  */
@@ -130,7 +130,7 @@
 
   for (i = 0; i < numSamples; i++)
     {
-      /* 1048576.0f corresponds to pow(2, 20) */
+	  /* 1048576.0f corresponds to pow(2, 20) */
       pOut[i] = (q31_t) (pIn[i] * 1048576.0f);
 
       pOut[i] += pIn[i] > 0 ? 0.5 : -0.5;
@@ -144,9 +144,9 @@
 
 /** 
  * @brief  Compare MATLAB Reference Output and ARM Test output
- * @param  q15_t*     Pointer to Ref buffer
- * @param  q15_t*     Pointer to Test buffer
- * @param  uint32_t     number of samples in the buffer
+ * @param  q15_t* 	Pointer to Ref buffer
+ * @param  q15_t* 	Pointer to Test buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none 
  */
 
@@ -158,13 +158,13 @@
 
   for (i = 0; i < numSamples; i++)
   {
-      diff = pIn[i] - pOut[i];
-      diffCrnt = (diff > 0) ? diff : -diff;
+  	diff = pIn[i] - pOut[i];
+  	diffCrnt = (diff > 0) ? diff : -diff;
 
-    if(diffCrnt > maxDiff)
-    {
-        maxDiff = diffCrnt;
-    }    
+	if(diffCrnt > maxDiff)
+	{
+		maxDiff = diffCrnt;
+	}	
   }
 
   return(maxDiff);
@@ -172,9 +172,9 @@
 
 /** 
  * @brief  Compare MATLAB Reference Output and ARM Test output
- * @param  q31_t*     Pointer to Ref buffer
- * @param  q31_t*     Pointer to Test buffer
- * @param  uint32_t     number of samples in the buffer
+ * @param  q31_t* 	Pointer to Ref buffer
+ * @param  q31_t* 	Pointer to Test buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none 
  */
 
@@ -186,13 +186,13 @@
 
   for (i = 0; i < numSamples; i++)
   {
-      diff = pIn[i] - pOut[i];
-      diffCrnt = (diff > 0) ? diff : -diff;
+  	diff = pIn[i] - pOut[i];
+  	diffCrnt = (diff > 0) ? diff : -diff;
 
-    if(diffCrnt > maxDiff)
-    {
-        maxDiff = diffCrnt;
-    }
+	if(diffCrnt > maxDiff)
+	{
+		maxDiff = diffCrnt;
+	}
   }
 
   return(maxDiff);
@@ -200,16 +200,16 @@
 
 /** 
  * @brief  Provide guard bits for Input buffer
- * @param  q31_t*     Pointer to input buffer
- * @param  uint32_t     blockSize
- * @param  uint32_t     guard_bits
+ * @param  q31_t* 	Pointer to input buffer
+ * @param  uint32_t 	blockSize
+ * @param  uint32_t 	guard_bits
  * @return none
  * The function Provides the guard bits for the buffer 
  * to avoid overflow 
  */
 
 void arm_provide_guard_bits_q31 (q31_t * input_buf, 
-                                 uint32_t blockSize,
+								 uint32_t blockSize,
                                  uint32_t guard_bits)
 {
   uint32_t i;
@@ -222,16 +222,16 @@
 
 /** 
  * @brief  Provide guard bits for Input buffer
- * @param  q31_t*     Pointer to input buffer
- * @param  uint32_t     blockSize
- * @param  uint32_t     guard_bits
+ * @param  q31_t* 	Pointer to input buffer
+ * @param  uint32_t 	blockSize
+ * @param  uint32_t 	guard_bits
  * @return none
  * The function Provides the guard bits for the buffer 
  * to avoid overflow 
  */
 
 void arm_provide_guard_bits_q7 (q7_t * input_buf, 
-                                uint32_t blockSize,
+								uint32_t blockSize,
                                 uint32_t guard_bits)
 {
   uint32_t i;
@@ -246,7 +246,7 @@
 
 /** 
  * @brief  Caluclates number of guard bits 
- * @param  uint32_t     number of additions
+ * @param  uint32_t 	number of additions
  * @return none
  * The function Caluclates the number of guard bits  
  * depending on the numtaps 
@@ -272,13 +272,13 @@
 
 /** 
  * @brief  Converts Q15 to floating-point
- * @param  uint32_t     number of samples in the buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none
  */
 
 void arm_apply_guard_bits (float32_t * pIn, 
-                           uint32_t numSamples, 
-                           uint32_t guard_bits)
+						   uint32_t numSamples, 
+						   uint32_t guard_bits)
 {
   uint32_t i;
 
@@ -290,7 +290,7 @@
 
 /** 
  * @brief  Calculates pow(2, numShifts)
- * @param  uint32_t     number of shifts
+ * @param  uint32_t 	number of shifts
  * @return pow(2, numShifts)
  */
 uint32_t arm_calc_2pow(uint32_t numShifts)
@@ -301,7 +301,7 @@
   for (i = 0; i < numShifts; i++)
     {
       val = val * 2;
-    }    
+    }	
 
   return(val);
 }
@@ -310,7 +310,7 @@
 
 /** 
  * @brief  Converts float to fixed q14 
- * @param  uint32_t     number of samples in the buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none
  * The function converts floating point values to fixed point values 
  */
@@ -322,7 +322,7 @@
 
   for (i = 0; i < numSamples; i++)
     {
-      /* 16384.0f corresponds to pow(2, 14) */
+	  /* 16384.0f corresponds to pow(2, 14) */
       pOut[i] = (q15_t) (pIn[i] * 16384.0f);
 
       pOut[i] += pIn[i] > 0 ? 0.5 : -0.5;
@@ -339,19 +339,19 @@
  
 /** 
  * @brief  Converts float to fixed q30 format
- * @param  uint32_t     number of samples in the buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none
  * The function converts floating point values to fixed point values 
  */
 
 void arm_float_to_q30 (float *pIn, q31_t * pOut, 
-                       uint32_t numSamples)
+					   uint32_t numSamples)
 {
   uint32_t i;
 
   for (i = 0; i < numSamples; i++)
     {
-      /* 1073741824.0f corresponds to pow(2, 30) */
+	  /* 1073741824.0f corresponds to pow(2, 30) */
       pOut[i] = (q31_t) (pIn[i] * 1073741824.0f);
 
       pOut[i] += pIn[i] > 0 ? 0.5 : -0.5;
@@ -365,19 +365,19 @@
 
 /** 
  * @brief  Converts float to fixed q30 format
- * @param  uint32_t     number of samples in the buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none
  * The function converts floating point values to fixed point values 
  */
 
 void arm_float_to_q29 (float *pIn, q31_t * pOut, 
-                       uint32_t numSamples)
+					   uint32_t numSamples)
 {
   uint32_t i;
 
   for (i = 0; i < numSamples; i++)
     {
-      /* 1073741824.0f corresponds to pow(2, 30) */
+	  /* 1073741824.0f corresponds to pow(2, 30) */
       pOut[i] = (q31_t) (pIn[i] * 536870912.0f);
 
       pOut[i] += pIn[i] > 0 ? 0.5 : -0.5;
@@ -392,7 +392,7 @@
 
 /** 
  * @brief  Converts float to fixed q28 format
- * @param  uint32_t     number of samples in the buffer
+ * @param  uint32_t 	number of samples in the buffer
  * @return none
  * The function converts floating point values to fixed point values 
  */
@@ -404,7 +404,7 @@
 
   for (i = 0; i < numSamples; i++)
     {
-    /* 268435456.0f corresponds to pow(2, 28) */
+	/* 268435456.0f corresponds to pow(2, 28) */
       pOut[i] = (q31_t) (pIn[i] * 268435456.0f);
 
       pOut[i] += pIn[i] > 0 ? 0.5 : -0.5;
@@ -418,8 +418,8 @@
 
 /** 
  * @brief  Clip the float values to +/- 1 
- * @param  pIn     input buffer
- * @param  numSamples     number of samples in the buffer
+ * @param  pIn 	input buffer
+ * @param  numSamples 	number of samples in the buffer
  * @return none
  * The function converts floating point values to fixed point values 
  */
@@ -431,14 +431,14 @@
   for (i = 0; i < numSamples; i++)
     {
       if(pIn[i] > 1.0f)
-      {
-        pIn[i] = 1.0;
-      }
-      else if( pIn[i] < -1.0f)
-      {
-        pIn[i] = -1.0;
-      }
-           
+	  {
+	    pIn[i] = 1.0;
+	  }
+	  else if( pIn[i] < -1.0f)
+	  {
+	    pIn[i] = -1.0;
+	  }
+	       
     }
 }