fun5.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. //
  2. // File: S_orignal_2.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 05-Mar-2023 15:19:40
  6. //
  7. // Include Files
  8. #include "fun5.h"
  9. #include "colon.h"
  10. #include "rt_nonfinite.h"
  11. #include "coder_array.h"
  12. #include <cmath>
  13. #include <iostream>
  14. // Function Definitions
  15. //
  16. // Arguments : double fd
  17. // double N
  18. // double ts
  19. // double Tr
  20. // double t_r
  21. // double tau
  22. // double fo
  23. // double k
  24. // coder::array<double, 2U> &S
  25. // Return Type : void
  26. //
  27. void S_orignal_2(double fd, double N, double ts, double Tr, double t_r, double tau,
  28. double fo, double k, coder::array<double, 2U> &S)
  29. {
  30. coder::array<double, 2U> b_b;
  31. coder::array<signed char, 2U> Signal_Radar;
  32. coder::array<signed char, 2U> rect;
  33. double a;
  34. double b;
  35. double b_a;
  36. int ncols;
  37. int ntilecols;
  38. b = Tr - ts;
  39. if (std::isnan(ts) || std::isnan(b)) {
  40. S.set_size(1, 1);
  41. S[0] = rtNaN;
  42. } else if ((ts == 0.0) || ((0.0 < b) && (ts < 0.0)) ||
  43. ((b < 0.0) && (ts > 0.0))) {
  44. S.set_size(1, 0);
  45. } else if (std::isinf(b) && (std::isinf(ts) || (0.0 == b))) {
  46. S.set_size(1, 1);
  47. S[0] = rtNaN;
  48. } else if (std::isinf(ts)) {
  49. S.set_size(1, 1);
  50. S[0] = 0.0;
  51. } else if (std::floor(ts) == ts) {
  52. ncols = static_cast<int>(std::floor(b / ts));
  53. S.set_size(1, ncols + 1);
  54. for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
  55. S[ntilecols] = ts * static_cast<double>(ntilecols);
  56. }
  57. } else {
  58. coder::eml_float_colon(ts, b, S);
  59. }
  60. rect.set_size(1, S.size(1));
  61. ncols = S.size(1);
  62. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  63. rect[ntilecols] = 0;
  64. }
  65. ntilecols = S.size(1);
  66. for (ncols = 0; ncols < ntilecols; ncols++) {
  67. b = S[ncols];
  68. if ((b >= t_r) && (b <= tau + t_r)) {
  69. rect[ncols] = 1;
  70. }
  71. }
  72. b = N * Tr - ts;
  73. if (std::isnan(ts) || std::isnan(b)) {
  74. S.set_size(1, 1);
  75. S[0] = rtNaN;
  76. } else if ((ts == 0.0) || ((0.0 < b) && (ts < 0.0)) ||
  77. ((b < 0.0) && (ts > 0.0))) {
  78. S.set_size(S.size(0), 0);
  79. } else if (std::isinf(b) && (std::isinf(ts) || (0.0 == b))) {
  80. S.set_size(1, 1);
  81. S[0] = rtNaN;
  82. } else if (std::isinf(ts)) {
  83. S.set_size(1, 1);
  84. S[0] = 0.0;
  85. } else if (std::floor(ts) == ts) {
  86. ncols = static_cast<int>(std::floor(b / ts));
  87. S.set_size(1, ncols + 1);
  88. for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
  89. S[ntilecols] = ts * static_cast<double>(ntilecols);
  90. }
  91. } else {
  92. coder::eml_float_colon(ts, b, S);
  93. }
  94. Signal_Radar.set_size(1, rect.size(1) * static_cast<int>(N));
  95. ncols = rect.size(1);
  96. ntilecols = static_cast<int>(N);
  97. for (int jtilecol{0}; jtilecol < ntilecols; jtilecol++) {
  98. int ibtile;
  99. ibtile = jtilecol * ncols;
  100. for (int jcol{0}; jcol < ncols; jcol++) {
  101. Signal_Radar[ibtile + jcol] = rect[jcol];
  102. }
  103. }
  104. a = 6.2831853071795862 * (fo + fd);
  105. S.set_size(1, S.size(1));
  106. ncols = S.size(1) - 1;
  107. for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
  108. S[ntilecols] = S[ntilecols] - t_r;
  109. }
  110. b_a = 3.1415926535897931 * k;
  111. b_b.set_size(1, S.size(1));
  112. ncols = S.size(1);
  113. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  114. b = S[ntilecols];
  115. b_b[ntilecols] = b * b;
  116. }
  117. S.set_size(1, S.size(1));
  118. ncols = S.size(1) - 1;
  119. for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
  120. S[ntilecols] = a * S[ntilecols] + b_a * b_b[ntilecols];
  121. }
  122. ncols = S.size(1);
  123. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  124. S[ntilecols] = std::cos(S[ntilecols]);
  125. }
  126. S.set_size(1, Signal_Radar.size(1));
  127. ncols = Signal_Radar.size(1) - 1;
  128. for (ntilecols = 0; ntilecols <= ncols; ntilecols++) {
  129. S[ntilecols] = static_cast<double>(Signal_Radar[ntilecols]) * S[ntilecols];
  130. }
  131. }
  132. //int main()
  133. //{
  134. // coder::array<double, 2U> S;
  135. // double fd = 40;
  136. // double N = 1;
  137. // double ts = 1.0000e-07;
  138. // double Tr = 4.0000e-04;
  139. // double t_r = 2.0000e-04;
  140. // double tau = 1.0000e-04;
  141. // double fo = 1e6;
  142. // double k = 1.0000e+11;
  143. //
  144. // // Call the entry-point 'S_orignal_2'.
  145. // S_orignal_2(fd, N, ts, Tr, t_r, tau, fo, k, S);
  146. // // 输出结果
  147. // for (int i = 0; i < S.size(1); i++) {
  148. // std::cout << S[i] << " ";
  149. // }
  150. // std::cout << std::endl;
  151. // return 0;
  152. //}