fun8_std.cpp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. //
  2. // File: std.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 09-Mar-2023 16:57:20
  6. //
  7. // Include Files
  8. #include "fun8_std.h"
  9. #include "fun8_AMJamming_H_data.h"
  10. #include "rt_nonfinite.h"
  11. #include "coder_array.h"
  12. #include <cmath>
  13. // Function Declarations
  14. static double rt_hypotd_snf(double u0, double u1);
  15. // Function Definitions
  16. //
  17. // Arguments : double u0
  18. // double u1
  19. // Return Type : double
  20. //
  21. static double rt_hypotd_snf(double u0, double u1)
  22. {
  23. double a;
  24. double y;
  25. a = std::abs(u0);
  26. y = std::abs(u1);
  27. if (a < y) {
  28. a /= y;
  29. y *= std::sqrt(a * a + 1.0);
  30. } else if (a > y) {
  31. y /= a;
  32. y = a * std::sqrt(y * y + 1.0);
  33. } else if (!std::isnan(y)) {
  34. y = a * 1.4142135623730951;
  35. }
  36. return y;
  37. }
  38. //
  39. // Arguments : const ::coder::array<creal_T, 2U> &x
  40. // Return Type : double
  41. //
  42. namespace coder {
  43. double b_std_8(const ::coder::array<creal_T, 2U> &x)
  44. {
  45. array<double, 1U> absdiff;
  46. double y;
  47. int n;
  48. n = x.size(1);
  49. if (x.size(1) == 0) {
  50. y = rtNaN;
  51. } else if (x.size(1) == 1) {
  52. if ((!std::isinf(x[0].re)) && (!std::isinf(x[0].im)) &&
  53. ((!std::isnan(x[0].re)) && (!std::isnan(x[0].im)))) {
  54. y = 0.0;
  55. } else {
  56. y = rtNaN;
  57. }
  58. } else {
  59. double bsum_re;
  60. double xbar_im;
  61. double xbar_re;
  62. int firstBlockLength;
  63. int k;
  64. int lastBlockLength;
  65. int nblocks;
  66. if (x.size(1) <= 1024) {
  67. firstBlockLength = x.size(1);
  68. lastBlockLength = 0;
  69. nblocks = 1;
  70. } else {
  71. firstBlockLength = 1024;
  72. nblocks = x.size(1) / 1024;
  73. lastBlockLength = x.size(1) - (nblocks << 10);
  74. if (lastBlockLength > 0) {
  75. nblocks++;
  76. } else {
  77. lastBlockLength = 1024;
  78. }
  79. }
  80. xbar_re = x[0].re;
  81. xbar_im = x[0].im;
  82. for (k = 2; k <= firstBlockLength; k++) {
  83. xbar_re += x[k - 1].re;
  84. xbar_im += x[k - 1].im;
  85. }
  86. for (int ib{2}; ib <= nblocks; ib++) {
  87. double bsum_im;
  88. int hi;
  89. firstBlockLength = (ib - 1) << 10;
  90. bsum_re = x[firstBlockLength].re;
  91. bsum_im = x[firstBlockLength].im;
  92. if (ib == nblocks) {
  93. hi = lastBlockLength;
  94. } else {
  95. hi = 1024;
  96. }
  97. for (k = 2; k <= hi; k++) {
  98. int bsum_re_tmp;
  99. bsum_re_tmp = (firstBlockLength + k) - 1;
  100. bsum_re += x[bsum_re_tmp].re;
  101. bsum_im += x[bsum_re_tmp].im;
  102. }
  103. xbar_re += bsum_re;
  104. xbar_im += bsum_im;
  105. }
  106. if (xbar_im == 0.0) {
  107. bsum_re = xbar_re / static_cast<double>(x.size(1));
  108. xbar_re = 0.0;
  109. } else if (xbar_re == 0.0) {
  110. bsum_re = 0.0;
  111. xbar_re = xbar_im / static_cast<double>(x.size(1));
  112. } else {
  113. bsum_re = xbar_re / static_cast<double>(x.size(1));
  114. xbar_re = xbar_im / static_cast<double>(x.size(1));
  115. }
  116. absdiff.set_size(x.size(1));
  117. for (k = 0; k < n; k++) {
  118. absdiff[k] = rt_hypotd_snf(x[k].re - bsum_re, x[k].im - xbar_re);
  119. }
  120. y = 0.0;
  121. xbar_re = 3.3121686421112381E-170;
  122. firstBlockLength = x.size(1);
  123. for (k = 0; k < firstBlockLength; k++) {
  124. if (absdiff[k] > xbar_re) {
  125. bsum_re = xbar_re / absdiff[k];
  126. y = y * bsum_re * bsum_re + 1.0;
  127. xbar_re = absdiff[k];
  128. } else {
  129. bsum_re = absdiff[k] / xbar_re;
  130. y += bsum_re * bsum_re;
  131. }
  132. }
  133. y = xbar_re * std::sqrt(y);
  134. y /= std::sqrt(static_cast<double>(x.size(1)) - 1.0);
  135. }
  136. return y;
  137. }
  138. } // namespace coder
  139. //
  140. // File trailer for std.cpp
  141. //
  142. // [EOF]
  143. //