RadarSignalGenerator301.cpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  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: RadarSignalGenerator301.cpp
  6. //
  7. // MATLAB Coder version : 5.3
  8. // C/C++ source code generated on : 27-Apr-2023 00:24:12
  9. //
  10. // Include Files
  11. #include "RadarSignalGenerator301.h"
  12. #include "AbstractLinearFMWaveform301.h"
  13. #include "LinearFMWaveform301.h"
  14. #include "../rt_nonfinite.h"
  15. #include "../coder_array.h"
  16. #include <cmath>
  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 RadarSignalGenerator301(coder::array<double, 1U> &sig, double *fs,
  74. double PRF[3], double *len)
  75. {
  76. coder::phased::LinearFMWaveform301 wavGen;
  77. coder::array<creal_T, 1U> r;
  78. coder::array<creal_T, 1U> r1;
  79. coder::array<creal_T, 1U> r3;
  80. coder::array<creal_T, 1U> xt;
  81. coder::array<double, 2U> r2;
  82. coder::array<double, 1U> b_xt;
  83. double idx;
  84. int ii;
  85. int k;
  86. int mode;
  87. int ndbl;
  88. PRF[0] = 500000.0;
  89. PRF[1] = 333333.33333333331;
  90. PRF[2] = 250000.0;
  91. // simTime = 2e-5;
  92. wavGen.isInitialized = 0;
  93. wavGen.matlabCodegenIsDeleted = false;
  94. // 相位编码定义
  95. // 产生5个脉冲
  96. // numPulses = fix(simTime*PRF);
  97. *len = 0.0;
  98. for (ii = 0; ii < 5; ii++) {
  99. mode = static_cast<int>(std::fmod(static_cast<double>(ii) + 1.0, 3.0));
  100. if (mode == 0) {
  101. mode = 3;
  102. }
  103. *len += 2.0E+10 / PRF[mode - 1];
  104. }
  105. ndbl = static_cast<int>(*len);
  106. sig.set_size(ndbl);
  107. for (k = 0; k < ndbl; k++) {
  108. sig[k] = 0.0;
  109. }
  110. idx = 1.0;
  111. for (ii = 0; ii < 5; ii++) {
  112. double OutputPulseIndex_idx_0;
  113. double cdiff;
  114. double kd;
  115. int nm1d2;
  116. mode = static_cast<int>(std::fmod(static_cast<double>(ii) + 1.0, 3.0));
  117. if (mode == 0) {
  118. mode = 3;
  119. }
  120. // 迭代波形
  121. if (wavGen.isInitialized != 1) {
  122. wavGen.isInitialized = 1;
  123. wavGen.isSetupComplete = true;
  124. wavGen.pOutputStartPulseIndex = 1.0;
  125. wavGen.pOutputPulseInterval[0] = 0.0;
  126. wavGen.pOutputPulseInterval[1] = 1.0;
  127. }
  128. kd = (wavGen.pOutputStartPulseIndex + wavGen.pOutputPulseInterval[0]) - 1.0;
  129. if (std::isnan(kd) || std::isinf(kd)) {
  130. cdiff = rtNaN;
  131. } else if (kd == 0.0) {
  132. cdiff = 0.0;
  133. } else {
  134. cdiff = std::fmod(kd, 3.0);
  135. if (cdiff == 0.0) {
  136. cdiff = 0.0;
  137. } else if (kd < 0.0) {
  138. cdiff += 3.0;
  139. }
  140. }
  141. OutputPulseIndex_idx_0 = cdiff + 1.0;
  142. kd = (wavGen.pOutputStartPulseIndex + wavGen.pOutputPulseInterval[1]) - 1.0;
  143. if (std::isnan(kd) || std::isinf(kd)) {
  144. cdiff = rtNaN;
  145. } else if (kd == 0.0) {
  146. cdiff = 0.0;
  147. } else {
  148. cdiff = std::fmod(kd, 3.0);
  149. if (cdiff == 0.0) {
  150. cdiff = 0.0;
  151. } else if (kd < 0.0) {
  152. cdiff += 3.0;
  153. }
  154. }
  155. wavGen.pOutputStartPulseIndex = cdiff + 1.0;
  156. ndbl = 20000 * (static_cast<int>(OutputPulseIndex_idx_0) - 1);
  157. xt.set_size(ndbl + 40000);
  158. for (k = 0; k <= ndbl + 39999; k++) {
  159. xt[k].re = 0.0;
  160. xt[k].im = 0.0;
  161. }
  162. coder::phased::AbstractLinearFMWaveform301::getMatchingWaveform(r);
  163. for (k = 0; k < 20000; k++) {
  164. xt[k] = r[k];
  165. }
  166. coder::phased::AbstractLinearFMWaveform301::getMatchingWaveform(r1);
  167. // 载波调制
  168. kd = (static_cast<double>(xt.size(0)) - 1.0) / 2.0E+10;
  169. ndbl = static_cast<int>(std::floor(kd / 5.0E-11 + 0.5));
  170. OutputPulseIndex_idx_0 = static_cast<double>(ndbl) * 5.0E-11;
  171. cdiff = OutputPulseIndex_idx_0 - kd;
  172. if (std::abs(cdiff) < 4.4408920985006262E-16 * std::abs(kd)) {
  173. ndbl++;
  174. OutputPulseIndex_idx_0 = kd;
  175. } else if (cdiff > 0.0) {
  176. OutputPulseIndex_idx_0 = (static_cast<double>(ndbl) - 1.0) * 5.0E-11;
  177. } else {
  178. ndbl++;
  179. }
  180. r2.set_size(1, ndbl);
  181. r2[0] = 0.0;
  182. r2[ndbl - 1] = OutputPulseIndex_idx_0;
  183. nm1d2 = (ndbl - 1) / 2;
  184. for (k = 0; k <= nm1d2 - 2; k++) {
  185. kd = (static_cast<double>(k) + 1.0) * 5.0E-11;
  186. r2[k + 1] = kd;
  187. r2[(ndbl - k) - 2] = OutputPulseIndex_idx_0 - kd;
  188. }
  189. if (nm1d2 << 1 == ndbl - 1) {
  190. r2[nm1d2] = OutputPulseIndex_idx_0 / 2.0;
  191. } else {
  192. kd = static_cast<double>(nm1d2) * 5.0E-11;
  193. r2[nm1d2] = kd;
  194. r2[nm1d2 + 1] = OutputPulseIndex_idx_0 - kd;
  195. }
  196. r3.set_size(r2.size(1));
  197. ndbl = r2.size(1);
  198. for (k = 0; k < ndbl; k++) {
  199. r3[k].re = r2[k] * 0.0;
  200. r3[k].im = r2[k] * 5.969026041820607E+10;
  201. }
  202. ndbl = r3.size(0);
  203. for (k = 0; k < ndbl; k++) {
  204. if (r3[k].im == 0.0) {
  205. r3[k].re = std::exp(r3[k].re);
  206. r3[k].im = 0.0;
  207. } else if (std::isinf(r3[k].im) && std::isinf(r3[k].re) &&
  208. (r3[k].re < 0.0)) {
  209. r3[k].re = 0.0;
  210. r3[k].im = 0.0;
  211. } else {
  212. cdiff = std::exp(r3[k].re / 2.0);
  213. r3[k].re = cdiff * (cdiff * std::cos(r3[k].im));
  214. r3[k].im = cdiff * (cdiff * std::sin(r3[k].im));
  215. }
  216. }
  217. if (xt.size(0) == r3.size(0)) {
  218. ndbl = xt.size(0);
  219. for (k = 0; k < ndbl; k++) {
  220. double re_tmp;
  221. kd = xt[k].re;
  222. OutputPulseIndex_idx_0 = r3[k].im;
  223. cdiff = xt[k].im;
  224. re_tmp = r3[k].re;
  225. xt[k].re = kd * re_tmp - cdiff * OutputPulseIndex_idx_0;
  226. xt[k].im = kd * OutputPulseIndex_idx_0 + cdiff * re_tmp;
  227. }
  228. } else {
  229. times(xt, r3);
  230. }
  231. kd = idx + 2.0E+10 / PRF[mode - 1];
  232. if (idx > kd - 1.0) {
  233. k = -1;
  234. nm1d2 = 0;
  235. } else {
  236. k = static_cast<int>(idx) - 2;
  237. nm1d2 = static_cast<int>(kd - 1.0);
  238. }
  239. b_xt.set_size(xt.size(0));
  240. ndbl = xt.size(0);
  241. for (mode = 0; mode < ndbl; mode++) {
  242. b_xt[mode] = xt[mode].re;
  243. }
  244. ndbl = (nm1d2 - k) - 1;
  245. for (nm1d2 = 0; nm1d2 < ndbl; nm1d2++) {
  246. sig[(k + nm1d2) + 1] = b_xt[nm1d2];
  247. }
  248. idx = kd;
  249. }
  250. wavGen.matlabCodegenDestructor();
  251. *fs = 2.0E+10;
  252. }
  253. //
  254. // File trailer for RadarSignalGenerator301.cpp
  255. //
  256. // [EOF]
  257. //