RadarSignalGenerator401.cpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // Academic License - for use in teaching, academic research, and meeting
  3. // course requirements at degree granting institutions only. Not for
  4. // government, commercial, or other organizational use.
  5. // File: RadarSignalGenerator401.cpp
  6. //
  7. // MATLAB Coder version : 5.3
  8. // C/C++ source code generated on : 27-Apr-2023 00:06:45
  9. //
  10. // Include Files
  11. #include "RadarSignalGenerator401.h"
  12. #include "FMCWWaveform401.h"
  13. #include "../rt_nonfinite.h"
  14. #include "../coder_array.h"
  15. #include <cmath>
  16. // Function Declarations
  17. static void times(coder::array<creal_T, 1U> &xt,
  18. const coder::array<creal_T, 1U> &r);
  19. // Function Definitions
  20. //
  21. // Arguments : coder::array<creal_T, 1U> &xt
  22. // const coder::array<creal_T, 1U> &r
  23. // Return Type : void
  24. //
  25. static void times(coder::array<creal_T, 1U> &xt,
  26. const coder::array<creal_T, 1U> &r)
  27. {
  28. coder::array<creal_T, 1U> b_xt;
  29. int i;
  30. int loop_ub;
  31. int stride_0_0;
  32. int stride_1_0;
  33. if (r.size(0) == 1) {
  34. i = xt.size(0);
  35. } else {
  36. i = r.size(0);
  37. }
  38. b_xt.set_size(i);
  39. stride_0_0 = (xt.size(0) != 1);
  40. stride_1_0 = (r.size(0) != 1);
  41. if (r.size(0) == 1) {
  42. loop_ub = xt.size(0);
  43. } else {
  44. loop_ub = r.size(0);
  45. }
  46. for (i = 0; i < loop_ub; i++) {
  47. double d;
  48. double d1;
  49. int i1;
  50. i1 = i * stride_1_0;
  51. d = r[i1].im;
  52. d1 = r[i1].re;
  53. b_xt[i].re = xt[i * stride_0_0].re * d1 - xt[i * stride_0_0].im * d;
  54. b_xt[i].im = xt[i * stride_0_0].re * d + xt[i * stride_0_0].im * d1;
  55. }
  56. xt.set_size(b_xt.size(0));
  57. loop_ub = b_xt.size(0);
  58. for (i = 0; i < loop_ub; i++) {
  59. xt[i] = b_xt[i];
  60. }
  61. }
  62. //
  63. // RADARSIGNALGENERATOR1 此处显示有关此函数的摘要
  64. // 此处显示详细说明
  65. //
  66. // Arguments : coder::array<double, 1U> &sig
  67. // double *fs
  68. // double PRF[3]
  69. // double *len
  70. // Return Type : void
  71. //
  72. void RadarSignalGenerator401(coder::array<double, 1U> &sig, double *fs,
  73. double PRF[3], double *len)
  74. {
  75. static coder::phased::FMCWWaveform401 wavGen;
  76. static const int iv[3]{1, 40001, 100001};
  77. static const int iv1[3]{40000, 100000, 180000};
  78. coder::array<creal_T, 1U> r1;
  79. coder::array<creal_T, 1U> xt;
  80. coder::array<double, 2U> r;
  81. coder::array<double, 1U> b_xt;
  82. double idx;
  83. int i;
  84. int ii;
  85. int mode;
  86. int ndbl;
  87. PRF[0] = 500000.0;
  88. PRF[1] = 333333.33333333331;
  89. PRF[2] = 250000.0;
  90. // simTime = 2e-5;
  91. wavGen.isInitialized = 0;
  92. // 产生5个脉冲
  93. // numPulses = fix(simTime*PRF);
  94. *len = 0.0;
  95. for (ii = 0; ii < 5; ii++) {
  96. mode = static_cast<int>(std::fmod(static_cast<double>(ii) + 1.0, 3.0));
  97. if (mode == 0) {
  98. mode = 3;
  99. }
  100. *len += 2.0E+10 / PRF[mode - 1];
  101. }
  102. ndbl = static_cast<int>(*len);
  103. sig.set_size(ndbl);
  104. for (i = 0; i < ndbl; i++) {
  105. sig[i] = 0.0;
  106. }
  107. idx = 1.0;
  108. for (ii = 0; ii < 5; ii++) {
  109. double InitOutputSweepIndex_idx_0;
  110. double cdiff;
  111. double kd;
  112. int k;
  113. int nm1d2;
  114. mode = static_cast<int>(std::fmod(static_cast<double>(ii) + 1.0, 3.0));
  115. if (mode == 0) {
  116. mode = 3;
  117. }
  118. // 迭代波形
  119. if (wavGen.isInitialized != 1) {
  120. wavGen.isInitialized = 1;
  121. wavGen.setupImpl();
  122. wavGen.pOutputStartSweepIndex = 1.0;
  123. wavGen.pOutputSweepInterval[0] = 0.0;
  124. wavGen.pOutputSweepInterval[1] = 1.0;
  125. }
  126. kd = (wavGen.pOutputStartSweepIndex + wavGen.pOutputSweepInterval[0]) - 1.0;
  127. if (std::isnan(kd) || std::isinf(kd)) {
  128. cdiff = rtNaN;
  129. } else if (kd == 0.0) {
  130. cdiff = 0.0;
  131. } else {
  132. cdiff = std::fmod(kd, 3.0);
  133. if (cdiff == 0.0) {
  134. cdiff = 0.0;
  135. } else if (kd < 0.0) {
  136. cdiff += 3.0;
  137. }
  138. }
  139. InitOutputSweepIndex_idx_0 = cdiff + 1.0;
  140. kd = (wavGen.pOutputStartSweepIndex + wavGen.pOutputSweepInterval[1]) - 1.0;
  141. if (std::isnan(kd) || std::isinf(kd)) {
  142. cdiff = rtNaN;
  143. } else if (kd == 0.0) {
  144. cdiff = 0.0;
  145. } else {
  146. cdiff = std::fmod(kd, 3.0);
  147. if (cdiff == 0.0) {
  148. cdiff = 0.0;
  149. } else if (kd < 0.0) {
  150. cdiff += 3.0;
  151. }
  152. }
  153. wavGen.pOutputStartSweepIndex = cdiff + 1.0;
  154. ndbl = 20000 * (static_cast<int>(InitOutputSweepIndex_idx_0) - 1);
  155. xt.set_size(ndbl + 40000);
  156. for (i = 0; i <= ndbl + 39999; i++) {
  157. xt[i].re = 0.0;
  158. xt[i].im = 0.0;
  159. }
  160. i = iv[static_cast<int>(InitOutputSweepIndex_idx_0) - 1];
  161. k = iv1[static_cast<int>(InitOutputSweepIndex_idx_0) - 1];
  162. if (i > k) {
  163. i = 0;
  164. k = 0;
  165. } else {
  166. i--;
  167. }
  168. ndbl = k - i;
  169. for (k = 0; k < ndbl; k++) {
  170. xt[k] = wavGen.pSamples[i + k];
  171. }
  172. // 载波调制
  173. kd = (static_cast<double>(xt.size(0)) - 1.0) / 2.0E+10;
  174. ndbl = static_cast<int>(std::floor(kd / 5.0E-11 + 0.5));
  175. InitOutputSweepIndex_idx_0 = static_cast<double>(ndbl) * 5.0E-11;
  176. cdiff = InitOutputSweepIndex_idx_0 - kd;
  177. if (std::abs(cdiff) < 4.4408920985006262E-16 * std::abs(kd)) {
  178. ndbl++;
  179. InitOutputSweepIndex_idx_0 = kd;
  180. } else if (cdiff > 0.0) {
  181. InitOutputSweepIndex_idx_0 = (static_cast<double>(ndbl) - 1.0) * 5.0E-11;
  182. } else {
  183. ndbl++;
  184. }
  185. r.set_size(1, ndbl);
  186. r[0] = 0.0;
  187. r[ndbl - 1] = InitOutputSweepIndex_idx_0;
  188. nm1d2 = (ndbl - 1) / 2;
  189. for (k = 0; k <= nm1d2 - 2; k++) {
  190. kd = (static_cast<double>(k) + 1.0) * 5.0E-11;
  191. r[k + 1] = kd;
  192. r[(ndbl - k) - 2] = InitOutputSweepIndex_idx_0 - kd;
  193. }
  194. if (nm1d2 << 1 == ndbl - 1) {
  195. r[nm1d2] = InitOutputSweepIndex_idx_0 / 2.0;
  196. } else {
  197. kd = static_cast<double>(nm1d2) * 5.0E-11;
  198. r[nm1d2] = kd;
  199. r[nm1d2 + 1] = InitOutputSweepIndex_idx_0 - kd;
  200. }
  201. r1.set_size(r.size(1));
  202. ndbl = r.size(1);
  203. for (i = 0; i < ndbl; i++) {
  204. r1[i].re = r[i] * 0.0;
  205. r1[i].im = r[i] * 5.969026041820607E+10;
  206. }
  207. ndbl = r1.size(0);
  208. for (k = 0; k < ndbl; k++) {
  209. if (r1[k].im == 0.0) {
  210. r1[k].re = std::exp(r1[k].re);
  211. r1[k].im = 0.0;
  212. } else if (std::isinf(r1[k].im) && std::isinf(r1[k].re) &&
  213. (r1[k].re < 0.0)) {
  214. r1[k].re = 0.0;
  215. r1[k].im = 0.0;
  216. } else {
  217. cdiff = std::exp(r1[k].re / 2.0);
  218. r1[k].re = cdiff * (cdiff * std::cos(r1[k].im));
  219. r1[k].im = cdiff * (cdiff * std::sin(r1[k].im));
  220. }
  221. }
  222. if (xt.size(0) == r1.size(0)) {
  223. ndbl = xt.size(0);
  224. for (i = 0; i < ndbl; i++) {
  225. double re_tmp;
  226. kd = xt[i].re;
  227. InitOutputSweepIndex_idx_0 = r1[i].im;
  228. cdiff = xt[i].im;
  229. re_tmp = r1[i].re;
  230. xt[i].re = kd * re_tmp - cdiff * InitOutputSweepIndex_idx_0;
  231. xt[i].im = kd * InitOutputSweepIndex_idx_0 + cdiff * re_tmp;
  232. }
  233. } else {
  234. times(xt, r1);
  235. }
  236. kd = idx + 2.0E+10 / PRF[mode - 1];
  237. if (idx > kd - 1.0) {
  238. i = -1;
  239. k = 0;
  240. } else {
  241. i = static_cast<int>(idx) - 2;
  242. k = static_cast<int>(kd - 1.0);
  243. }
  244. b_xt.set_size(xt.size(0));
  245. ndbl = xt.size(0);
  246. for (nm1d2 = 0; nm1d2 < ndbl; nm1d2++) {
  247. b_xt[nm1d2] = xt[nm1d2].re;
  248. }
  249. ndbl = (k - i) - 1;
  250. for (k = 0; k < ndbl; k++) {
  251. sig[(i + k) + 1] = b_xt[k];
  252. }
  253. idx = kd;
  254. }
  255. *fs = 2.0E+10;
  256. }
  257. //
  258. // File trailer for RadarSignalGenerator401.cpp
  259. //
  260. // [EOF]
  261. //