fun8_FFTImplementationCallback.cpp 8.8 KB

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