fun7_ifft.cpp 8.1 KB

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