fun1_FFTImplementationCallback.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710
  1. //
  2. // File: fun1_FFTImplementationCallback.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_FFTImplementationCallback.h"
  9. #include "rt_nonfinite.h"
  10. #include "coder_array.h"
  11. #include <cmath>
  12. // Function Definitions
  13. //
  14. // Arguments : const ::coder::array<double, 1U> &x
  15. // ::coder::array<creal_T, 1U> &y
  16. // int nrowsx
  17. // int nRows
  18. // int nfft
  19. // const ::coder::array<creal_T, 1U> &wwc
  20. // const ::coder::array<double, 2U> &costab
  21. // const ::coder::array<double, 2U> &sintab
  22. // const ::coder::array<double, 2U> &costabinv
  23. // const ::coder::array<double, 2U> &sintabinv
  24. // Return Type : void
  25. //
  26. namespace coder {
  27. namespace internal {
  28. void fun1_FFTImplementationCallback::doHalfLengthBluestein(
  29. const ::coder::array<double, 1U> &x, ::coder::array<creal_T, 1U> &y,
  30. int nrowsx, int nRows, int nfft, const ::coder::array<creal_T, 1U> &wwc,
  31. const ::coder::array<double, 2U> &costab,
  32. const ::coder::array<double, 2U> &sintab,
  33. const ::coder::array<double, 2U> &costabinv,
  34. const ::coder::array<double, 2U> &sintabinv)
  35. {
  36. array<creal_T, 1U> fv;
  37. array<creal_T, 1U> fy;
  38. array<creal_T, 1U> reconVar1;
  39. array<creal_T, 1U> reconVar2;
  40. array<creal_T, 1U> ytmp;
  41. array<double, 2U> b_costab;
  42. array<double, 2U> b_sintab;
  43. array<double, 2U> costab1q;
  44. array<double, 2U> hcostabinv;
  45. array<double, 2U> hsintab;
  46. array<double, 2U> hsintabinv;
  47. array<int, 2U> wrapIndex;
  48. double temp_im;
  49. double temp_re;
  50. double twid_im;
  51. double twid_re;
  52. double z_tmp;
  53. int hnRows;
  54. int i;
  55. int iDelta2;
  56. int ihi;
  57. int istart;
  58. int j;
  59. int ju;
  60. int k;
  61. int nRowsD2;
  62. int nd2;
  63. int temp_re_tmp;
  64. boolean_T tst;
  65. hnRows = nRows / 2;
  66. ytmp.set_size(hnRows);
  67. if (hnRows > nrowsx) {
  68. ytmp.set_size(hnRows);
  69. for (iDelta2 = 0; iDelta2 < hnRows; iDelta2++) {
  70. ytmp[iDelta2].re = 0.0;
  71. ytmp[iDelta2].im = 0.0;
  72. }
  73. }
  74. if ((x.size(0) & 1) == 0) {
  75. tst = true;
  76. ihi = x.size(0);
  77. } else if (x.size(0) >= nRows) {
  78. tst = true;
  79. ihi = nRows;
  80. } else {
  81. tst = false;
  82. ihi = x.size(0) - 1;
  83. }
  84. if (ihi >= nRows) {
  85. ihi = nRows;
  86. }
  87. nd2 = nRows << 1;
  88. twid_re = 6.2831853071795862 / static_cast<double>(nd2);
  89. j = nd2 / 2 / 2;
  90. costab1q.set_size(1, j + 1);
  91. costab1q[0] = 1.0;
  92. nd2 = j / 2 - 1;
  93. for (k = 0; k <= nd2; k++) {
  94. costab1q[k + 1] = std::cos(twid_re * (static_cast<double>(k) + 1.0));
  95. }
  96. iDelta2 = nd2 + 2;
  97. nd2 = j - 1;
  98. for (k = iDelta2; k <= nd2; k++) {
  99. costab1q[k] = std::sin(twid_re * static_cast<double>(j - k));
  100. }
  101. costab1q[j] = 0.0;
  102. j = costab1q.size(1) - 1;
  103. nd2 = (costab1q.size(1) - 1) << 1;
  104. b_costab.set_size(1, nd2 + 1);
  105. b_sintab.set_size(1, nd2 + 1);
  106. b_costab[0] = 1.0;
  107. b_sintab[0] = 0.0;
  108. for (k = 0; k < j; k++) {
  109. b_costab[k + 1] = costab1q[k + 1];
  110. b_sintab[k + 1] = -costab1q[(j - k) - 1];
  111. }
  112. iDelta2 = costab1q.size(1);
  113. for (k = iDelta2; k <= nd2; k++) {
  114. b_costab[k] = -costab1q[nd2 - k];
  115. b_sintab[k] = -costab1q[k - j];
  116. }
  117. nd2 = costab.size(1) / 2;
  118. costab1q.set_size(1, nd2);
  119. hsintab.set_size(1, nd2);
  120. hcostabinv.set_size(1, nd2);
  121. hsintabinv.set_size(1, nd2);
  122. for (i = 0; i < nd2; i++) {
  123. iDelta2 = ((i + 1) << 1) - 2;
  124. costab1q[i] = costab[iDelta2];
  125. hsintab[i] = sintab[iDelta2];
  126. hcostabinv[i] = costabinv[iDelta2];
  127. hsintabinv[i] = sintabinv[iDelta2];
  128. }
  129. reconVar1.set_size(hnRows);
  130. reconVar2.set_size(hnRows);
  131. wrapIndex.set_size(1, hnRows);
  132. for (i = 0; i < hnRows; i++) {
  133. iDelta2 = i << 1;
  134. twid_re = b_sintab[iDelta2];
  135. twid_im = b_costab[iDelta2];
  136. reconVar1[i].re = twid_re + 1.0;
  137. reconVar1[i].im = -twid_im;
  138. reconVar2[i].re = 1.0 - twid_re;
  139. reconVar2[i].im = twid_im;
  140. if (i + 1 != 1) {
  141. wrapIndex[i] = (hnRows - i) + 1;
  142. } else {
  143. wrapIndex[0] = 1;
  144. }
  145. }
  146. z_tmp = static_cast<double>(ihi) / 2.0;
  147. iDelta2 = static_cast<int>(z_tmp);
  148. for (ju = 0; ju < iDelta2; ju++) {
  149. temp_re_tmp = (hnRows + ju) - 1;
  150. temp_re = wwc[temp_re_tmp].re;
  151. temp_im = wwc[temp_re_tmp].im;
  152. nd2 = ju << 1;
  153. twid_re = x[nd2];
  154. twid_im = x[nd2 + 1];
  155. ytmp[ju].re = temp_re * twid_re + temp_im * twid_im;
  156. ytmp[ju].im = temp_re * twid_im - temp_im * twid_re;
  157. }
  158. if (!tst) {
  159. temp_re_tmp = (hnRows + static_cast<int>(z_tmp)) - 1;
  160. temp_re = wwc[temp_re_tmp].re;
  161. temp_im = wwc[temp_re_tmp].im;
  162. twid_re = x[static_cast<int>(z_tmp) << 1];
  163. ytmp[static_cast<int>(z_tmp)].re = temp_re * twid_re + temp_im * 0.0;
  164. ytmp[static_cast<int>(z_tmp)].im = temp_re * 0.0 - temp_im * twid_re;
  165. if (static_cast<int>(z_tmp) + 2 <= hnRows) {
  166. iDelta2 = static_cast<int>(static_cast<double>(ihi) / 2.0) + 2;
  167. for (i = iDelta2; i <= hnRows; i++) {
  168. ytmp[i - 1].re = 0.0;
  169. ytmp[i - 1].im = 0.0;
  170. }
  171. }
  172. } else if (static_cast<int>(z_tmp) + 1 <= hnRows) {
  173. iDelta2 = static_cast<int>(static_cast<double>(ihi) / 2.0) + 1;
  174. for (i = iDelta2; i <= hnRows; i++) {
  175. ytmp[i - 1].re = 0.0;
  176. ytmp[i - 1].im = 0.0;
  177. }
  178. }
  179. z_tmp = static_cast<double>(nfft) / 2.0;
  180. nd2 = static_cast<int>(z_tmp);
  181. fy.set_size(nd2);
  182. if (static_cast<int>(z_tmp) > ytmp.size(0)) {
  183. fy.set_size(nd2);
  184. for (iDelta2 = 0; iDelta2 < nd2; iDelta2++) {
  185. fy[iDelta2].re = 0.0;
  186. fy[iDelta2].im = 0.0;
  187. }
  188. }
  189. ihi = ytmp.size(0);
  190. istart = static_cast<int>(z_tmp);
  191. if (ihi < istart) {
  192. istart = ihi;
  193. }
  194. iDelta2 = static_cast<int>(z_tmp) - 2;
  195. nRowsD2 = static_cast<int>(z_tmp) / 2;
  196. k = nRowsD2 / 2;
  197. nd2 = 0;
  198. ju = 0;
  199. for (i = 0; i <= istart - 2; i++) {
  200. fy[nd2] = ytmp[i];
  201. j = static_cast<int>(z_tmp);
  202. tst = true;
  203. while (tst) {
  204. j >>= 1;
  205. ju ^= j;
  206. tst = ((ju & j) == 0);
  207. }
  208. nd2 = ju;
  209. }
  210. fy[nd2] = ytmp[istart - 1];
  211. if (static_cast<int>(z_tmp) > 1) {
  212. for (i = 0; i <= iDelta2; i += 2) {
  213. temp_re = fy[i + 1].re;
  214. temp_im = fy[i + 1].im;
  215. twid_re = fy[i].re;
  216. twid_im = fy[i].im;
  217. fy[i + 1].re = fy[i].re - fy[i + 1].re;
  218. fy[i + 1].im = fy[i].im - fy[i + 1].im;
  219. twid_re += temp_re;
  220. twid_im += temp_im;
  221. fy[i].re = twid_re;
  222. fy[i].im = twid_im;
  223. }
  224. }
  225. nd2 = 2;
  226. iDelta2 = 4;
  227. ju = ((k - 1) << 2) + 1;
  228. while (k > 0) {
  229. for (i = 0; i < ju; i += iDelta2) {
  230. temp_re_tmp = i + nd2;
  231. temp_re = fy[temp_re_tmp].re;
  232. temp_im = fy[temp_re_tmp].im;
  233. fy[temp_re_tmp].re = fy[i].re - temp_re;
  234. fy[temp_re_tmp].im = fy[i].im - temp_im;
  235. fy[i].re = fy[i].re + temp_re;
  236. fy[i].im = fy[i].im + temp_im;
  237. }
  238. istart = 1;
  239. for (j = k; j < nRowsD2; j += k) {
  240. twid_re = costab1q[j];
  241. twid_im = hsintab[j];
  242. i = istart;
  243. ihi = istart + ju;
  244. while (i < ihi) {
  245. temp_re_tmp = i + nd2;
  246. temp_re = twid_re * fy[temp_re_tmp].re - twid_im * fy[temp_re_tmp].im;
  247. temp_im = twid_re * fy[temp_re_tmp].im + twid_im * fy[temp_re_tmp].re;
  248. fy[temp_re_tmp].re = fy[i].re - temp_re;
  249. fy[temp_re_tmp].im = fy[i].im - temp_im;
  250. fy[i].re = fy[i].re + temp_re;
  251. fy[i].im = fy[i].im + temp_im;
  252. i += iDelta2;
  253. }
  254. istart++;
  255. }
  256. k /= 2;
  257. nd2 = iDelta2;
  258. iDelta2 += iDelta2;
  259. ju -= nd2;
  260. }
  261. fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(wwc, static_cast<int>(z_tmp),
  262. costab1q, hsintab, fv);
  263. nd2 = fy.size(0);
  264. for (iDelta2 = 0; iDelta2 < nd2; iDelta2++) {
  265. twid_im = fy[iDelta2].re * fv[iDelta2].im + fy[iDelta2].im * fv[iDelta2].re;
  266. fy[iDelta2].re =
  267. fy[iDelta2].re * fv[iDelta2].re - fy[iDelta2].im * fv[iDelta2].im;
  268. fy[iDelta2].im = twid_im;
  269. }
  270. fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(fy, static_cast<int>(z_tmp),
  271. hcostabinv, hsintabinv, fv);
  272. if (fv.size(0) > 1) {
  273. twid_re = 1.0 / static_cast<double>(fv.size(0));
  274. nd2 = fv.size(0);
  275. for (iDelta2 = 0; iDelta2 < nd2; iDelta2++) {
  276. fv[iDelta2].re = twid_re * fv[iDelta2].re;
  277. fv[iDelta2].im = twid_re * fv[iDelta2].im;
  278. }
  279. }
  280. iDelta2 = wwc.size(0);
  281. for (k = hnRows; k <= iDelta2; k++) {
  282. nd2 = k - hnRows;
  283. ytmp[nd2].re = wwc[k - 1].re * fv[k - 1].re + wwc[k - 1].im * fv[k - 1].im;
  284. ytmp[nd2].im = wwc[k - 1].re * fv[k - 1].im - wwc[k - 1].im * fv[k - 1].re;
  285. }
  286. for (i = 0; i < hnRows; i++) {
  287. iDelta2 = wrapIndex[i];
  288. twid_re = ytmp[iDelta2 - 1].re;
  289. twid_im = -ytmp[iDelta2 - 1].im;
  290. y[i].re =
  291. 0.5 * ((ytmp[i].re * reconVar1[i].re - ytmp[i].im * reconVar1[i].im) +
  292. (twid_re * reconVar2[i].re - twid_im * reconVar2[i].im));
  293. y[i].im =
  294. 0.5 * ((ytmp[i].re * reconVar1[i].im + ytmp[i].im * reconVar1[i].re) +
  295. (twid_re * reconVar2[i].im + twid_im * reconVar2[i].re));
  296. iDelta2 = hnRows + i;
  297. y[iDelta2].re =
  298. 0.5 * ((ytmp[i].re * reconVar2[i].re - ytmp[i].im * reconVar2[i].im) +
  299. (twid_re * reconVar1[i].re - twid_im * reconVar1[i].im));
  300. y[iDelta2].im =
  301. 0.5 * ((ytmp[i].re * reconVar2[i].im + ytmp[i].im * reconVar2[i].re) +
  302. (twid_re * reconVar1[i].im + twid_im * reconVar1[i].re));
  303. }
  304. }
  305. //
  306. // Arguments : const ::coder::array<double, 1U> &x
  307. // ::coder::array<creal_T, 1U> &y
  308. // int unsigned_nRows
  309. // const ::coder::array<double, 2U> &costab
  310. // const ::coder::array<double, 2U> &sintab
  311. // Return Type : void
  312. //
  313. void fun1_FFTImplementationCallback::doHalfLengthRadix2(
  314. const ::coder::array<double, 1U> &x, ::coder::array<creal_T, 1U> &y,
  315. int unsigned_nRows, const ::coder::array<double, 2U> &costab,
  316. const ::coder::array<double, 2U> &sintab)
  317. {
  318. array<creal_T, 1U> reconVar1;
  319. array<creal_T, 1U> reconVar2;
  320. array<double, 2U> hcostab;
  321. array<double, 2U> hsintab;
  322. array<int, 2U> wrapIndex;
  323. array<int, 1U> bitrevIndex;
  324. double b_y_im;
  325. double temp2_im;
  326. double temp2_re;
  327. double temp_im;
  328. double temp_re;
  329. double y_im;
  330. double y_im_tmp;
  331. double z_tmp;
  332. int hszCostab;
  333. int i;
  334. int istart;
  335. int iy;
  336. int j;
  337. int ju;
  338. int k;
  339. int nRows;
  340. int nRowsD2;
  341. int nRowsM2;
  342. boolean_T tst;
  343. nRows = unsigned_nRows / 2;
  344. j = y.size(0);
  345. if (j >= nRows) {
  346. j = nRows;
  347. }
  348. nRowsM2 = nRows - 2;
  349. nRowsD2 = nRows / 2;
  350. k = nRowsD2 / 2;
  351. hszCostab = costab.size(1) / 2;
  352. hcostab.set_size(1, hszCostab);
  353. hsintab.set_size(1, hszCostab);
  354. for (i = 0; i < hszCostab; i++) {
  355. iy = ((i + 1) << 1) - 2;
  356. hcostab[i] = costab[iy];
  357. hsintab[i] = sintab[iy];
  358. }
  359. reconVar1.set_size(nRows);
  360. reconVar2.set_size(nRows);
  361. wrapIndex.set_size(1, nRows);
  362. for (i = 0; i < nRows; i++) {
  363. temp2_re = sintab[i];
  364. y_im = costab[i];
  365. reconVar1[i].re = temp2_re + 1.0;
  366. reconVar1[i].im = -y_im;
  367. reconVar2[i].re = 1.0 - temp2_re;
  368. reconVar2[i].im = y_im;
  369. if (i + 1 != 1) {
  370. wrapIndex[i] = (nRows - i) + 1;
  371. } else {
  372. wrapIndex[0] = 1;
  373. }
  374. }
  375. z_tmp = static_cast<double>(unsigned_nRows) / 2.0;
  376. ju = 0;
  377. iy = 1;
  378. hszCostab = static_cast<int>(z_tmp);
  379. bitrevIndex.set_size(hszCostab);
  380. for (istart = 0; istart < hszCostab; istart++) {
  381. bitrevIndex[istart] = 0;
  382. }
  383. for (istart = 0; istart <= j - 2; istart++) {
  384. bitrevIndex[istart] = iy;
  385. hszCostab = static_cast<int>(z_tmp);
  386. tst = true;
  387. while (tst) {
  388. hszCostab >>= 1;
  389. ju ^= hszCostab;
  390. tst = ((ju & hszCostab) == 0);
  391. }
  392. iy = ju + 1;
  393. }
  394. bitrevIndex[j - 1] = iy;
  395. if ((x.size(0) & 1) == 0) {
  396. tst = true;
  397. j = x.size(0);
  398. } else if (x.size(0) >= unsigned_nRows) {
  399. tst = true;
  400. j = unsigned_nRows;
  401. } else {
  402. tst = false;
  403. j = x.size(0) - 1;
  404. }
  405. if (j >= unsigned_nRows) {
  406. j = unsigned_nRows;
  407. }
  408. temp2_re = static_cast<double>(j) / 2.0;
  409. istart = static_cast<int>(temp2_re);
  410. for (i = 0; i < istart; i++) {
  411. iy = i << 1;
  412. y[bitrevIndex[i] - 1].re = x[iy];
  413. y[bitrevIndex[i] - 1].im = x[iy + 1];
  414. }
  415. if (!tst) {
  416. istart = bitrevIndex[static_cast<int>(temp2_re)] - 1;
  417. y[istart].re = x[static_cast<int>(temp2_re) << 1];
  418. y[istart].im = 0.0;
  419. }
  420. if (nRows > 1) {
  421. for (i = 0; i <= nRowsM2; i += 2) {
  422. temp_re = y[i + 1].re;
  423. temp_im = y[i + 1].im;
  424. y[i + 1].re = y[i].re - y[i + 1].re;
  425. y[i + 1].im = y[i].im - y[i + 1].im;
  426. y[i].re = y[i].re + temp_re;
  427. y[i].im = y[i].im + temp_im;
  428. }
  429. }
  430. hszCostab = 2;
  431. iy = 4;
  432. ju = ((k - 1) << 2) + 1;
  433. while (k > 0) {
  434. for (i = 0; i < ju; i += iy) {
  435. nRowsM2 = i + hszCostab;
  436. temp_re = y[nRowsM2].re;
  437. temp_im = y[nRowsM2].im;
  438. y[nRowsM2].re = y[i].re - temp_re;
  439. y[nRowsM2].im = y[i].im - temp_im;
  440. y[i].re = y[i].re + temp_re;
  441. y[i].im = y[i].im + temp_im;
  442. }
  443. istart = 1;
  444. for (j = k; j < nRowsD2; j += k) {
  445. temp2_re = hcostab[j];
  446. temp2_im = hsintab[j];
  447. i = istart;
  448. nRows = istart + ju;
  449. while (i < nRows) {
  450. nRowsM2 = i + hszCostab;
  451. temp_re = temp2_re * y[nRowsM2].re - temp2_im * y[nRowsM2].im;
  452. temp_im = temp2_re * y[nRowsM2].im + temp2_im * y[nRowsM2].re;
  453. y[nRowsM2].re = y[i].re - temp_re;
  454. y[nRowsM2].im = y[i].im - temp_im;
  455. y[i].re = y[i].re + temp_re;
  456. y[i].im = y[i].im + temp_im;
  457. i += iy;
  458. }
  459. istart++;
  460. }
  461. k /= 2;
  462. hszCostab = iy;
  463. iy += iy;
  464. ju -= hszCostab;
  465. }
  466. hszCostab = static_cast<int>(z_tmp) / 2;
  467. temp2_re = y[0].re;
  468. temp_im = y[0].im;
  469. b_y_im = y[0].re * reconVar1[0].im + y[0].im * reconVar1[0].re;
  470. y_im = -y[0].im;
  471. y[0].re = 0.5 * ((y[0].re * reconVar1[0].re - y[0].im * reconVar1[0].im) +
  472. (temp2_re * reconVar2[0].re - y_im * reconVar2[0].im));
  473. y[0].im =
  474. 0.5 * (b_y_im + (temp2_re * reconVar2[0].im + y_im * reconVar2[0].re));
  475. y[static_cast<int>(z_tmp)].re =
  476. 0.5 * ((temp2_re * reconVar2[0].re - temp_im * reconVar2[0].im) +
  477. (temp2_re * reconVar1[0].re - -temp_im * reconVar1[0].im));
  478. y[static_cast<int>(z_tmp)].im =
  479. 0.5 * ((temp2_re * reconVar2[0].im + temp_im * reconVar2[0].re) +
  480. (temp2_re * reconVar1[0].im + -temp_im * reconVar1[0].re));
  481. for (i = 2; i <= hszCostab; i++) {
  482. temp_re = y[i - 1].re;
  483. temp_im = y[i - 1].im;
  484. istart = wrapIndex[i - 1];
  485. y_im = y[istart - 1].re;
  486. temp2_im = y[istart - 1].im;
  487. b_y_im =
  488. y[i - 1].re * reconVar1[i - 1].im + y[i - 1].im * reconVar1[i - 1].re;
  489. y_im_tmp = -y[istart - 1].im;
  490. y[i - 1].re =
  491. 0.5 * ((y[i - 1].re * reconVar1[i - 1].re -
  492. y[i - 1].im * reconVar1[i - 1].im) +
  493. (y_im * reconVar2[i - 1].re - y_im_tmp * reconVar2[i - 1].im));
  494. y[i - 1].im = 0.5 * (b_y_im + (y_im * reconVar2[i - 1].im +
  495. y_im_tmp * reconVar2[i - 1].re));
  496. iy = (static_cast<int>(z_tmp) + i) - 1;
  497. y[iy].re =
  498. 0.5 * ((temp_re * reconVar2[i - 1].re - temp_im * reconVar2[i - 1].im) +
  499. (y_im * reconVar1[i - 1].re - -temp2_im * reconVar1[i - 1].im));
  500. y[iy].im =
  501. 0.5 * ((temp_re * reconVar2[i - 1].im + temp_im * reconVar2[i - 1].re) +
  502. (y_im * reconVar1[i - 1].im + -temp2_im * reconVar1[i - 1].re));
  503. y[istart - 1].re = 0.5 * ((y_im * reconVar1[istart - 1].re -
  504. temp2_im * reconVar1[istart - 1].im) +
  505. (temp_re * reconVar2[istart - 1].re -
  506. -temp_im * reconVar2[istart - 1].im));
  507. y[istart - 1].im = 0.5 * ((y_im * reconVar1[istart - 1].im +
  508. temp2_im * reconVar1[istart - 1].re) +
  509. (temp_re * reconVar2[istart - 1].im +
  510. -temp_im * reconVar2[istart - 1].re));
  511. iy = (istart + static_cast<int>(z_tmp)) - 1;
  512. y[iy].re = 0.5 * ((y_im * reconVar2[istart - 1].re -
  513. temp2_im * reconVar2[istart - 1].im) +
  514. (temp_re * reconVar1[istart - 1].re -
  515. -temp_im * reconVar1[istart - 1].im));
  516. y[iy].im = 0.5 * ((y_im * reconVar2[istart - 1].im +
  517. temp2_im * reconVar2[istart - 1].re) +
  518. (temp_re * reconVar1[istart - 1].im +
  519. -temp_im * reconVar1[istart - 1].re));
  520. }
  521. if (hszCostab != 0) {
  522. temp2_re = y[hszCostab].re;
  523. temp_im = y[hszCostab].im;
  524. b_y_im = y[hszCostab].re * reconVar1[hszCostab].im +
  525. y[hszCostab].im * reconVar1[hszCostab].re;
  526. y_im_tmp = -y[hszCostab].im;
  527. y[hszCostab].re = 0.5 * ((y[hszCostab].re * reconVar1[hszCostab].re -
  528. y[hszCostab].im * reconVar1[hszCostab].im) +
  529. (temp2_re * reconVar2[hszCostab].re -
  530. y_im_tmp * reconVar2[hszCostab].im));
  531. y[hszCostab].im = 0.5 * (b_y_im + (temp2_re * reconVar2[hszCostab].im +
  532. y_im_tmp * reconVar2[hszCostab].re));
  533. istart = static_cast<int>(z_tmp) + hszCostab;
  534. y[istart].re = 0.5 * ((temp2_re * reconVar2[hszCostab].re -
  535. temp_im * reconVar2[hszCostab].im) +
  536. (temp2_re * reconVar1[hszCostab].re -
  537. -temp_im * reconVar1[hszCostab].im));
  538. y[istart].im = 0.5 * ((temp2_re * reconVar2[hszCostab].im +
  539. temp_im * reconVar2[hszCostab].re) +
  540. (temp2_re * reconVar1[hszCostab].im +
  541. -temp_im * reconVar1[hszCostab].re));
  542. }
  543. }
  544. //
  545. // Arguments : int nfft
  546. // boolean_T useRadix2
  547. // int *n2blue
  548. // int *nRows
  549. // Return Type : void
  550. //
  551. void fun1_FFTImplementationCallback::get_algo_sizes(int nfft, boolean_T useRadix2,
  552. int *n2blue, int *nRows)
  553. {
  554. *n2blue = 1;
  555. if (useRadix2) {
  556. *nRows = nfft;
  557. } else {
  558. if (nfft > 0) {
  559. int n;
  560. int pmax;
  561. n = (nfft + nfft) - 1;
  562. pmax = 31;
  563. if (n <= 1) {
  564. pmax = 0;
  565. } else {
  566. int pmin;
  567. boolean_T exitg1;
  568. pmin = 0;
  569. exitg1 = false;
  570. while ((!exitg1) && (pmax - pmin > 1)) {
  571. int k;
  572. int pow2p;
  573. k = (pmin + pmax) >> 1;
  574. pow2p = 1 << k;
  575. if (pow2p == n) {
  576. pmax = k;
  577. exitg1 = true;
  578. } else if (pow2p > n) {
  579. pmax = k;
  580. } else {
  581. pmin = k;
  582. }
  583. }
  584. }
  585. *n2blue = 1 << pmax;
  586. }
  587. *nRows = *n2blue;
  588. }
  589. }
  590. //
  591. // Arguments : const ::coder::array<creal_T, 1U> &x
  592. // int unsigned_nRows
  593. // const ::coder::array<double, 2U> &costab
  594. // const ::coder::array<double, 2U> &sintab
  595. // ::coder::array<creal_T, 1U> &y
  596. // Return Type : void
  597. //
  598. void fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(
  599. const ::coder::array<creal_T, 1U> &x, int unsigned_nRows,
  600. const ::coder::array<double, 2U> &costab,
  601. const ::coder::array<double, 2U> &sintab, ::coder::array<creal_T, 1U> &y)
  602. {
  603. double temp_im;
  604. double temp_re;
  605. double twid_im;
  606. double twid_re;
  607. int i;
  608. int iDelta2;
  609. int iheight;
  610. int iy;
  611. int ju;
  612. int k;
  613. int nRowsD2;
  614. y.set_size(unsigned_nRows);
  615. if (unsigned_nRows > x.size(0)) {
  616. y.set_size(unsigned_nRows);
  617. for (iy = 0; iy < unsigned_nRows; iy++) {
  618. y[iy].re = 0.0;
  619. y[iy].im = 0.0;
  620. }
  621. }
  622. iDelta2 = x.size(0);
  623. if (iDelta2 >= unsigned_nRows) {
  624. iDelta2 = unsigned_nRows;
  625. }
  626. iheight = unsigned_nRows - 2;
  627. nRowsD2 = unsigned_nRows / 2;
  628. k = nRowsD2 / 2;
  629. iy = 0;
  630. ju = 0;
  631. for (i = 0; i <= iDelta2 - 2; i++) {
  632. boolean_T tst;
  633. y[iy] = x[i];
  634. iy = unsigned_nRows;
  635. tst = true;
  636. while (tst) {
  637. iy >>= 1;
  638. ju ^= iy;
  639. tst = ((ju & iy) == 0);
  640. }
  641. iy = ju;
  642. }
  643. y[iy] = x[iDelta2 - 1];
  644. if (unsigned_nRows > 1) {
  645. for (i = 0; i <= iheight; i += 2) {
  646. temp_re = y[i + 1].re;
  647. temp_im = y[i + 1].im;
  648. twid_re = y[i].re;
  649. twid_im = y[i].im;
  650. y[i + 1].re = y[i].re - y[i + 1].re;
  651. y[i + 1].im = y[i].im - y[i + 1].im;
  652. twid_re += temp_re;
  653. twid_im += temp_im;
  654. y[i].re = twid_re;
  655. y[i].im = twid_im;
  656. }
  657. }
  658. iy = 2;
  659. iDelta2 = 4;
  660. iheight = ((k - 1) << 2) + 1;
  661. while (k > 0) {
  662. int temp_re_tmp;
  663. for (i = 0; i < iheight; i += iDelta2) {
  664. temp_re_tmp = i + iy;
  665. temp_re = y[temp_re_tmp].re;
  666. temp_im = y[temp_re_tmp].im;
  667. y[temp_re_tmp].re = y[i].re - temp_re;
  668. y[temp_re_tmp].im = y[i].im - temp_im;
  669. y[i].re = y[i].re + temp_re;
  670. y[i].im = y[i].im + temp_im;
  671. }
  672. ju = 1;
  673. for (int j{k}; j < nRowsD2; j += k) {
  674. int ihi;
  675. twid_re = costab[j];
  676. twid_im = sintab[j];
  677. i = ju;
  678. ihi = ju + iheight;
  679. while (i < ihi) {
  680. temp_re_tmp = i + iy;
  681. temp_re = twid_re * y[temp_re_tmp].re - twid_im * y[temp_re_tmp].im;
  682. temp_im = twid_re * y[temp_re_tmp].im + twid_im * y[temp_re_tmp].re;
  683. y[temp_re_tmp].re = y[i].re - temp_re;
  684. y[temp_re_tmp].im = y[i].im - temp_im;
  685. y[i].re = y[i].re + temp_re;
  686. y[i].im = y[i].im + temp_im;
  687. i += iDelta2;
  688. }
  689. ju++;
  690. }
  691. k /= 2;
  692. iy = iDelta2;
  693. iDelta2 += iDelta2;
  694. iheight -= iy;
  695. }
  696. }
  697. } // namespace internal
  698. } // namespace coder
  699. //
  700. // File trailer for fun1_FFTImplementationCallback.cpp
  701. //
  702. // [EOF]
  703. //