RadarSignalGenerator101.cpp 7.6 KB

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