123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262 |
- //
- // 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 <cmath>
- // Function Definitions
- //
- // Arguments : const ::coder::array<double, 2U> &x
- // ::coder::array<creal_T, 2U> &y
- // Return Type : void
- //
- namespace coder {
- void fft(const ::coder::array<double, 2U> &x, ::coder::array<creal_T, 2U> &y)
- {
- array<creal_T, 1U> b_fv;
- array<creal_T, 1U> fv;
- array<creal_T, 1U> wwc;
- array<creal_T, 1U> yCol;
- array<double, 2U> costab;
- array<double, 2U> costab1q;
- array<double, 2U> sintab;
- array<double, 2U> sintabinv;
- array<double, 1U> 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<double>(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<double>(k) + 1.0));
- }
- i = nd2 + 2;
- nd2 = nRows - 1;
- for (k = i; k <= nd2; k++) {
- costab1q[k] = std::sin(nt_re * static_cast<double>(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<double>(rt) /
- static_cast<double>(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<double>(rt) /
- static_cast<double>(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<double>(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]
- //
|