// // File: fft.cpp // // MATLAB Coder version : 5.2 // C/C++ source code generated on : 11-Mar-2023 10:38:07 // // Include Files #include "fun1_fft.h" #include "fun1_FFTImplementationCallback.h" #include "rt_nonfinite.h" #include "coder_array.h" #include // Function Definitions // // Arguments : const ::coder::array &x // ::coder::array &y // Return Type : void // namespace coder { void fft(const ::coder::array &x, ::coder::array &y) { array b_fv; array fv; array wwc; array yCol; array costab; array costab1q; array sintab; array sintabinv; array b_x; int N2blue; int nRows; if (x.size(1) == 0) { y.set_size(1, 0); } else { double nt_re; int i; int k; int nd2; boolean_T useRadix2; useRadix2 = ((x.size(1) & (x.size(1) - 1)) == 0); internal::fun1_FFTImplementationCallback::get_algo_sizes(x.size(1), useRadix2, &N2blue, &nRows); nt_re = 6.2831853071795862 / static_cast(nRows); nRows = nRows / 2 / 2; costab1q.set_size(1, nRows + 1); costab1q[0] = 1.0; nd2 = nRows / 2 - 1; for (k = 0; k <= nd2; k++) { costab1q[k + 1] = std::cos(nt_re * (static_cast(k) + 1.0)); } i = nd2 + 2; nd2 = nRows - 1; for (k = i; k <= nd2; k++) { costab1q[k] = std::sin(nt_re * static_cast(nRows - k)); } costab1q[nRows] = 0.0; if (!useRadix2) { nRows = costab1q.size(1) - 1; nd2 = (costab1q.size(1) - 1) << 1; costab.set_size(1, nd2 + 1); sintab.set_size(1, nd2 + 1); costab[0] = 1.0; sintab[0] = 0.0; sintabinv.set_size(1, nd2 + 1); for (k = 0; k < nRows; k++) { sintabinv[k + 1] = costab1q[(nRows - k) - 1]; } i = costab1q.size(1); for (k = i; k <= nd2; k++) { sintabinv[k] = costab1q[k - nRows]; } for (k = 0; k < nRows; k++) { costab[k + 1] = costab1q[k + 1]; sintab[k + 1] = -costab1q[(nRows - k) - 1]; } i = costab1q.size(1); for (k = i; k <= nd2; k++) { costab[k] = -costab1q[nd2 - k]; sintab[k] = -costab1q[k - nRows]; } } else { nRows = costab1q.size(1) - 1; nd2 = (costab1q.size(1) - 1) << 1; costab.set_size(1, nd2 + 1); sintab.set_size(1, nd2 + 1); costab[0] = 1.0; sintab[0] = 0.0; for (k = 0; k < nRows; k++) { costab[k + 1] = costab1q[k + 1]; sintab[k + 1] = -costab1q[(nRows - k) - 1]; } i = costab1q.size(1); for (k = i; k <= nd2; k++) { costab[k] = -costab1q[nd2 - k]; sintab[k] = -costab1q[k - nRows]; } sintabinv.set_size(1, 0); } if (useRadix2) { yCol.set_size(x.size(1)); if (x.size(1) != 1) { nd2 = x.size(1); b_x = x.reshape(nd2); internal::fun1_FFTImplementationCallback::doHalfLengthRadix2( b_x, yCol, x.size(1), costab, sintab); } else { yCol[0].re = x[0]; yCol[0].im = 0.0; } } else { int nfft; nd2 = x.size(1); b_x = x.reshape(nd2); nfft = x.size(1); if ((nfft != 1) && ((nfft & 1) == 0)) { int nInt2; int nInt2m1; int rt; nRows = nfft / 2; nInt2m1 = (nRows + nRows) - 1; wwc.set_size(nInt2m1); rt = 0; wwc[nRows - 1].re = 1.0; wwc[nRows - 1].im = 0.0; nInt2 = nRows << 1; for (k = 0; k <= nRows - 2; k++) { double nt_im; nd2 = ((k + 1) << 1) - 1; if (nInt2 - rt <= nd2) { rt += nd2 - nInt2; } else { rt += nd2; } nt_im = -3.1415926535897931 * static_cast(rt) / static_cast(nRows); if (nt_im == 0.0) { nt_re = 1.0; nt_im = 0.0; } else { nt_re = std::cos(nt_im); nt_im = std::sin(nt_im); } i = (nRows - k) - 2; wwc[i].re = nt_re; wwc[i].im = -nt_im; } i = nInt2m1 - 1; for (k = i; k >= nRows; k--) { wwc[k] = wwc[(nInt2m1 - k) - 1]; } } else { int nInt2; int nInt2m1; int rt; nInt2m1 = (nfft + nfft) - 1; wwc.set_size(nInt2m1); rt = 0; wwc[nfft - 1].re = 1.0; wwc[nfft - 1].im = 0.0; nInt2 = nfft << 1; for (k = 0; k <= nfft - 2; k++) { double nt_im; nd2 = ((k + 1) << 1) - 1; if (nInt2 - rt <= nd2) { rt += nd2 - nInt2; } else { rt += nd2; } nt_im = -3.1415926535897931 * static_cast(rt) / static_cast(nfft); if (nt_im == 0.0) { nt_re = 1.0; nt_im = 0.0; } else { nt_re = std::cos(nt_im); nt_im = std::sin(nt_im); } i = (nfft - k) - 2; wwc[i].re = nt_re; wwc[i].im = -nt_im; } i = nInt2m1 - 1; for (k = i; k >= nfft; k--) { wwc[k] = wwc[(nInt2m1 - k) - 1]; } } yCol.set_size(nfft); if (nfft > b_x.size(0)) { yCol.set_size(nfft); for (i = 0; i < nfft; i++) { yCol[i].re = 0.0; yCol[i].im = 0.0; } } if ((N2blue != 1) && ((nfft & 1) == 0)) { internal::fun1_FFTImplementationCallback::doHalfLengthBluestein( b_x, yCol, b_x.size(0), nfft, N2blue, wwc, costab, sintab, costab, sintabinv); } else { nd2 = b_x.size(0); if (nfft < nd2) { nd2 = nfft; } for (k = 0; k < nd2; k++) { nRows = (nfft + k) - 1; yCol[k].re = wwc[nRows].re * b_x[k]; yCol[k].im = wwc[nRows].im * -b_x[k]; } i = nd2 + 1; for (k = i; k <= nfft; k++) { yCol[k - 1].re = 0.0; yCol[k - 1].im = 0.0; } internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl( yCol, N2blue, costab, sintab, fv); internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl( wwc, N2blue, costab, sintab, b_fv); b_fv.set_size(fv.size(0)); nd2 = fv.size(0); for (i = 0; i < nd2; i++) { nt_re = fv[i].re * b_fv[i].im + fv[i].im * b_fv[i].re; b_fv[i].re = fv[i].re * b_fv[i].re - fv[i].im * b_fv[i].im; b_fv[i].im = nt_re; } internal::fun1_FFTImplementationCallback::r2br_r2dit_trig_impl( b_fv, N2blue, costab, sintabinv, fv); if (fv.size(0) > 1) { nt_re = 1.0 / static_cast(fv.size(0)); nd2 = fv.size(0); for (i = 0; i < nd2; i++) { fv[i].re = nt_re * fv[i].re; fv[i].im = nt_re * fv[i].im; } } i = wwc.size(0); for (k = nfft; k <= i; k++) { nd2 = k - nfft; yCol[nd2].re = wwc[k - 1].re * fv[k - 1].re + wwc[k - 1].im * fv[k - 1].im; yCol[nd2].im = wwc[k - 1].re * fv[k - 1].im - wwc[k - 1].im * fv[k - 1].re; } } } y.set_size(1, x.size(1)); nd2 = x.size(1); for (i = 0; i < nd2; i++) { y[i] = yCol[i]; } } } } // namespace coder // // File trailer for fft.cpp // // [EOF] //