CMovAvgFilter.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. //
  2. // File: CMovAvgFilter.cpp
  3. //
  4. // MATLAB Coder version : 4.3
  5. // C/C++ source code generated on : 12-Jan-2022 14:14:11
  6. //
  7. // Include Files
  8. #include "CMovAvgFilter.h"
  9. // Function Definitions
  10. //
  11. // Arguments : void
  12. // Return Type : void
  13. //
  14. CMovAvgFilter::~CMovAvgFilter()
  15. {
  16. // (no terminate code required)
  17. }
  18. void CMovAvgFilter::SetPdoa1dEnable(bool bEnable)
  19. {
  20. s_enabled_pdoa1d = bEnable;
  21. }
  22. bool CMovAvgFilter::GetPdoa1dEnable()
  23. {
  24. return s_enabled_pdoa1d;
  25. }
  26. void CMovAvgFilter::SetPdoa2dEnable(bool bEnable)
  27. {
  28. s_enabled_pdoa2d = bEnable;
  29. }
  30. bool CMovAvgFilter::GetPdoa2dEnable()
  31. {
  32. return s_enabled_pdoa2d;
  33. }
  34. //
  35. // Arguments : void
  36. // Return Type : void
  37. //
  38. CMovAvgFilter::CMovAvgFilter()
  39. {
  40. this->SD_.pd = &this->pd_;
  41. this->firstRun_not_empty_init();
  42. this->MovAvgFilter_init();
  43. }
  44. //
  45. // Arguments : real_T x
  46. // Return Type : real_T
  47. //
  48. real_T CMovAvgFilter::MovAvgFilter(real_T x)
  49. {
  50. real_T avg;
  51. int32_T m;
  52. if (!this->pd_.firstRun_not_empty) {
  53. this->pd_.xbuf.size[0] = 11;
  54. for (m = 0; m < 11; m++) {
  55. this->pd_.xbuf.data[m] = x;
  56. }
  57. this->pd_.prevAvg = x;
  58. this->pd_.firstRun_not_empty = true;
  59. }
  60. for (m = 0; m < 10; m++) {
  61. this->pd_.xbuf.data[m] = this->pd_.xbuf.data[m + 1];
  62. }
  63. this->pd_.xbuf.data[10] = x;
  64. avg = this->pd_.prevAvg + (x - this->pd_.xbuf.data[0]) / 10.0;
  65. this->pd_.prevAvg = avg;
  66. return avg;
  67. }
  68. //
  69. // Arguments : void
  70. // Return Type : void
  71. //
  72. void CMovAvgFilter::MovAvgFilter_init()
  73. {
  74. this->pd_.xbuf.size[0] = 0;
  75. }
  76. bool CMovAvgFilter::s_enabled_pdoa1d = false;
  77. bool CMovAvgFilter::s_enabled_pdoa2d = false;
  78. //
  79. // Arguments : void
  80. // Return Type : void
  81. //
  82. void CMovAvgFilter::firstRun_not_empty_init()
  83. {
  84. this->pd_.firstRun_not_empty = false;
  85. }
  86. //
  87. // Arguments : void
  88. // Return Type : MovAvgFilterStackData *
  89. //
  90. MovAvgFilterStackData *CMovAvgFilter::getStackData()
  91. {
  92. return &this->SD_;
  93. }
  94. //
  95. // File trailer for CMovAvgFilter.cpp
  96. //
  97. // [EOF]
  98. //