fun1_ifft.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. //
  2. // File: ifft_1.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_ifft.h"
  9. #include "fun1_FFTImplementationCallback.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, 2U> &x
  16. // ::coder::array<creal_T, 2U> &y
  17. // Return Type : void
  18. //
  19. namespace coder {
  20. void ifft_1(const ::coder::array<creal_T, 2U> &x, ::coder::array<creal_T, 2U> &y)
  21. {
  22. array<creal_T, 1U> b_fv;
  23. array<creal_T, 1U> fv;
  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. int N2blue;
  31. int nd2;
  32. int nfft;
  33. nfft = x.size(1);
  34. if (x.size(1) == 0) {
  35. y.set_size(1, 0);
  36. } else {
  37. double nt_im;
  38. int i;
  39. int k;
  40. int nInt2;
  41. int rt;
  42. boolean_T useRadix2;
  43. useRadix2 = ((x.size(1) & (x.size(1) - 1)) == 0);
  44. internal::fun1_FFTImplementationCallback::get_algo_sizes(x.size(1), useRadix2,
  45. &N2blue, &nd2);
  46. nt_im = 6.2831853071795862 / static_cast<double>(nd2);
  47. nInt2 = nd2 / 2 / 2;
  48. costab1q.set_size(1, nInt2 + 1);
  49. costab1q[0] = 1.0;
  50. nd2 = nInt2 / 2 - 1;
  51. for (k = 0; k <= nd2; k++) {
  52. costab1q[k + 1] = std::cos(nt_im * (static_cast<double>(k) + 1.0));
  53. }
  54. i = nd2 + 2;
  55. rt = nInt2 - 1;
  56. for (k = i; k <= rt; k++) {
  57. costab1q[k] = std::sin(nt_im * static_cast<double>(nInt2 - k));
  58. }
  59. costab1q[nInt2] = 0.0;
  60. if (!useRadix2) {
  61. nInt2 = costab1q.size(1) - 1;
  62. nd2 = (costab1q.size(1) - 1) << 1;
  63. costab.set_size(1, nd2 + 1);
  64. sintab.set_size(1, nd2 + 1);
  65. costab[0] = 1.0;
  66. sintab[0] = 0.0;
  67. sintabinv.set_size(1, nd2 + 1);
  68. for (k = 0; k < nInt2; k++) {
  69. sintabinv[k + 1] = costab1q[(nInt2 - k) - 1];
  70. }
  71. i = costab1q.size(1);
  72. for (k = i; k <= nd2; k++) {
  73. sintabinv[k] = costab1q[k - nInt2];
  74. }
  75. for (k = 0; k < nInt2; k++) {
  76. costab[k + 1] = costab1q[k + 1];
  77. sintab[k + 1] = -costab1q[(nInt2 - k) - 1];
  78. }
  79. i = costab1q.size(1);
  80. for (k = i; k <= nd2; k++) {
  81. costab[k] = -costab1q[nd2 - k];
  82. sintab[k] = -costab1q[k - nInt2];
  83. }
  84. } else {
  85. nInt2 = costab1q.size(1) - 1;
  86. nd2 = (costab1q.size(1) - 1) << 1;
  87. costab.set_size(1, nd2 + 1);
  88. sintab.set_size(1, nd2 + 1);
  89. costab[0] = 1.0;
  90. sintab[0] = 0.0;
  91. for (k = 0; k < nInt2; k++) {
  92. costab[k + 1] = costab1q[k + 1];
  93. sintab[k + 1] = costab1q[(nInt2 - k) - 1];
  94. }
  95. i = costab1q.size(1);
  96. for (k = i; k <= nd2; k++) {
  97. costab[k] = -costab1q[nd2 - k];
  98. sintab[k] = costab1q[k - nInt2];
  99. }
  100. sintabinv.set_size(1, 0);
  101. }
  102. if (useRadix2) {
  103. nd2 = x.size(1);
  104. wwc = x.reshape(nd2);
  105. internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(
  106. wwc, x.size(1), costab, sintab, yCol);
  107. if (yCol.size(0) > 1) {
  108. nt_im = 1.0 / static_cast<double>(yCol.size(0));
  109. nd2 = yCol.size(0);
  110. for (i = 0; i < nd2; i++) {
  111. yCol[i].re = nt_im * yCol[i].re;
  112. yCol[i].im = nt_im * yCol[i].im;
  113. }
  114. }
  115. } else {
  116. double nt_re;
  117. nd2 = (x.size(1) + x.size(1)) - 1;
  118. wwc.set_size(nd2);
  119. rt = 0;
  120. wwc[x.size(1) - 1].re = 1.0;
  121. wwc[x.size(1) - 1].im = 0.0;
  122. nInt2 = x.size(1) << 1;
  123. i = x.size(1);
  124. for (k = 0; k <= i - 2; k++) {
  125. int b_y;
  126. b_y = ((k + 1) << 1) - 1;
  127. if (nInt2 - rt <= b_y) {
  128. rt += b_y - nInt2;
  129. } else {
  130. rt += b_y;
  131. }
  132. nt_im = 3.1415926535897931 * static_cast<double>(rt) /
  133. static_cast<double>(nfft);
  134. if (nt_im == 0.0) {
  135. nt_re = 1.0;
  136. nt_im = 0.0;
  137. } else {
  138. nt_re = std::cos(nt_im);
  139. nt_im = std::sin(nt_im);
  140. }
  141. wwc[(x.size(1) - k) - 2].re = nt_re;
  142. wwc[(x.size(1) - k) - 2].im = -nt_im;
  143. }
  144. i = nd2 - 1;
  145. for (k = i; k >= nfft; k--) {
  146. wwc[k] = wwc[(nd2 - k) - 1];
  147. }
  148. yCol.set_size(x.size(1));
  149. nd2 = x.size(1);
  150. for (k = 0; k < nd2; k++) {
  151. nt_re = wwc[(nfft + k) - 1].re;
  152. nt_im = wwc[(nfft + k) - 1].im;
  153. yCol[k].re = nt_re * x[k].re + nt_im * x[k].im;
  154. yCol[k].im = nt_re * x[k].im - nt_im * x[k].re;
  155. }
  156. i = x.size(1) + 1;
  157. for (k = i; k <= nfft; k++) {
  158. yCol[k - 1].re = 0.0;
  159. yCol[k - 1].im = 0.0;
  160. }
  161. internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(
  162. yCol, N2blue, costab, sintab, fv);
  163. internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(
  164. wwc, N2blue, costab, sintab, b_fv);
  165. b_fv.set_size(fv.size(0));
  166. nd2 = fv.size(0);
  167. for (i = 0; i < nd2; i++) {
  168. nt_im = fv[i].re * b_fv[i].im + fv[i].im * b_fv[i].re;
  169. b_fv[i].re = fv[i].re * b_fv[i].re - fv[i].im * b_fv[i].im;
  170. b_fv[i].im = nt_im;
  171. }
  172. internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl(
  173. b_fv, N2blue, costab, sintabinv, fv);
  174. if (fv.size(0) > 1) {
  175. nt_im = 1.0 / static_cast<double>(fv.size(0));
  176. nd2 = fv.size(0);
  177. for (i = 0; i < nd2; i++) {
  178. fv[i].re = nt_im * fv[i].re;
  179. fv[i].im = nt_im * fv[i].im;
  180. }
  181. }
  182. nt_re = x.size(1);
  183. i = x.size(1);
  184. rt = wwc.size(0);
  185. for (k = i; k <= rt; k++) {
  186. double ai;
  187. nt_im = wwc[k - 1].re * fv[k - 1].re + wwc[k - 1].im * fv[k - 1].im;
  188. ai = wwc[k - 1].re * fv[k - 1].im - wwc[k - 1].im * fv[k - 1].re;
  189. if (ai == 0.0) {
  190. nd2 = k - i;
  191. yCol[nd2].re = nt_im / nt_re;
  192. yCol[nd2].im = 0.0;
  193. } else if (nt_im == 0.0) {
  194. nd2 = k - i;
  195. yCol[nd2].re = 0.0;
  196. yCol[nd2].im = ai / nt_re;
  197. } else {
  198. nd2 = k - i;
  199. yCol[nd2].re = nt_im / nt_re;
  200. yCol[nd2].im = ai / nt_re;
  201. }
  202. }
  203. }
  204. y.set_size(1, x.size(1));
  205. nd2 = x.size(1);
  206. for (i = 0; i < nd2; i++) {
  207. y[i] = yCol[i];
  208. }
  209. }
  210. }
  211. } // namespace coder
  212. //
  213. // File trailer for ifft_1.cpp
  214. //
  215. // [EOF]
  216. //