RadarSignalGenerator201.cpp 7.2 KB

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