fun8_3_ifft.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. //
  2. // File: ifft_8_3.cpp
  3. //
  4. // MATLAB Coder version : 5.2
  5. // C/C++ source code generated on : 10-Mar-2023 15:16:29
  6. //
  7. // Include Files
  8. #include "fun8_3_ifft.h"
  9. #include "fun8_3_FFTImplementationCallback.h"
  10. #include "fun8_3_jamming_H_data.h"
  11. #include "rt_nonfinite.h"
  12. #include "coder_array.h"
  13. #include <cmath>
  14. // Function Definitions
  15. //
  16. // Arguments : const ::coder::array<creal_T, 2U> &x
  17. // ::coder::array<creal_T, 2U> &y
  18. // Return Type : void
  19. //
  20. namespace coder {
  21. void ifft_8_3(const ::coder::array<creal_T, 2U> &x, ::coder::array<creal_T, 2U> &y)
  22. {
  23. array<creal_T, 1U> fv;
  24. array<creal_T, 1U> fy;
  25. array<creal_T, 1U> wwc;
  26. array<creal_T, 1U> yCol;
  27. array<double, 2U> costab;
  28. array<double, 2U> costab1q;
  29. array<double, 2U> sintab;
  30. array<double, 2U> sintabinv;
  31. if (x.size(1) == 0) {
  32. y.set_size(1, 0);
  33. } else {
  34. double twid_re;
  35. int N2blue;
  36. int ihi;
  37. int j;
  38. int k;
  39. int pmax;
  40. int pmin;
  41. int pow2p;
  42. boolean_T useRadix2;
  43. useRadix2 = ((x.size(1) & (x.size(1) - 1)) == 0);
  44. N2blue = 1;
  45. if (useRadix2) {
  46. pmax = x.size(1);
  47. } else {
  48. ihi = (x.size(1) + x.size(1)) - 1;
  49. pmax = 31;
  50. if (ihi <= 1) {
  51. pmax = 0;
  52. } else {
  53. boolean_T exitg1;
  54. pmin = 0;
  55. exitg1 = false;
  56. while ((!exitg1) && (pmax - pmin > 1)) {
  57. k = (pmin + pmax) >> 1;
  58. pow2p = 1 << k;
  59. if (pow2p == ihi) {
  60. pmax = k;
  61. exitg1 = true;
  62. } else if (pow2p > ihi) {
  63. pmax = k;
  64. } else {
  65. pmin = k;
  66. }
  67. }
  68. }
  69. N2blue = 1 << pmax;
  70. pmax = N2blue;
  71. }
  72. twid_re = 6.2831853071795862 / static_cast<double>(pmax);
  73. ihi = pmax / 2 / 2;
  74. costab1q.set_size(1, ihi + 1);
  75. costab1q[0] = 1.0;
  76. pmax = ihi / 2 - 1;
  77. for (k = 0; k <= pmax; k++) {
  78. costab1q[k + 1] = std::cos(twid_re * (static_cast<double>(k) + 1.0));
  79. }
  80. j = pmax + 2;
  81. pmax = ihi - 1;
  82. for (k = j; k <= pmax; k++) {
  83. costab1q[k] = std::sin(twid_re * static_cast<double>(ihi - k));
  84. }
  85. costab1q[ihi] = 0.0;
  86. if (!useRadix2) {
  87. ihi = costab1q.size(1) - 1;
  88. pmax = (costab1q.size(1) - 1) << 1;
  89. costab.set_size(1, pmax + 1);
  90. sintab.set_size(1, pmax + 1);
  91. costab[0] = 1.0;
  92. sintab[0] = 0.0;
  93. sintabinv.set_size(1, pmax + 1);
  94. for (k = 0; k < ihi; k++) {
  95. sintabinv[k + 1] = costab1q[(ihi - k) - 1];
  96. }
  97. j = costab1q.size(1);
  98. for (k = j; k <= pmax; k++) {
  99. sintabinv[k] = costab1q[k - ihi];
  100. }
  101. for (k = 0; k < ihi; k++) {
  102. costab[k + 1] = costab1q[k + 1];
  103. sintab[k + 1] = -costab1q[(ihi - k) - 1];
  104. }
  105. j = costab1q.size(1);
  106. for (k = j; k <= pmax; k++) {
  107. costab[k] = -costab1q[pmax - k];
  108. sintab[k] = -costab1q[k - ihi];
  109. }
  110. } else {
  111. ihi = costab1q.size(1) - 1;
  112. pmax = (costab1q.size(1) - 1) << 1;
  113. costab.set_size(1, pmax + 1);
  114. sintab.set_size(1, pmax + 1);
  115. costab[0] = 1.0;
  116. sintab[0] = 0.0;
  117. for (k = 0; k < ihi; k++) {
  118. costab[k + 1] = costab1q[k + 1];
  119. sintab[k + 1] = costab1q[(ihi - k) - 1];
  120. }
  121. j = costab1q.size(1);
  122. for (k = j; k <= pmax; k++) {
  123. costab[k] = -costab1q[pmax - k];
  124. sintab[k] = costab1q[k - ihi];
  125. }
  126. sintabinv.set_size(1, 0);
  127. }
  128. if (useRadix2) {
  129. pmax = x.size(1);
  130. wwc = x.reshape(pmax);
  131. internal::fft::fun8_3_FFTImplementationCallback::r2br_r2dit_trig_impl(
  132. wwc, x.size(1), costab, sintab, yCol);
  133. if (yCol.size(0) > 1) {
  134. twid_re = 1.0 / static_cast<double>(yCol.size(0));
  135. pmax = yCol.size(0);
  136. for (j = 0; j < pmax; j++) {
  137. yCol[j].re = twid_re * yCol[j].re;
  138. yCol[j].im = twid_re * yCol[j].im;
  139. }
  140. }
  141. } else {
  142. double nt_im;
  143. double nt_re;
  144. double twid_im;
  145. int i;
  146. int ju;
  147. int nRowsD2;
  148. int nfft;
  149. int nt_re_tmp;
  150. nfft = x.size(1);
  151. pmax = (x.size(1) + x.size(1)) - 1;
  152. wwc.set_size(pmax);
  153. pmin = 0;
  154. wwc[x.size(1) - 1].re = 1.0;
  155. wwc[x.size(1) - 1].im = 0.0;
  156. pow2p = x.size(1) << 1;
  157. j = x.size(1);
  158. for (k = 0; k <= j - 2; k++) {
  159. ju = ((k + 1) << 1) - 1;
  160. if (pow2p - pmin <= ju) {
  161. pmin += ju - pow2p;
  162. } else {
  163. pmin += ju;
  164. }
  165. nt_im = 3.1415926535897931 * static_cast<double>(pmin) /
  166. static_cast<double>(nfft);
  167. if (nt_im == 0.0) {
  168. nt_re = 1.0;
  169. nt_im = 0.0;
  170. } else {
  171. nt_re = std::cos(nt_im);
  172. nt_im = std::sin(nt_im);
  173. }
  174. wwc[(x.size(1) - k) - 2].re = nt_re;
  175. wwc[(x.size(1) - k) - 2].im = -nt_im;
  176. }
  177. j = pmax - 1;
  178. for (k = j; k >= nfft; k--) {
  179. wwc[k] = wwc[(pmax - k) - 1];
  180. }
  181. yCol.set_size(x.size(1));
  182. pmax = x.size(1);
  183. for (k = 0; k < pmax; k++) {
  184. nt_re_tmp = (nfft + k) - 1;
  185. nt_re = wwc[nt_re_tmp].re;
  186. nt_im = wwc[nt_re_tmp].im;
  187. yCol[k].re = nt_re * x[k].re + nt_im * x[k].im;
  188. yCol[k].im = nt_re * x[k].im - nt_im * x[k].re;
  189. }
  190. j = x.size(1) + 1;
  191. for (k = j; k <= nfft; k++) {
  192. yCol[k - 1].re = 0.0;
  193. yCol[k - 1].im = 0.0;
  194. }
  195. fy.set_size(N2blue);
  196. if (N2blue > yCol.size(0)) {
  197. fy.set_size(N2blue);
  198. for (j = 0; j < N2blue; j++) {
  199. fy[j].re = 0.0;
  200. fy[j].im = 0.0;
  201. }
  202. }
  203. pmin = yCol.size(0);
  204. if (pmin >= N2blue) {
  205. pmin = N2blue;
  206. }
  207. pow2p = N2blue - 2;
  208. nRowsD2 = N2blue / 2;
  209. k = nRowsD2 / 2;
  210. pmax = 0;
  211. ju = 0;
  212. for (i = 0; i <= pmin - 2; i++) {
  213. fy[pmax] = yCol[i];
  214. ihi = N2blue;
  215. useRadix2 = true;
  216. while (useRadix2) {
  217. ihi >>= 1;
  218. ju ^= ihi;
  219. useRadix2 = ((ju & ihi) == 0);
  220. }
  221. pmax = ju;
  222. }
  223. fy[pmax] = yCol[pmin - 1];
  224. if (N2blue > 1) {
  225. for (i = 0; i <= pow2p; i += 2) {
  226. nt_re = fy[i + 1].re;
  227. nt_im = fy[i + 1].im;
  228. twid_re = fy[i].re;
  229. twid_im = fy[i].im;
  230. fy[i + 1].re = fy[i].re - fy[i + 1].re;
  231. fy[i + 1].im = fy[i].im - fy[i + 1].im;
  232. twid_re += nt_re;
  233. twid_im += nt_im;
  234. fy[i].re = twid_re;
  235. fy[i].im = twid_im;
  236. }
  237. }
  238. pmax = 2;
  239. pmin = 4;
  240. pow2p = ((k - 1) << 2) + 1;
  241. while (k > 0) {
  242. for (i = 0; i < pow2p; i += pmin) {
  243. nt_re_tmp = i + pmax;
  244. nt_re = fy[nt_re_tmp].re;
  245. nt_im = fy[nt_re_tmp].im;
  246. fy[nt_re_tmp].re = fy[i].re - nt_re;
  247. fy[nt_re_tmp].im = fy[i].im - nt_im;
  248. fy[i].re = fy[i].re + nt_re;
  249. fy[i].im = fy[i].im + nt_im;
  250. }
  251. ju = 1;
  252. for (j = k; j < nRowsD2; j += k) {
  253. twid_re = costab[j];
  254. twid_im = sintab[j];
  255. i = ju;
  256. ihi = ju + pow2p;
  257. while (i < ihi) {
  258. nt_re_tmp = i + pmax;
  259. nt_re = twid_re * fy[nt_re_tmp].re - twid_im * fy[nt_re_tmp].im;
  260. nt_im = twid_re * fy[nt_re_tmp].im + twid_im * fy[nt_re_tmp].re;
  261. fy[nt_re_tmp].re = fy[i].re - nt_re;
  262. fy[nt_re_tmp].im = fy[i].im - nt_im;
  263. fy[i].re = fy[i].re + nt_re;
  264. fy[i].im = fy[i].im + nt_im;
  265. i += pmin;
  266. }
  267. ju++;
  268. }
  269. k /= 2;
  270. pmax = pmin;
  271. pmin += pmin;
  272. pow2p -= pmax;
  273. }
  274. internal::fft::fun8_3_FFTImplementationCallback::r2br_r2dit_trig_impl(
  275. wwc, N2blue, costab, sintab, fv);
  276. pmax = fy.size(0);
  277. for (j = 0; j < pmax; j++) {
  278. twid_im = fy[j].re * fv[j].im + fy[j].im * fv[j].re;
  279. fy[j].re = fy[j].re * fv[j].re - fy[j].im * fv[j].im;
  280. fy[j].im = twid_im;
  281. }
  282. internal::fft::fun8_3_FFTImplementationCallback::r2br_r2dit_trig_impl(
  283. fy, N2blue, costab, sintabinv, fv);
  284. if (fv.size(0) > 1) {
  285. twid_re = 1.0 / static_cast<double>(fv.size(0));
  286. pmax = fv.size(0);
  287. for (j = 0; j < pmax; j++) {
  288. fv[j].re = twid_re * fv[j].re;
  289. fv[j].im = twid_re * fv[j].im;
  290. }
  291. }
  292. nt_re = x.size(1);
  293. j = wwc.size(0);
  294. for (k = nfft; k <= j; k++) {
  295. twid_re = wwc[k - 1].re * fv[k - 1].re + wwc[k - 1].im * fv[k - 1].im;
  296. twid_im = wwc[k - 1].re * fv[k - 1].im - wwc[k - 1].im * fv[k - 1].re;
  297. if (twid_im == 0.0) {
  298. pmax = k - nfft;
  299. yCol[pmax].re = twid_re / nt_re;
  300. yCol[pmax].im = 0.0;
  301. } else if (twid_re == 0.0) {
  302. pmax = k - nfft;
  303. yCol[pmax].re = 0.0;
  304. yCol[pmax].im = twid_im / nt_re;
  305. } else {
  306. pmax = k - nfft;
  307. yCol[pmax].re = twid_re / nt_re;
  308. yCol[pmax].im = twid_im / nt_re;
  309. }
  310. }
  311. }
  312. y.set_size(1, x.size(1));
  313. pmax = x.size(1);
  314. for (j = 0; j < pmax; j++) {
  315. y[j] = yCol[j];
  316. }
  317. }
  318. }
  319. } // namespace coder
  320. //
  321. // File trailer for ifft_8_3.cpp
  322. //
  323. // [EOF]
  324. //