fun10_multifx.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  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: multifx.cpp
  6. //
  7. // MATLAB Coder version : 5.3
  8. // C/C++ source code generated on : 27-Mar-2023 15:34:32
  9. //
  10. // Include Files
  11. #include "fun10_multifx.h"
  12. #include "fun10_distcal.h"
  13. #include "fun10_histcounts.h"
  14. #include "rt_nonfinite.h"
  15. #include "fun10_sort.h"
  16. #include "coder_array.h"
  17. #include <algorithm>
  18. #include <cmath>
  19. // Type Definitions
  20. struct emxArray_real_T_1x25 {
  21. double data[25];
  22. int size[2];
  23. };
  24. struct cell_wrap_0 {
  25. emxArray_real_T_1x25 f1;
  26. };
  27. // Function Definitions
  28. //
  29. // MULTIFX 多站时差分选
  30. // 此处显示详细说明
  31. // %% 1. 数据生成
  32. // 做传输时间
  33. //
  34. // Arguments : const coder::array<double, 2U> &RadarCart
  35. // const coder::array<double, 2U> &ZCPlatCart
  36. // double N_data[]
  37. // int N_size[2]
  38. // double edges_data[]
  39. // int edges_size[2]
  40. // Return Type : void
  41. //
  42. void multifx(const coder::array<double, 2U> &RadarCart,
  43. const coder::array<double, 2U> &ZCPlatCart, double N_data[],
  44. int N_size[2], double edges_data[], int edges_size[2])
  45. {
  46. static const double PulseITime[25]{0.0001,
  47. 0.0002,
  48. 0.00030000000000000003,
  49. 0.0004,
  50. 0.0005,
  51. 0.00060000000000000006,
  52. 0.0007000000000000001,
  53. 0.0008,
  54. 0.00090000000000000008,
  55. 0.001,
  56. 0.0011,
  57. 0.0012000000000000001,
  58. 0.0013,
  59. 0.0014,
  60. 0.0015,
  61. 0.0015999999999999999,
  62. 0.0017000000000000001,
  63. 0.0018,
  64. 0.0019,
  65. 0.002,
  66. 0.0021,
  67. 0.0022,
  68. 0.0023,
  69. 0.0024000000000000002,
  70. 0.0025};
  71. static const double PulseCTime[16]{0.00013, 0.00043999999999999996,
  72. 0.00075, 0.00106,
  73. 0.00137, 0.00168,
  74. 0.00199, 0.0023,
  75. 0.00031, 0.00062,
  76. 0.00093, 0.00124,
  77. 0.00155, 0.00186,
  78. 0.00217, 0.00248};
  79. static const double PulseDTime[16]{0.00012,
  80. 0.00045,
  81. 0.00078,
  82. 0.00111,
  83. 0.0014399999999999999,
  84. 0.0017699999999999999,
  85. 0.0021,
  86. 0.00243,
  87. 0.00033,
  88. 0.00066,
  89. 0.00099,
  90. 0.00132,
  91. 0.00165,
  92. 0.00198,
  93. 0.00231,
  94. 0.00264};
  95. static const double PulseGTime[16]{0.00015,
  96. 0.0003,
  97. 0.00045,
  98. 0.0006,
  99. 0.00074999999999999991,
  100. 0.00089999999999999987,
  101. 0.00105,
  102. 0.0012,
  103. 0.0013499999999999999,
  104. 0.0014999999999999998,
  105. 0.00165,
  106. 0.0018,
  107. 0.00195,
  108. 0.0021,
  109. 0.00225,
  110. 0.0024};
  111. static const double PulseFTime[15]{0.00016,
  112. 0.00032,
  113. 0.00048000000000000007,
  114. 0.00064,
  115. 0.0008,
  116. 0.00096,
  117. 0.0011200000000000001,
  118. 0.00128,
  119. 0.00144,
  120. 0.0016000000000000003,
  121. 0.0017600000000000003,
  122. 0.0019200000000000003,
  123. 0.0020800000000000003,
  124. 0.0022400000000000002,
  125. 0.0024000000000000002};
  126. coder::array<double, 2U> TDOARecordYY;
  127. coder::array<double, 2U> TOAA;
  128. coder::array<double, 2U> TOAB;
  129. coder::array<double, 2U> TransTime;
  130. cell_wrap_0 RadarPulseTime[7];
  131. cell_wrap_0 r;
  132. cell_wrap_0 r1;
  133. cell_wrap_0 r2;
  134. cell_wrap_0 r3;
  135. cell_wrap_0 r4;
  136. cell_wrap_0 r5;
  137. cell_wrap_0 r6;
  138. double dv[16];
  139. double RadarCart_data[3];
  140. double ZCPlatCart_data[3];
  141. double RadarTotal;
  142. double TDOAWindow;
  143. int RadarCart_size[2];
  144. int ZCPlatCart_size[2];
  145. unsigned int TOAAcnt;
  146. int b_i;
  147. int b_u1;
  148. int c_u1;
  149. int i;
  150. int loop_ub;
  151. int n;
  152. int u0;
  153. int u1;
  154. if ((ZCPlatCart.size(0) == 0) || (ZCPlatCart.size(1) == 0)) {
  155. n = 1;
  156. } else if (ZCPlatCart.size(0) > ZCPlatCart.size(1)) {
  157. n = ZCPlatCart.size(0) + 1;
  158. } else {
  159. n = ZCPlatCart.size(1) + 1;
  160. }
  161. if ((RadarCart.size(0) == 0) || (RadarCart.size(1) == 0)) {
  162. u1 = 0;
  163. } else {
  164. u0 = RadarCart.size(0);
  165. u1 = RadarCart.size(1);
  166. if (u0 >= u1) {
  167. u1 = u0;
  168. }
  169. }
  170. TransTime.set_size(n, u1);
  171. n *= u1;
  172. for (i = 0; i < n; i++) {
  173. TransTime[i] = 0.0;
  174. }
  175. if ((ZCPlatCart.size(0) == 0) || (ZCPlatCart.size(1) == 0)) {
  176. u1 = 0;
  177. } else {
  178. u0 = ZCPlatCart.size(0);
  179. u1 = ZCPlatCart.size(1);
  180. if (u0 >= u1) {
  181. u1 = u0;
  182. }
  183. if ((RadarCart.size(0) == 0) || (RadarCart.size(1) == 0)) {
  184. b_u1 = 0;
  185. } else {
  186. u0 = RadarCart.size(0);
  187. b_u1 = RadarCart.size(1);
  188. if (u0 >= b_u1) {
  189. b_u1 = u0;
  190. }
  191. }
  192. }
  193. for (b_i = 0; b_i < u1; b_i++) {
  194. if (0 <= b_u1 - 1) {
  195. n = ZCPlatCart.size(1);
  196. ZCPlatCart_size[0] = 1;
  197. ZCPlatCart_size[1] = ZCPlatCart.size(1);
  198. loop_ub = RadarCart.size(1);
  199. RadarCart_size[0] = 1;
  200. RadarCart_size[1] = RadarCart.size(1);
  201. for (i = 0; i < n; i++) {
  202. ZCPlatCart_data[i] = ZCPlatCart[b_i + ZCPlatCart.size(0) * i];
  203. }
  204. }
  205. for (u0 = 0; u0 < b_u1; u0++) {
  206. for (i = 0; i < loop_ub; i++) {
  207. RadarCart_data[i] = RadarCart[u0 + RadarCart.size(0) * i];
  208. }
  209. TransTime[b_i + TransTime.size(0) * u0] =
  210. b_distcal(ZCPlatCart_data, ZCPlatCart_size, RadarCart_data,
  211. RadarCart_size) /
  212. 2.99792458E+8;
  213. }
  214. }
  215. if ((RadarCart.size(0) == 0) || (RadarCart.size(1) == 0)) {
  216. u1 = 0;
  217. } else {
  218. u0 = RadarCart.size(0);
  219. u1 = RadarCart.size(1);
  220. if (u0 >= u1) {
  221. u1 = u0;
  222. }
  223. if ((ZCPlatCart.size(0) == 0) || (ZCPlatCart.size(1) == 0)) {
  224. c_u1 = 0;
  225. } else {
  226. u0 = ZCPlatCart.size(0);
  227. c_u1 = ZCPlatCart.size(1);
  228. if (u0 >= c_u1) {
  229. c_u1 = u0;
  230. }
  231. }
  232. }
  233. for (u0 = 0; u0 < u1; u0++) {
  234. TransTime[c_u1 + TransTime.size(0) * u0] =
  235. TransTime[TransTime.size(0) * u0] -
  236. TransTime[TransTime.size(0) * u0 + 1];
  237. }
  238. // %% 2. 时差窗
  239. // 理论时差窗
  240. n = ZCPlatCart.size(1);
  241. ZCPlatCart_size[0] = 1;
  242. ZCPlatCart_size[1] = ZCPlatCart.size(1);
  243. for (i = 0; i < n; i++) {
  244. ZCPlatCart_data[i] = ZCPlatCart[ZCPlatCart.size(0) * i];
  245. }
  246. n = ZCPlatCart.size(1);
  247. RadarCart_size[0] = 1;
  248. RadarCart_size[1] = ZCPlatCart.size(1);
  249. for (i = 0; i < n; i++) {
  250. RadarCart_data[i] = ZCPlatCart[ZCPlatCart.size(0) * i + 1];
  251. }
  252. // 考虑误差
  253. TDOAWindow = b_distcal(ZCPlatCart_data, ZCPlatCart_size, RadarCart_data,
  254. RadarCart_size) /
  255. 2.99792458E+8 +
  256. 1.7E-8;
  257. // %% 3. 脉冲流计算
  258. // 仿真时间
  259. // 辐射源c: 130us 180us二参差
  260. // 辐射源d:120us 210us二参差
  261. // 辐射源e: 170us
  262. // 辐射源f: 160us
  263. // 辐射源g: 150us
  264. // 辐射源h: 140us
  265. // 辐射源i: 100us
  266. std::copy(&PulseCTime[0], &PulseCTime[16], &dv[0]);
  267. coder::internal::sort(dv);
  268. r.f1.size[0] = 1;
  269. r.f1.size[1] = 16;
  270. for (i = 0; i < 16; i++) {
  271. r.f1.data[i] = dv[i];
  272. dv[i] = PulseDTime[i];
  273. }
  274. coder::internal::sort(dv);
  275. r1.f1.size[0] = 1;
  276. r1.f1.size[1] = 16;
  277. std::copy(&dv[0], &dv[16], &r1.f1.data[0]);
  278. r2.f1.size[0] = 1;
  279. r2.f1.size[1] = 14;
  280. for (i = 0; i < 14; i++) {
  281. r2.f1.data[i] = 0.00017 * static_cast<double>(i) + 0.00017;
  282. }
  283. r3.f1.size[0] = 1;
  284. r3.f1.size[1] = 15;
  285. std::copy(&PulseFTime[0], &PulseFTime[15], &r3.f1.data[0]);
  286. r4.f1.size[0] = 1;
  287. r4.f1.size[1] = 16;
  288. std::copy(&PulseGTime[0], &PulseGTime[16], &r4.f1.data[0]);
  289. r5.f1.size[0] = 1;
  290. r5.f1.size[1] = 17;
  291. for (i = 0; i < 17; i++) {
  292. r5.f1.data[i] = 0.00014 * static_cast<double>(i) + 0.00014;
  293. }
  294. r6.f1.size[0] = 1;
  295. r6.f1.size[1] = 25;
  296. std::copy(&PulseITime[0], &PulseITime[25], &r6.f1.data[0]);
  297. RadarPulseTime[0] = r;
  298. RadarPulseTime[1] = r1;
  299. RadarPulseTime[2] = r2;
  300. RadarPulseTime[3] = r3;
  301. RadarPulseTime[4] = r4;
  302. RadarPulseTime[5] = r5;
  303. RadarPulseTime[6] = r6;
  304. // %% 4. 脉冲序列
  305. RadarTotal = 0.0;
  306. for (b_i = 0; b_i < 7; b_i++) {
  307. RadarTotal += static_cast<double>(RadarPulseTime[b_i].f1.size[1]);
  308. }
  309. n = static_cast<int>(RadarTotal);
  310. TOAA.set_size(1, n);
  311. for (i = 0; i < n; i++) {
  312. TOAA[i] = 0.0;
  313. }
  314. TOAAcnt = 0U;
  315. // 主站
  316. for (b_i = 0; b_i < 7; b_i++) {
  317. i = RadarPulseTime[b_i].f1.size[1];
  318. for (u0 = 0; u0 < i; u0++) {
  319. RadarTotal =
  320. RadarPulseTime[b_i].f1.data[u0] + TransTime[TransTime.size(0) * b_i];
  321. if (RadarTotal <= 0.0025) {
  322. TOAAcnt++;
  323. TOAA[static_cast<int>(TOAAcnt) - 1] = RadarTotal;
  324. }
  325. }
  326. }
  327. if (1 > static_cast<int>(TOAAcnt)) {
  328. i = 0;
  329. } else {
  330. i = static_cast<int>(TOAAcnt);
  331. }
  332. TOAA.set_size(TOAA.size(0), i);
  333. // 副站
  334. TOAB.set_size(1, n);
  335. for (i = 0; i < n; i++) {
  336. TOAB[i] = 0.0;
  337. }
  338. TOAAcnt = 0U;
  339. for (b_i = 0; b_i < 7; b_i++) {
  340. i = RadarPulseTime[b_i].f1.size[1];
  341. for (u0 = 0; u0 < i; u0++) {
  342. RadarTotal = RadarPulseTime[b_i].f1.data[u0] +
  343. TransTime[TransTime.size(0) * b_i + 1];
  344. if (RadarTotal <= 0.0025) {
  345. TOAAcnt++;
  346. TOAB[static_cast<int>(TOAAcnt) - 1] = RadarTotal;
  347. }
  348. }
  349. }
  350. if (1 > static_cast<int>(TOAAcnt)) {
  351. i = 0;
  352. } else {
  353. i = static_cast<int>(TOAAcnt);
  354. }
  355. TOAB.set_size(TOAB.size(0), i);
  356. // figure
  357. // subplot(1,2,1)
  358. // stem(TOAA,ones(1,TOAAcnt));
  359. // subplot(1,2,2)
  360. // stem(TOAB,ones(TOABcnt,1));
  361. // %% 5. 求时差
  362. coder::internal::sort(TOAA);
  363. coder::internal::sort(TOAB);
  364. TOAAcnt = 0U;
  365. TDOARecordYY.set_size(1, static_cast<int>(static_cast<double>(TOAA.size(1)) *
  366. static_cast<double>(TOAB.size(1))));
  367. n = static_cast<int>(static_cast<double>(TOAA.size(1)) *
  368. static_cast<double>(TOAB.size(1)));
  369. for (i = 0; i < n; i++) {
  370. TDOARecordYY[i] = 0.0;
  371. }
  372. i = TOAA.size(1);
  373. for (b_i = 0; b_i < i; b_i++) {
  374. n = TOAB.size(1);
  375. for (u0 = 0; u0 < n; u0++) {
  376. RadarTotal = TOAA[b_i] - TOAB[u0];
  377. if (std::abs(RadarTotal) <= TDOAWindow) {
  378. TOAAcnt++;
  379. TDOARecordYY[static_cast<int>(TOAAcnt) - 1] = RadarTotal;
  380. }
  381. }
  382. }
  383. if (1 > static_cast<int>(TOAAcnt)) {
  384. i = 0;
  385. } else {
  386. i = static_cast<int>(TOAAcnt);
  387. }
  388. TDOARecordYY.set_size(TDOARecordYY.size(0), i);
  389. // figure
  390. // scatter(TDOARecordXX,TDOARecordYY,'filled');
  391. // hold on
  392. //
  393. // XX = 0:0.1e-6:simTime;
  394. // for i = 1:7
  395. // YY = linspace(TransTime(3,i),TransTime(3,i),length(XX));
  396. // plot(XX,YY);
  397. // hold on
  398. // end
  399. // %% 6. 直方图
  400. // for i = 1:length(TDOARecordYY)
  401. // TDOARecordYY(i) = round(TDOARecordYY(i),8);
  402. // end
  403. // figure
  404. // histogram(TDOARecordYY,25);
  405. coder::histcounts(TDOARecordYY, N_data, N_size, edges_data, edges_size);
  406. // for i = 1:length(N)
  407. // if (N(i) >= 5)
  408. // disp([num2str(edges(i)),'~',num2str(edges(i+1)),':
  409. // ',num2str(N(i))]);
  410. // end
  411. // end
  412. }
  413. //
  414. // File trailer for multifx.cpp
  415. //
  416. // [EOF]
  417. //