tool.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #include "tool.h"
  2. char JS_RTT_UpBuffer[4096]; // J-Scope RTT Buffer
  3. int JS_RTT_Channel = 1; // J-Scope RTT Channel
  4. acValBuffer_t acValBuffer;
  5. void JS_RTT_Init(void)
  6. {
  7. SEGGER_RTT_ConfigUpBuffer(JS_RTT_Channel, "JScope_I4I4I4I4I4I4", &JS_RTT_UpBuffer[0], sizeof(JS_RTT_UpBuffer), SEGGER_RTT_MODE_BLOCK_IF_FIFO_FULL);
  8. }
  9. void JS_RTT_Print(signed int Sine1,signed int Sine2,signed int Sine3)
  10. {
  11. acValBuffer.Sine1 = Sine1;
  12. acValBuffer.Sine2 = Sine2;
  13. acValBuffer.Sine3 = Sine3;
  14. SEGGER_RTT_Write(JS_RTT_Channel, &acValBuffer, sizeof(acValBuffer));
  15. }
  16. void JS_RTT_Print_06(signed int Sine1,signed int Sine2,signed int Sine3,signed int Sine4,signed int Sine5,signed int Sine6)
  17. {
  18. acValBuffer.Sine1 = Sine1;
  19. acValBuffer.Sine2 = Sine2;
  20. acValBuffer.Sine3 = Sine3;
  21. acValBuffer.Sine4 = Sine4;
  22. acValBuffer.Sine5 = Sine5;
  23. acValBuffer.Sine6 = Sine6;
  24. SEGGER_RTT_Write(JS_RTT_Channel, &acValBuffer, sizeof(acValBuffer));
  25. }
  26. /**
  27. @brief 求变异系数的绝对值
  28. @param p_array-[in] 数组地址
  29. @param len-[in] 数组成员个数
  30. @return 变异系数的绝对值
  31. */
  32. float32_t CoefficientVariation(double *p_array, uint32_t len)
  33. {
  34. int i;
  35. float32_t sum = 0; //总和
  36. float32_t avg; //平均值
  37. float32_t spow = 0;
  38. for(i=0;i<len;i++)sum += p_array[i];//求总和
  39. avg = sum/len;//计算平均值
  40. for(i=0;i<len;i++)spow += (p_array[i]-avg)*(p_array[i]-avg);//平方累加
  41. float32_t standardDeviation=0,Coefficient_variation=0;
  42. // static char string[500];
  43. if(!arm_sqrt_f32((spow/len),&standardDeviation))
  44. {
  45. // sprintf(string,"standardDeviation:%f\r\n",standardDeviation);
  46. // SEGGER_RTT_printf(0,"%s",string);
  47. standardDeviation = (standardDeviation)/avg;
  48. arm_abs_f32(&standardDeviation,&Coefficient_variation,1);
  49. // sprintf(string,"Coefficient_variation:%f\r\n",Coefficient_variation);
  50. // SEGGER_RTT_printf(0,"%s",string);
  51. }
  52. return Coefficient_variation;
  53. }