fun1_false_target_distance.cpp 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. //
  2. // File: false_target_distance.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 11-Mar-2023 10:38:07
  6. //
  7. // Include Files
  8. #include "fun1_false_target_distance.h"
  9. #include "colon.h"
  10. #include "fun1_fft.h"
  11. #include "fun1_fftshift.h"
  12. #include "fun1_ifft.h"
  13. #include "rt_nonfinite.h"
  14. #include "coder_array.h"
  15. #include <cmath>
  16. #include <iostream>
  17. using namespace std;
  18. // Function Declarations
  19. static double rt_hypotd_snf(double u0, double u1);
  20. // Function Definitions
  21. //
  22. // Arguments : double u0
  23. // double u1
  24. // Return Type : double
  25. //
  26. static double rt_hypotd_snf(double u0, double u1)
  27. {
  28. double a;
  29. double y;
  30. a = std::abs(u0);
  31. y = std::abs(u1);
  32. if (a < y) {
  33. a /= y;
  34. y *= std::sqrt(a * a + 1.0);
  35. }
  36. else if (a > y) {
  37. y /= a;
  38. y = a * std::sqrt(y * y + 1.0);
  39. }
  40. else if (!std::isnan(y)) {
  41. y = a * 1.4142135623730951;
  42. }
  43. return y;
  44. }
  45. //
  46. // S_orignal开始
  47. //
  48. // Arguments : double fd
  49. // double N
  50. // double ts
  51. // double Tr
  52. // double t_r
  53. // double tau
  54. // double fo
  55. // double k
  56. // double A
  57. // double dlt_t
  58. // double R
  59. // double fs
  60. // coder::array<double, 2U> &S
  61. // coder::array<double, 2U> &S1
  62. // coder::array<double, 2U> &SS
  63. // coder::array<double, 2U> &S_disturb
  64. // coder::array<double, 2U> &S3
  65. // Return Type : void
  66. //
  67. void false_target_distance(double fd, double N, double ts, double Tr,
  68. double t_r, double tau, double fo, double k,
  69. double A, double dlt_t, double R, double fs,
  70. coder::array<double, 2U> &S,
  71. coder::array<double, 2U> &S1,
  72. coder::array<double, 2U> &SS,
  73. coder::array<double, 2U> &S_disturb,
  74. coder::array<double, 2U> &S3)
  75. {
  76. coder::array<creal_T, 2U> b_x;
  77. coder::array<creal_T, 2U> r;
  78. coder::array<creal_T, 2U> x;
  79. coder::array<double, 2U> rect;
  80. coder::array<double, 2U> t;
  81. coder::array<signed char, 2U> Signal_Radar;
  82. double a_tmp;
  83. double b_a_tmp;
  84. double b_b_tmp;
  85. double b_tmp;
  86. double xtmp;
  87. int ibtile;
  88. int jcol;
  89. int jtilecol;
  90. int ncols;
  91. int ntilecols;
  92. // fd = 200 / 3e2;
  93. // N = 1;
  94. // ts = 1 / 1e7;
  95. // Tr = 5e-4;
  96. // t_r = 2 / 1e4;
  97. // tau = 30e-6;
  98. // fo = 1e6;
  99. // k = 1e12 / 6;
  100. // A = 1;
  101. // dlt_t = 25e-6;
  102. // R = 30e3;
  103. // fs = 1e7;
  104. b_tmp = Tr - ts;
  105. if (std::isnan(ts) || std::isnan(b_tmp)) {
  106. t.set_size(1, 1);
  107. t[0] = rtNaN;
  108. }
  109. else if ((ts == 0.0) || ((0.0 < b_tmp) && (ts < 0.0)) ||
  110. ((b_tmp < 0.0) && (ts > 0.0))) {
  111. t.set_size(1, 0);
  112. }
  113. else if (std::isinf(b_tmp) && (std::isinf(ts) || (0.0 == b_tmp))) {
  114. t.set_size(1, 1);
  115. t[0] = rtNaN;
  116. }
  117. else if (std::isinf(ts)) {
  118. t.set_size(1, 1);
  119. t[0] = 0.0;
  120. }
  121. else if (std::floor(ts) == ts) {
  122. ibtile = static_cast<int>(std::floor(b_tmp / ts));
  123. t.set_size(1, ibtile + 1);
  124. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  125. t[ntilecols] = ts * static_cast<double>(ntilecols);
  126. }
  127. }
  128. else {
  129. coder::eml_float_colon(ts, b_tmp, t);
  130. }
  131. // 以ts为间隔产生Tr/ts个抽样
  132. rect.set_size(1, t.size(1));
  133. ibtile = t.size(1);
  134. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  135. rect[ntilecols] = 0.0;
  136. }
  137. ntilecols = t.size(1);
  138. for (ncols = 0; ncols < ntilecols; ncols++) {
  139. xtmp = t[ncols];
  140. if ((xtmp >= t_r) && (xtmp <= tau + t_r)) {
  141. rect[ncols] = 1.0;
  142. }
  143. }
  144. b_b_tmp = N * Tr - ts;
  145. if (std::isnan(ts) || std::isnan(b_b_tmp)) {
  146. t.set_size(1, 1);
  147. t[0] = rtNaN;
  148. }
  149. else if ((ts == 0.0) || ((0.0 < b_b_tmp) && (ts < 0.0)) ||
  150. ((b_b_tmp < 0.0) && (ts > 0.0))) {
  151. t.set_size(1, 0);
  152. }
  153. else if (std::isinf(b_b_tmp) && (std::isinf(ts) || (0.0 == b_b_tmp))) {
  154. t.set_size(1, 1);
  155. t[0] = rtNaN;
  156. }
  157. else if (std::isinf(ts)) {
  158. t.set_size(1, 1);
  159. t[0] = 0.0;
  160. }
  161. else if (std::floor(ts) == ts) {
  162. ibtile = static_cast<int>(std::floor(b_b_tmp / ts));
  163. t.set_size(1, ibtile + 1);
  164. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  165. t[ntilecols] = ts * static_cast<double>(ntilecols);
  166. }
  167. }
  168. else {
  169. coder::eml_float_colon(ts, b_b_tmp, t);
  170. }
  171. // 以ts为间隔产生N个脉冲信号的抽样间隔
  172. Signal_Radar.set_size(1, rect.size(1) * static_cast<int>(N));
  173. ncols = rect.size(1);
  174. ntilecols = static_cast<int>(N);
  175. for (jtilecol = 0; jtilecol < ntilecols; jtilecol++) {
  176. ibtile = jtilecol * ncols;
  177. for (jcol = 0; jcol < ncols; jcol++) {
  178. Signal_Radar[ibtile + jcol] = static_cast<signed char>(rect[jcol]);
  179. }
  180. }
  181. // 目标回波信号,重复N个脉冲串
  182. a_tmp = 6.2831853071795862 * (fo + fd);
  183. S.set_size(1, t.size(1));
  184. ibtile = t.size(1);
  185. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  186. S[ntilecols] = t[ntilecols] - t_r;
  187. }
  188. b_a_tmp = 3.1415926535897931 * k;
  189. rect.set_size(1, S.size(1));
  190. ncols = S.size(1);
  191. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  192. xtmp = S[ntilecols];
  193. rect[ntilecols] = xtmp * xtmp;
  194. }
  195. S.set_size(1, S.size(1));
  196. ibtile = S.size(1) - 1;
  197. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  198. S[ntilecols] = a_tmp * S[ntilecols] + b_a_tmp * rect[ntilecols];
  199. }
  200. ncols = S.size(1);
  201. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  202. S[ntilecols] = std::cos(S[ntilecols]);
  203. }
  204. S.set_size(1, Signal_Radar.size(1));
  205. ibtile = Signal_Radar.size(1) - 1;
  206. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  207. S[ntilecols] = static_cast<double>(Signal_Radar[ntilecols]) * S[ntilecols];
  208. // printf("S--%f--%d\n", S[ntilecols], ntilecols);
  209. }
  210. SS.set_size(1, S.size(1));
  211. ibtile = S.size(1);
  212. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  213. SS[ntilecols] = S[ntilecols];
  214. }
  215. // S_orignal结束
  216. // S_match(s)开始
  217. if (std::isnan(ts) || std::isnan(b_tmp)) {
  218. t.set_size(t.size(0), 1);
  219. }
  220. else if ((ts == 0.0) || ((0.0 < b_tmp) && (ts < 0.0)) ||
  221. ((b_tmp < 0.0) && (ts > 0.0))) {
  222. t.set_size(t.size(0), 0);
  223. }
  224. else if (std::isinf(b_tmp) && (std::isinf(ts) || (0.0 == b_tmp))) {
  225. t.set_size(t.size(0), 1);
  226. }
  227. else if (std::isinf(ts)) {
  228. t.set_size(t.size(0), 1);
  229. }
  230. else if (std::floor(ts) == ts) {
  231. t.set_size(t.size(0), static_cast<int>(std::floor(b_tmp / ts)) + 1);
  232. }
  233. else {
  234. coder::eml_float_colon(ts, b_tmp, rect);
  235. t.set_size(t.size(0), rect.size(1));
  236. }
  237. // 多少个采样点
  238. if (1 > t.size(1)) {
  239. ibtile = 0;
  240. }
  241. else {
  242. ibtile = t.size(1);
  243. }
  244. S.set_size(S.size(0), ibtile);
  245. // 单脉冲目标回波信号
  246. // 脉冲压缩 :时域翻折取共轭在进行线性卷积
  247. coder::fft(S, x);
  248. rect.set_size(1, ibtile);
  249. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  250. rect[ntilecols] = S[ntilecols];
  251. }
  252. ncols = ibtile >> 1;
  253. for (jtilecol = 0; jtilecol < ncols; jtilecol++) {
  254. ntilecols = (ibtile - jtilecol) - 1;
  255. xtmp = rect[jtilecol];
  256. rect[jtilecol] = rect[ntilecols];
  257. rect[ntilecols] = xtmp;
  258. }
  259. coder::fft(rect, r);
  260. b_x.set_size(1, x.size(1));
  261. ibtile = x.size(1);
  262. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  263. b_x[ntilecols].re =
  264. x[ntilecols].re * r[ntilecols].re - x[ntilecols].im * r[ntilecols].im;
  265. b_x[ntilecols].im =
  266. x[ntilecols].re * r[ntilecols].im + x[ntilecols].im * r[ntilecols].re;
  267. }
  268. coder::ifft_1(b_x, x);
  269. coder::fftshift(x);
  270. ncols = x.size(1);
  271. S1.set_size(1, x.size(1));
  272. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  273. S1[ntilecols] = rt_hypotd_snf(x[ntilecols].re, x[ntilecols].im);
  274. // printf("S1--%f--%d\n", S1[ntilecols], ntilecols);
  275. }
  276. // S_match(s)结束
  277. // 干扰信号1开始
  278. SS.set_size(1, SS.size(1));
  279. ibtile = SS.size(1) - 1;
  280. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  281. SS[ntilecols] = A * SS[ntilecols];
  282. // printf("SS--%f--%d\n", SS[ntilecols], ntilecols);
  283. }
  284. // 干扰信号1结束
  285. // 干扰信号2开始
  286. if (std::isnan(ts) || std::isnan(b_tmp)) {
  287. t.set_size(1, 1);
  288. t[0] = rtNaN;
  289. }
  290. else if ((ts == 0.0) || ((0.0 < b_tmp) && (ts < 0.0)) ||
  291. ((b_tmp < 0.0) && (ts > 0.0))) {
  292. t.set_size(1, 0);
  293. }
  294. else if (std::isinf(b_tmp) && (std::isinf(ts) || (0.0 == b_tmp))) {
  295. t.set_size(1, 1);
  296. t[0] = rtNaN;
  297. }
  298. else if (std::isinf(ts)) {
  299. t.set_size(1, 1);
  300. t[0] = 0.0;
  301. }
  302. else if (std::floor(ts) == ts) {
  303. ibtile = static_cast<int>(std::floor(b_tmp / ts));
  304. t.set_size(1, ibtile + 1);
  305. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  306. t[ntilecols] = ts * static_cast<double>(ntilecols);
  307. }
  308. }
  309. else {
  310. coder::eml_float_colon(ts, b_tmp, t);
  311. }
  312. // 以ts为间隔产生Tr/ts个抽样
  313. rect.set_size(1, t.size(1));
  314. ibtile = t.size(1);
  315. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  316. rect[ntilecols] = 0.0;
  317. }
  318. ntilecols = t.size(1);
  319. for (ncols = 0; ncols < ntilecols; ncols++) {
  320. xtmp = t[ncols];
  321. if ((xtmp >= t_r + dlt_t) && (xtmp <= (tau + t_r) + dlt_t)) {
  322. rect[ncols] = 1.0;
  323. }
  324. }
  325. if (std::isnan(ts) || std::isnan(b_b_tmp)) {
  326. t.set_size(1, 1);
  327. t[0] = rtNaN;
  328. }
  329. else if ((ts == 0.0) || ((0.0 < b_b_tmp) && (ts < 0.0)) ||
  330. ((b_b_tmp < 0.0) && (ts > 0.0))) {
  331. t.set_size(1, 0);
  332. }
  333. else if (std::isinf(b_b_tmp) && (std::isinf(ts) || (0.0 == b_b_tmp))) {
  334. t.set_size(1, 1);
  335. t[0] = rtNaN;
  336. }
  337. else if (std::isinf(ts)) {
  338. t.set_size(1, 1);
  339. t[0] = 0.0;
  340. }
  341. else if (std::floor(ts) == ts) {
  342. ibtile = static_cast<int>(std::floor(b_b_tmp / ts));
  343. t.set_size(1, ibtile + 1);
  344. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  345. t[ntilecols] = ts * static_cast<double>(ntilecols);
  346. }
  347. }
  348. else {
  349. coder::eml_float_colon(ts, b_b_tmp, t);
  350. }
  351. // 以ts为间隔产生N个脉冲信号的抽样间隔
  352. Signal_Radar.set_size(1, rect.size(1) * static_cast<int>(N));
  353. ncols = rect.size(1);
  354. ntilecols = static_cast<int>(N);
  355. for (jtilecol = 0; jtilecol < ntilecols; jtilecol++) {
  356. ibtile = jtilecol * ncols;
  357. for (jcol = 0; jcol < ncols; jcol++) {
  358. Signal_Radar[ibtile + jcol] = static_cast<signed char>(rect[jcol]);
  359. }
  360. }
  361. // 目标回波信号,重复N个脉冲串
  362. S_disturb.set_size(1, t.size(1));
  363. ibtile = t.size(1);
  364. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  365. S_disturb[ntilecols] = (t[ntilecols] - t_r) - dlt_t;
  366. }
  367. rect.set_size(1, S_disturb.size(1));
  368. ncols = S_disturb.size(1);
  369. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  370. xtmp = S_disturb[ntilecols];
  371. rect[ntilecols] = xtmp * xtmp;
  372. }
  373. S_disturb.set_size(1, S_disturb.size(1));
  374. ibtile = S_disturb.size(1) - 1;
  375. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  376. S_disturb[ntilecols] =
  377. a_tmp * S_disturb[ntilecols] + b_a_tmp * rect[ntilecols];
  378. }
  379. ncols = S_disturb.size(1);
  380. for (ntilecols = 0; ntilecols < ncols; ntilecols++) {
  381. S_disturb[ntilecols] = std::cos(S_disturb[ntilecols]);
  382. }
  383. S_disturb.set_size(1, Signal_Radar.size(1));
  384. ibtile = Signal_Radar.size(1) - 1;
  385. for (ntilecols = 0; ntilecols <= ibtile; ntilecols++) {
  386. S_disturb[ntilecols] =
  387. A * static_cast<double>(Signal_Radar[ntilecols]) * S_disturb[ntilecols];
  388. // printf("S_disturb--%f--%d\n", S_disturb[ntilecols], ntilecols);
  389. }
  390. // 干扰信号2结束
  391. // 假距离
  392. if (std::isnan(ts) || std::isnan(b_tmp)) {
  393. t.set_size(t.size(0), 1);
  394. }
  395. else if ((ts == 0.0) || ((0.0 < b_tmp) && (ts < 0.0)) ||
  396. ((b_tmp < 0.0) && (ts > 0.0))) {
  397. t.set_size(t.size(0), 0);
  398. }
  399. else if (std::isinf(b_tmp) && (std::isinf(ts) || (0.0 == b_tmp))) {
  400. t.set_size(t.size(0), 1);
  401. }
  402. else if (std::isinf(ts)) {
  403. t.set_size(t.size(0), 1);
  404. }
  405. else if (std::floor(ts) == ts) {
  406. t.set_size(t.size(0), static_cast<int>(std::floor(b_tmp / ts)) + 1);
  407. }
  408. else {
  409. coder::eml_float_colon(ts, b_tmp, rect);
  410. t.set_size(t.size(0), rect.size(1));
  411. }
  412. xtmp = std::trunc(2.0 * R / 3.0E+8 * fs);
  413. S3.set_size(1, static_cast<int>(static_cast<double>(t.size(1)) + xtmp));
  414. ibtile = static_cast<int>(static_cast<double>(t.size(1)) + xtmp);
  415. for (ntilecols = 0; ntilecols < ibtile; ntilecols++) {
  416. S3[ntilecols] = 0.0;
  417. }
  418. if (xtmp + 1.0 > static_cast<double>(t.size(1)) + xtmp) {
  419. ntilecols = 1;
  420. }
  421. else {
  422. ntilecols = static_cast<int>(xtmp + 1.0);
  423. }
  424. ibtile = S1.size(1);
  425. for (ncols = 0; ncols < ibtile; ncols++) {
  426. S3[(ntilecols + ncols) - 1] = S1[ncols] * 1.5;
  427. // printf("S3--%f--%d\n", S3[ncols], ncols);
  428. }
  429. }
  430. //int main()
  431. //{
  432. // coder::array<double, 2U> S;
  433. // coder::array<double, 2U> S1;
  434. // coder::array<double, 2U> S3;
  435. // coder::array<double, 2U> SS;
  436. // coder::array<double, 2U> S_disturb;
  437. // double fd = 200 / 3e2;
  438. // double N = 1;
  439. // double ts = 1 / 1e7;
  440. // double Tr = 5e-4;
  441. // double t_r = 2 / 1e4;
  442. // double tau = 30e-6;
  443. // double fo = 1e6;
  444. // double k = 1e12 / 6;
  445. // double A = 1;
  446. // double dlt_t = 25e-6;
  447. // double R = 30e3;
  448. // double fs = 1e7;
  449. //
  450. // false_target_distance(fd, N, ts, Tr, t_r, tau, fo, k, A, dlt_t, R, fs, S, S1, SS,S_disturb, S3);
  451. // //输出S
  452. // cout << "S=" <<endl;
  453. // for (int i = 0; i < S.size(1); i++) {
  454. // std::cout << S[i] << " ";
  455. // }
  456. // cout << endl;
  457. // //输出S1
  458. // cout << "S1=" <<endl;
  459. // for (int i = 0; i < S1.size(1); i++) {
  460. // std::cout << S1[i] << " ";
  461. // }
  462. // cout << endl;
  463. // //输出SS
  464. // cout << "SS=" <<endl;
  465. // cout << SS.size(1)<<endl;
  466. // for (int i = 0; i < SS.size(1); i++) {
  467. // std::cout << SS[i] << " ";
  468. // }
  469. // cout << endl;
  470. // //输出S_disturb
  471. // cout << "S_disturb=" <<endl;
  472. // for (int i = 0; i < S_disturb.size(1); i++) {
  473. // std::cout << S_disturb[i] << " ";
  474. // }
  475. // cout << endl;
  476. // //输出S3
  477. // cout << "S3=" <<endl;
  478. // for (int i = 0; i < S3.size(1); i++) {
  479. // std::cout << S3[i] << " ";
  480. // }
  481. //}