Пример #1
0
void d_abs(const creal_T x[106], real_T y[106])
{
  int32_T k;
  for (k = 0; k < 106; k++) {
    y[k] = muDoubleScalarHypot(x[k].re, x[k].im);
  }
}
Пример #2
0
void b_abs(const creal_T x[5120], real_T y[5120])
{
  int32_T k;
  for (k = 0; k < 5120; k++) {
    y[k] = muDoubleScalarHypot(x[k].re, x[k].im);
  }
}
Пример #3
0
real_T d_norm(const emxArray_creal_T *x)
{
    real_T y;
    int32_T j;
    int32_T i;
    boolean_T exitg1;
    real_T s;
    if ((x->size[0] == 1) || (x->size[1] == 1)) {
        y = 0.0;
        j = x->size[0] * x->size[1];
        for (i = 0; i < j; i++) {
            y += muDoubleScalarHypot(x->data[i].re, x->data[i].im);
        }
    } else {
        y = 0.0;
        j = 0;
        exitg1 = FALSE;
        while ((exitg1 == FALSE) && (j <= x->size[1] - 1)) {
            s = 0.0;
            for (i = 0; i < x->size[0]; i++) {
                s += muDoubleScalarHypot(x->data[i + x->size[0] * j].re, x->data[i +
                                         x->size[0] * j].im);
            }

            if (muDoubleScalarIsNaN(s)) {
                y = rtNaN;
                exitg1 = TRUE;
            } else {
                if (s > y) {
                    y = s;
                }

                j++;
            }
        }
    }

    return y;
}
Пример #4
0
/* Function Definitions */
static real_T eml_dlapy2(real_T x1, real_T x2)
{
  return muDoubleScalarHypot(x1, x2);
}
Пример #5
0
/* Function Definitions */
static real_T eml_scalar_abs(const creal_T x)
{
  return muDoubleScalarHypot(x.re, x.im);
}
Пример #6
0
static void c_eml_qrsolve(const emlrtStack *sp, const emxArray_real_T *A,
  emxArray_real_T *B, emxArray_real_T *Y)
{
  emxArray_real_T *b_A;
  emxArray_real_T *work;
  int32_T mn;
  int32_T i51;
  int32_T ix;
  emxArray_real_T *tau;
  emxArray_int32_T *jpvt;
  int32_T m;
  int32_T n;
  int32_T b_mn;
  emxArray_real_T *vn1;
  emxArray_real_T *vn2;
  int32_T k;
  boolean_T overflow;
  boolean_T b12;
  int32_T i;
  int32_T i_i;
  int32_T nmi;
  int32_T mmi;
  int32_T pvt;
  int32_T iy;
  boolean_T b13;
  real_T xnorm;
  int32_T i52;
  real_T atmp;
  real_T d16;
  boolean_T b14;
  boolean_T b_i;
  ptrdiff_t n_t;
  ptrdiff_t incx_t;
  double * xix0_t;
  boolean_T exitg1;
  const mxArray *y;
  static const int32_T iv78[2] = { 1, 8 };

  const mxArray *m14;
  char_T cv76[8];
  static const char_T cv77[8] = { '%', '%', '%', 'd', '.', '%', 'd', 'e' };

  char_T cv78[14];
  uint32_T unnamed_idx_0;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  emlrtStack f_st;
  emlrtStack g_st;
  emlrtStack h_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  e_st.prev = &d_st;
  e_st.tls = d_st.tls;
  f_st.prev = &e_st;
  f_st.tls = e_st.tls;
  g_st.prev = &f_st;
  g_st.tls = f_st.tls;
  h_st.prev = &g_st;
  h_st.tls = g_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &b_A, 2, &m_emlrtRTEI, true);
  b_emxInit_real_T(sp, &work, 1, &rb_emlrtRTEI, true);
  mn = (int32_T)muDoubleScalarMin(A->size[0], A->size[1]);
  st.site = &mc_emlrtRSI;
  b_st.site = &nc_emlrtRSI;
  c_st.site = &oc_emlrtRSI;
  i51 = b_A->size[0] * b_A->size[1];
  b_A->size[0] = A->size[0];
  b_A->size[1] = A->size[1];
  emxEnsureCapacity(&c_st, (emxArray__common *)b_A, i51, (int32_T)sizeof(real_T),
                    &m_emlrtRTEI);
  ix = A->size[0] * A->size[1];
  for (i51 = 0; i51 < ix; i51++) {
    b_A->data[i51] = A->data[i51];
  }

  b_emxInit_real_T(&c_st, &tau, 1, &m_emlrtRTEI, true);
  b_emxInit_int32_T(&c_st, &jpvt, 2, &m_emlrtRTEI, true);
  m = b_A->size[0];
  n = b_A->size[1];
  b_mn = muIntScalarMin_sint32(b_A->size[0], b_A->size[1]);
  i51 = tau->size[0];
  tau->size[0] = b_mn;
  emxEnsureCapacity(&c_st, (emxArray__common *)tau, i51, (int32_T)sizeof(real_T),
                    &n_emlrtRTEI);
  d_st.site = &mf_emlrtRSI;
  e_st.site = &rb_emlrtRSI;
  f_st.site = &sb_emlrtRSI;
  g_st.site = &tb_emlrtRSI;
  eml_signed_integer_colon(&g_st, b_A->size[1], jpvt);
  if ((b_A->size[0] == 0) || (b_A->size[1] == 0)) {
  } else {
    ix = b_A->size[1];
    i51 = work->size[0];
    work->size[0] = ix;
    emxEnsureCapacity(&c_st, (emxArray__common *)work, i51, (int32_T)sizeof
                      (real_T), &m_emlrtRTEI);
    for (i51 = 0; i51 < ix; i51++) {
      work->data[i51] = 0.0;
    }

    b_emxInit_real_T(&c_st, &vn1, 1, &pb_emlrtRTEI, true);
    b_emxInit_real_T(&c_st, &vn2, 1, &qb_emlrtRTEI, true);
    d_st.site = &tc_emlrtRSI;
    ix = b_A->size[1];
    i51 = vn1->size[0];
    vn1->size[0] = ix;
    emxEnsureCapacity(&c_st, (emxArray__common *)vn1, i51, (int32_T)sizeof
                      (real_T), &pb_emlrtRTEI);
    i51 = vn2->size[0];
    vn2->size[0] = ix;
    emxEnsureCapacity(&c_st, (emxArray__common *)vn2, i51, (int32_T)sizeof
                      (real_T), &qb_emlrtRTEI);
    k = 1;
    d_st.site = &nf_emlrtRSI;
    overflow = (b_A->size[1] > 2147483646);
    if (overflow) {
      e_st.site = &db_emlrtRSI;
      check_forloop_overflow_error(&e_st);
    }

    for (ix = 0; ix + 1 <= b_A->size[1]; ix++) {
      d_st.site = &sc_emlrtRSI;
      vn1->data[ix] = b_eml_xnrm2(&d_st, b_A->size[0], b_A, k);
      vn2->data[ix] = vn1->data[ix];
      k += b_A->size[0];
    }

    d_st.site = &rc_emlrtRSI;
    if (1 > b_mn) {
      b12 = false;
    } else {
      b12 = (b_mn > 2147483646);
    }

    if (b12) {
      e_st.site = &db_emlrtRSI;
      check_forloop_overflow_error(&e_st);
    }

    for (i = 1; i <= b_mn; i++) {
      i_i = (i + (i - 1) * m) - 1;
      nmi = n - i;
      mmi = m - i;
      d_st.site = &of_emlrtRSI;
      ix = eml_ixamax(&d_st, 1 + nmi, vn1, i);
      pvt = (i + ix) - 2;
      if (pvt + 1 != i) {
        d_st.site = &pf_emlrtRSI;
        e_st.site = &bc_emlrtRSI;
        f_st.site = &cc_emlrtRSI;
        ix = 1 + m * pvt;
        iy = 1 + m * (i - 1);
        g_st.site = &dc_emlrtRSI;
        if (1 > m) {
          b13 = false;
        } else {
          b13 = (m > 2147483646);
        }

        if (b13) {
          h_st.site = &db_emlrtRSI;
          check_forloop_overflow_error(&h_st);
        }

        for (k = 1; k <= m; k++) {
          i51 = b_A->size[0] * b_A->size[1];
          xnorm = b_A->data[emlrtDynamicBoundsCheckFastR2012b(ix, 1, i51,
            &le_emlrtBCI, &f_st) - 1];
          i51 = b_A->size[0] * b_A->size[1];
          i52 = b_A->size[0] * b_A->size[1];
          b_A->data[emlrtDynamicBoundsCheckFastR2012b(ix, 1, i51, &le_emlrtBCI,
            &f_st) - 1] = b_A->data[emlrtDynamicBoundsCheckFastR2012b(iy, 1, i52,
            &le_emlrtBCI, &f_st) - 1];
          i51 = b_A->size[0] * b_A->size[1];
          b_A->data[emlrtDynamicBoundsCheckFastR2012b(iy, 1, i51, &le_emlrtBCI,
            &f_st) - 1] = xnorm;
          ix++;
          iy++;
        }

        ix = jpvt->data[pvt];
        jpvt->data[pvt] = jpvt->data[i - 1];
        jpvt->data[i - 1] = ix;
        vn1->data[pvt] = vn1->data[i - 1];
        vn2->data[pvt] = vn2->data[i - 1];
      }

      if (i < m) {
        d_st.site = &qc_emlrtRSI;
        atmp = b_A->data[i_i];
        d16 = 0.0;
        if (1 + mmi <= 0) {
        } else {
          e_st.site = &wc_emlrtRSI;
          xnorm = b_eml_xnrm2(&e_st, mmi, b_A, i_i + 2);
          if (xnorm != 0.0) {
            xnorm = muDoubleScalarHypot(b_A->data[i_i], xnorm);
            if (b_A->data[i_i] >= 0.0) {
              xnorm = -xnorm;
            }

            if (muDoubleScalarAbs(xnorm) < 1.0020841800044864E-292) {
              ix = 0;
              do {
                ix++;
                e_st.site = &xc_emlrtRSI;
                b_eml_xscal(&e_st, mmi, 9.9792015476736E+291, b_A, i_i + 2);
                xnorm *= 9.9792015476736E+291;
                atmp *= 9.9792015476736E+291;
              } while (!(muDoubleScalarAbs(xnorm) >= 1.0020841800044864E-292));

              e_st.site = &yc_emlrtRSI;
              xnorm = b_eml_xnrm2(&e_st, mmi, b_A, i_i + 2);
              xnorm = muDoubleScalarHypot(atmp, xnorm);
              if (atmp >= 0.0) {
                xnorm = -xnorm;
              }

              d16 = (xnorm - atmp) / xnorm;
              e_st.site = &ad_emlrtRSI;
              b_eml_xscal(&e_st, mmi, 1.0 / (atmp - xnorm), b_A, i_i + 2);
              e_st.site = &bd_emlrtRSI;
              if (1 > ix) {
                b14 = false;
              } else {
                b14 = (ix > 2147483646);
              }

              if (b14) {
                f_st.site = &db_emlrtRSI;
                check_forloop_overflow_error(&f_st);
              }

              for (k = 1; k <= ix; k++) {
                xnorm *= 1.0020841800044864E-292;
              }

              atmp = xnorm;
            } else {
              d16 = (xnorm - b_A->data[i_i]) / xnorm;
              atmp = 1.0 / (b_A->data[i_i] - xnorm);
              e_st.site = &cd_emlrtRSI;
              b_eml_xscal(&e_st, mmi, atmp, b_A, i_i + 2);
              atmp = xnorm;
            }
          }
        }

        tau->data[i - 1] = d16;
      } else {
        atmp = b_A->data[i_i];
        d_st.site = &pc_emlrtRSI;
        tau->data[i - 1] = eml_matlab_zlarfg();
      }

      b_A->data[i_i] = atmp;
      if (i < n) {
        atmp = b_A->data[i_i];
        b_A->data[i_i] = 1.0;
        d_st.site = &qf_emlrtRSI;
        eml_matlab_zlarf(&d_st, mmi + 1, nmi, i_i + 1, tau->data[i - 1], b_A, i
                         + i * m, m, work);
        b_A->data[i_i] = atmp;
      }

      d_st.site = &rf_emlrtRSI;
      if (i + 1 > n) {
        b_i = false;
      } else {
        b_i = (n > 2147483646);
      }

      if (b_i) {
        e_st.site = &db_emlrtRSI;
        check_forloop_overflow_error(&e_st);
      }

      for (ix = i; ix + 1 <= n; ix++) {
        if (vn1->data[ix] != 0.0) {
          xnorm = muDoubleScalarAbs(b_A->data[(i + b_A->size[0] * ix) - 1]) /
            vn1->data[ix];
          xnorm = 1.0 - xnorm * xnorm;
          if (xnorm < 0.0) {
            xnorm = 0.0;
          }

          atmp = vn1->data[ix] / vn2->data[ix];
          atmp = xnorm * (atmp * atmp);
          if (atmp <= 1.4901161193847656E-8) {
            if (i < m) {
              d_st.site = &sf_emlrtRSI;
              e_st.site = &uc_emlrtRSI;
              if (mmi < 1) {
                xnorm = 0.0;
              } else {
                f_st.site = &vc_emlrtRSI;
                g_st.site = &vc_emlrtRSI;
                n_t = (ptrdiff_t)(mmi);
                g_st.site = &vc_emlrtRSI;
                incx_t = (ptrdiff_t)(1);
                i51 = b_A->size[0] * b_A->size[1];
                i52 = (i + m * ix) + 1;
                xix0_t = (double *)(&b_A->data[emlrtDynamicBoundsCheckFastR2012b
                                    (i52, 1, i51, &vb_emlrtBCI, &f_st) - 1]);
                xnorm = dnrm2(&n_t, xix0_t, &incx_t);
              }

              vn1->data[ix] = xnorm;
              vn2->data[ix] = vn1->data[ix];
            } else {
              vn1->data[ix] = 0.0;
              vn2->data[ix] = 0.0;
            }
          } else {
            d_st.site = &tf_emlrtRSI;
            vn1->data[ix] *= muDoubleScalarSqrt(xnorm);
          }
        }
      }
    }

    emxFree_real_T(&vn2);
    emxFree_real_T(&vn1);
  }

  atmp = 0.0;
  if (mn > 0) {
    xnorm = muDoubleScalarMax(A->size[0], A->size[1]) * muDoubleScalarAbs
      (b_A->data[0]) * 2.2204460492503131E-16;
    k = 0;
    exitg1 = false;
    while ((!exitg1) && (k <= mn - 1)) {
      if (muDoubleScalarAbs(b_A->data[k + b_A->size[0] * k]) <= xnorm) {
        st.site = &lc_emlrtRSI;
        y = NULL;
        m14 = emlrtCreateCharArray(2, iv78);
        for (i = 0; i < 8; i++) {
          cv76[i] = cv77[i];
        }

        emlrtInitCharArrayR2013a(&st, 8, m14, cv76);
        emlrtAssign(&y, m14);
        b_st.site = &tg_emlrtRSI;
        emlrt_marshallIn(&b_st, c_sprintf(&b_st, b_sprintf(&b_st, y,
          emlrt_marshallOut(14.0), emlrt_marshallOut(6.0), &o_emlrtMCI),
          emlrt_marshallOut(xnorm), &p_emlrtMCI), "sprintf", cv78);
        st.site = &kc_emlrtRSI;
        b_eml_warning(&st, atmp, cv78);
        exitg1 = true;
      } else {
        atmp++;
        k++;
      }
    }
  }

  unnamed_idx_0 = (uint32_T)A->size[1];
  i51 = Y->size[0];
  Y->size[0] = (int32_T)unnamed_idx_0;
  emxEnsureCapacity(sp, (emxArray__common *)Y, i51, (int32_T)sizeof(real_T),
                    &m_emlrtRTEI);
  ix = (int32_T)unnamed_idx_0;
  for (i51 = 0; i51 < ix; i51++) {
    Y->data[i51] = 0.0;
  }

  for (ix = 0; ix < mn; ix++) {
    if (tau->data[ix] != 0.0) {
      xnorm = B->data[ix];
      i51 = A->size[0] + (int32_T)(1.0 - ((1.0 + (real_T)ix) + 1.0));
      emlrtForLoopVectorCheckR2012b((1.0 + (real_T)ix) + 1.0, 1.0, A->size[0],
        mxDOUBLE_CLASS, i51, &ac_emlrtRTEI, sp);
      for (i = 0; i < i51; i++) {
        unnamed_idx_0 = ((uint32_T)ix + i) + 2U;
        xnorm += b_A->data[((int32_T)unnamed_idx_0 + b_A->size[0] * ix) - 1] *
          B->data[(int32_T)unnamed_idx_0 - 1];
      }

      xnorm *= tau->data[ix];
      if (xnorm != 0.0) {
        B->data[ix] -= xnorm;
        i51 = A->size[0] + (int32_T)(1.0 - ((1.0 + (real_T)ix) + 1.0));
        emlrtForLoopVectorCheckR2012b((1.0 + (real_T)ix) + 1.0, 1.0, A->size[0],
          mxDOUBLE_CLASS, i51, &yb_emlrtRTEI, sp);
        for (i = 0; i < i51; i++) {
          unnamed_idx_0 = ((uint32_T)ix + i) + 2U;
          B->data[(int32_T)unnamed_idx_0 - 1] -= b_A->data[((int32_T)
            unnamed_idx_0 + b_A->size[0] * ix) - 1] * xnorm;
        }
      }
    }
  }

  emxFree_real_T(&tau);
  emlrtForLoopVectorCheckR2012b(1.0, 1.0, atmp, mxDOUBLE_CLASS, (int32_T)atmp,
    &xb_emlrtRTEI, sp);
  for (i = 0; i < (int32_T)atmp; i++) {
    Y->data[jpvt->data[i] - 1] = B->data[i];
  }

  emlrtForLoopVectorCheckR2012b(atmp, -1.0, 1.0, mxDOUBLE_CLASS, (int32_T)-(1.0
    + (-1.0 - atmp)), &wb_emlrtRTEI, sp);
  for (ix = 0; ix < (int32_T)-(1.0 + (-1.0 - atmp)); ix++) {
    xnorm = atmp + -(real_T)ix;
    Y->data[jpvt->data[(int32_T)xnorm - 1] - 1] = eml_div(Y->data[jpvt->data
      [(int32_T)xnorm - 1] - 1], b_A->data[((int32_T)xnorm + b_A->size[0] *
      ((int32_T)xnorm - 1)) - 1]);
    for (i = 0; i < (int32_T)(xnorm - 1.0); i++) {
      Y->data[jpvt->data[i] - 1] -= Y->data[jpvt->data[(int32_T)xnorm - 1] - 1] *
        b_A->data[i + b_A->size[0] * ((int32_T)xnorm - 1)];
    }
  }

  emxFree_int32_T(&jpvt);
  emxFree_real_T(&work);
  emxFree_real_T(&b_A);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Пример #7
0
/* Function Definitions */
static void b_equalizeOFDM(testMACRouterStackData *SD, const emlrtStack *sp,
  const creal_T recv_data[1280], const real_T tx_longPreamble[53], const real_T
  tx_pilots[48], const real_T c_tx_pilotLocationsWithoutGuard[4], const real_T
  tx_dataSubcarrierIndexies_data[48], const int32_T
  tx_dataSubcarrierIndexies_size[2], c_struct_T *estimate, OFDMDemodulator_1
  *hPreambleDemod, OFDMDemodulator_1 *hDataDemod, creal_T R[576],
  emxArray_creal_T *Rraw)
{
  OFDMDemodulator_1 *obj;
  const mxArray *y;
  static const int32_T iv198[2] = { 1, 45 };

  const mxArray *m49;
  char_T cv241[45];
  int32_T i;
  static const char_T cv242[45] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'y',
    's', 't', 'e', 'm', ':', 'm', 'e', 't', 'h', 'o', 'd', 'C', 'a', 'l', 'l',
    'e', 'd', 'W', 'h', 'e', 'n', 'R', 'e', 'l', 'e', 'a', 's', 'e', 'd', 'C',
    'o', 'd', 'e', 'g', 'e', 'n' };

  const mxArray *b_y;
  static const int32_T iv199[2] = { 1, 4 };

  char_T cv243[4];
  static const char_T cv244[4] = { 's', 't', 'e', 'p' };

  const mxArray *c_y;
  static const int32_T iv200[2] = { 1, 51 };

  char_T cv245[51];
  static const char_T cv246[51] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'y',
    's', 't', 'e', 'm', ':', 'm', 'e', 't', 'h', 'o', 'd', 'C', 'a', 'l', 'l',
    'e', 'd', 'W', 'h', 'e', 'n', 'L', 'o', 'c', 'k', 'e', 'd', 'R', 'e', 'l',
    'e', 'a', 's', 'e', 'd', 'C', 'o', 'd', 'e', 'g', 'e', 'n' };

  const mxArray *d_y;
  static const int32_T iv201[2] = { 1, 5 };

  char_T cv247[5];
  static const char_T cv248[5] = { 's', 'e', 't', 'u', 'p' };

  int8_T fullGrid[64];
  int32_T k;
  static const int8_T iv202[11] = { 0, 1, 2, 3, 4, 5, 59, 60, 61, 62, 63 };

  int8_T ii_data[64];
  int32_T ii;
  boolean_T exitg2;
  boolean_T guard2 = FALSE;
  int8_T b_ii_data[64];
  creal_T recv[64];
  emxArray_creal_T *RLongFirst;
  const mxArray *e_y;
  static const int32_T iv203[2] = { 1, 45 };

  const mxArray *f_y;
  static const int32_T iv204[2] = { 1, 4 };

  const mxArray *g_y;
  static const int32_T iv205[2] = { 1, 51 };

  const mxArray *h_y;
  static const int32_T iv206[2] = { 1, 5 };

  boolean_T exitg1;
  boolean_T guard1 = FALSE;
  creal_T b_recv[64];
  emxArray_creal_T *RLongSecond;
  emxArray_creal_T *b_R;
  creal_T c_R[106];
  real_T b_tx_longPreamble[106];
  creal_T RNormal[106];
  real_T dv13[106];
  real_T dv14[106];
  real_T REnergy[53];
  creal_T RConj[53];
  creal_T b_RConj[53];
  const mxArray *i_y;
  static const int32_T iv207[2] = { 1, 45 };

  const mxArray *j_y;
  static const int32_T iv208[2] = { 1, 4 };

  const mxArray *k_y;
  static const int32_T iv209[2] = { 1, 51 };

  const mxArray *l_y;
  static const int32_T iv210[2] = { 1, 5 };

  int8_T b_fullGrid[768];
  static const int16_T iv211[48] = { 11, 25, 39, 53, 75, 89, 103, 117, 139, 153,
    167, 181, 203, 217, 231, 245, 267, 281, 295, 309, 331, 345, 359, 373, 395,
    409, 423, 437, 459, 473, 487, 501, 523, 537, 551, 565, 587, 601, 615, 629,
    651, 665, 679, 693, 715, 729, 743, 757 };

  boolean_T c_fullGrid[768];
  int32_T ii_size[1];
  int32_T c_ii_data[768];
  real_T d_ii_data[768];
  int32_T b_ii_size[1];
  creal_T RXPilots[48];
  creal_T preambleGainsFull[636];
  int32_T ia;
  int32_T iv212[3];
  static const int8_T iv213[3] = { 48, 12, 1 };

  int32_T b_Rraw[3];
  creal_T PilotNormal[48];
  real_T pilotEqGains_re;
  real_T pilotEqGains_im;
  real_T a[48];
  real_T PilotEnergy[48];
  creal_T b_PilotNormal[48];
  creal_T pilotEqGains[576];
  creal_T preambleGainsFull_data[576];
  creal_T b_preambleGainsFull_data[576];
  creal_T c_preambleGainsFull_data[576];
  real_T preambleGainsFull_data_re;
  real_T preambleGainsFull_data_im;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  st.prev = sp;
  st.tls = sp->tls;
  b_st.prev = &st;
  b_st.tls = st.tls;
  c_st.prev = &b_st;
  c_st.tls = b_st.tls;
  d_st.prev = &c_st;
  d_st.tls = c_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);

  /*  equalizeOFDM: Equalize the entire OFDM frame through the use of both */
  /*  the long preamble from the 802.11a standard and four pilot tones in */
  /*  the data frames themselves.  The gains from the pilots are */
  /*  interpolated across frequency to fill the data frame and apply gains */
  /*  to all data subcarriers. */
  /*     %% Use Long Preamble frame to estimate channel in frequency domain */
  /*  Separate out received preambles */
  emlrtVectorVectorIndexCheckR2012b(1280, 1, 1, 160, &y_emlrtECI, sp);

  /*  Demod */
  st.site = &xr_emlrtRSI;
  obj = hPreambleDemod;
  if (!obj->isReleased) {
  } else {
    y = NULL;
    m49 = mxCreateCharArray(2, iv198);
    for (i = 0; i < 45; i++) {
      cv241[i] = cv242[i];
    }

    emlrtInitCharArrayR2013a(&st, 45, m49, cv241);
    emlrtAssign(&y, m49);
    b_y = NULL;
    m49 = mxCreateCharArray(2, iv199);
    for (i = 0; i < 4; i++) {
      cv243[i] = cv244[i];
    }

    emlrtInitCharArrayR2013a(&st, 4, m49, cv243);
    emlrtAssign(&b_y, m49);
    b_st.site = &cb_emlrtRSI;
    c_error(&b_st, message(&b_st, y, b_y, &emlrtMCI), &emlrtMCI);
  }

  if (!obj->isInitialized) {
    b_st.site = &cb_emlrtRSI;
    if (!obj->isInitialized) {
    } else {
      c_y = NULL;
      m49 = mxCreateCharArray(2, iv200);
      for (i = 0; i < 51; i++) {
        cv245[i] = cv246[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 51, m49, cv245);
      emlrtAssign(&c_y, m49);
      d_y = NULL;
      m49 = mxCreateCharArray(2, iv201);
      for (i = 0; i < 5; i++) {
        cv247[i] = cv248[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 5, m49, cv247);
      emlrtAssign(&d_y, m49);
      c_st.site = &cb_emlrtRSI;
      c_error(&c_st, message(&c_st, c_y, d_y, &emlrtMCI), &emlrtMCI);
    }

    c_st.site = &cb_emlrtRSI;
    obj->isInitialized = TRUE;
    d_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    memset(&fullGrid[0], 1, sizeof(int8_T) << 6);
    for (k = 0; k < 11; k++) {
      fullGrid[iv202[k]] = 0;
    }

    d_st.site = &fs_emlrtRSI;
    i = 0;
    ii = 1;
    exitg2 = FALSE;
    while ((exitg2 == FALSE) && (ii < 65)) {
      guard2 = FALSE;
      if (fullGrid[ii - 1] == 1) {
        i++;
        ii_data[i - 1] = (int8_T)ii;
        if (i >= 64) {
          exitg2 = TRUE;
        } else {
          guard2 = TRUE;
        }
      } else {
        guard2 = TRUE;
      }

      if (guard2 == TRUE) {
        ii++;
      }
    }

    if (1 > i) {
      i = 0;
    }

    for (k = 0; k < i; k++) {
      b_ii_data[k] = ii_data[k];
    }

    for (k = 0; k < i; k++) {
      ii_data[k] = b_ii_data[k];
    }

    d_st.site = &fs_emlrtRSI;
    k = obj->pDataLinearIndices->size[0];
    obj->pDataLinearIndices->size[0] = i;
    emxEnsureCapacity(&d_st, (emxArray__common *)obj->pDataLinearIndices, k,
                      (int32_T)sizeof(real_T), &pb_emlrtRTEI);
    for (k = 0; k < i; k++) {
      obj->pDataLinearIndices->data[k] = ii_data[k];
    }

    c_st.site = &cb_emlrtRSI;
  }

  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  memcpy(&recv[0], &recv_data[192], sizeof(creal_T) << 6);
  emxInit_creal_T(&st, &RLongFirst, 3, &yb_emlrtRTEI, TRUE);
  b_st.site = &cb_emlrtRSI;
  OFDMDemodulator_stepImpl(&b_st, obj, recv, RLongFirst);

  /* First half of long preamble */
  st.site = &yr_emlrtRSI;
  obj = hPreambleDemod;
  if (!obj->isReleased) {
  } else {
    e_y = NULL;
    m49 = mxCreateCharArray(2, iv203);
    for (i = 0; i < 45; i++) {
      cv241[i] = cv242[i];
    }

    emlrtInitCharArrayR2013a(&st, 45, m49, cv241);
    emlrtAssign(&e_y, m49);
    f_y = NULL;
    m49 = mxCreateCharArray(2, iv204);
    for (i = 0; i < 4; i++) {
      cv243[i] = cv244[i];
    }

    emlrtInitCharArrayR2013a(&st, 4, m49, cv243);
    emlrtAssign(&f_y, m49);
    b_st.site = &cb_emlrtRSI;
    c_error(&b_st, message(&b_st, e_y, f_y, &emlrtMCI), &emlrtMCI);
  }

  if (!obj->isInitialized) {
    b_st.site = &cb_emlrtRSI;
    if (!obj->isInitialized) {
    } else {
      g_y = NULL;
      m49 = mxCreateCharArray(2, iv205);
      for (i = 0; i < 51; i++) {
        cv245[i] = cv246[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 51, m49, cv245);
      emlrtAssign(&g_y, m49);
      h_y = NULL;
      m49 = mxCreateCharArray(2, iv206);
      for (i = 0; i < 5; i++) {
        cv247[i] = cv248[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 5, m49, cv247);
      emlrtAssign(&h_y, m49);
      c_st.site = &cb_emlrtRSI;
      c_error(&c_st, message(&c_st, g_y, h_y, &emlrtMCI), &emlrtMCI);
    }

    c_st.site = &cb_emlrtRSI;
    obj->isInitialized = TRUE;
    d_st.site = &db_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    memset(&fullGrid[0], 1, sizeof(int8_T) << 6);
    for (k = 0; k < 11; k++) {
      fullGrid[iv202[k]] = 0;
    }

    d_st.site = &fs_emlrtRSI;
    i = 0;
    ii = 1;
    exitg1 = FALSE;
    while ((exitg1 == FALSE) && (ii < 65)) {
      guard1 = FALSE;
      if (fullGrid[ii - 1] == 1) {
        i++;
        ii_data[i - 1] = (int8_T)ii;
        if (i >= 64) {
          exitg1 = TRUE;
        } else {
          guard1 = TRUE;
        }
      } else {
        guard1 = TRUE;
      }

      if (guard1 == TRUE) {
        ii++;
      }
    }

    if (1 > i) {
      i = 0;
    }

    for (k = 0; k < i; k++) {
      b_ii_data[k] = ii_data[k];
    }

    for (k = 0; k < i; k++) {
      ii_data[k] = b_ii_data[k];
    }

    d_st.site = &fs_emlrtRSI;
    k = obj->pDataLinearIndices->size[0];
    obj->pDataLinearIndices->size[0] = i;
    emxEnsureCapacity(&d_st, (emxArray__common *)obj->pDataLinearIndices, k,
                      (int32_T)sizeof(real_T), &pb_emlrtRTEI);
    for (k = 0; k < i; k++) {
      obj->pDataLinearIndices->data[k] = ii_data[k];
    }

    c_st.site = &cb_emlrtRSI;
  }

  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  memcpy(&b_recv[0], &recv_data[256], sizeof(creal_T) << 6);
  emxInit_creal_T(&st, &RLongSecond, 3, &ac_emlrtRTEI, TRUE);
  emxInit_creal_T(&st, &b_R, 3, &pb_emlrtRTEI, TRUE);
  b_st.site = &cb_emlrtRSI;
  OFDMDemodulator_stepImpl(&b_st, obj, b_recv, RLongSecond);

  /* Second half of long preamble */
  /*     %% Preamble Equalization */
  /*  Get Equalizer tap gains */
  k = RLongFirst->size[0];
  ii = RLongSecond->size[0];
  emlrtDimSizeEqCheckFastR2012b(k, ii, &x_emlrtECI, sp);
  st.site = &as_emlrtRSI;
  k = b_R->size[0] * b_R->size[1] * b_R->size[2];
  b_R->size[0] = RLongFirst->size[0];
  b_R->size[1] = 2;
  b_R->size[2] = 1;
  emxEnsureCapacity(&st, (emxArray__common *)b_R, k, (int32_T)sizeof(creal_T),
                    &pb_emlrtRTEI);
  i = RLongFirst->size[0];
  for (k = 0; k < i; k++) {
    b_R->data[k] = RLongFirst->data[k];
  }

  emxFree_creal_T(&RLongFirst);
  i = RLongSecond->size[0];
  for (k = 0; k < i; k++) {
    b_R->data[k + b_R->size[0]] = RLongSecond->data[k];
  }

  emxFree_creal_T(&RLongSecond);

  /*  Calculate Equalizer Taps with preamble symbols */
  /*  Calculate non-normalized channel gains */
  for (k = 0; k < 53; k++) {
    ii = b_R->size[0];
    i = 1 + k;
    emlrtDynamicBoundsCheckFastR2012b(i, 1, ii, &lb_emlrtBCI, &st);
  }

  i = b_R->size[0];
  for (k = 0; k < 2; k++) {
    for (ii = 0; ii < 53; ii++) {
      c_R[ii + 53 * k] = b_R->data[ii + i * k];
    }
  }

  emxFree_creal_T(&b_R);
  for (k = 0; k < 53; k++) {
    b_tx_longPreamble[k] = tx_longPreamble[k];
    b_tx_longPreamble[53 + k] = tx_longPreamble[k];
  }

  b_st.site = &bt_emlrtRSI;
  b_rdivide(c_R, b_tx_longPreamble, RNormal);

  /*  Known is the original Long Preamble symbols  */
  /*  Scale channel gains */
  b_st.site = &ct_emlrtRSI;
  d_abs(RNormal, dv13);
  memcpy(&dv14[0], &dv13[0], 106U * sizeof(real_T));
  b_st.site = &ct_emlrtRSI;
  b_power(dv14, dv13);
  b_st.site = &ct_emlrtRSI;
  c_mean(dv13, REnergy);
  b_st.site = &dt_emlrtRSI;
  d_mean(RNormal, RConj);
  for (k = 0; k < 53; k++) {
    RConj[k].im = -RConj[k].im;
    b_RConj[k] = RConj[k];
  }

  b_st.site = &et_emlrtRSI;
  c_rdivide(b_RConj, REnergy, RConj);

  /*  Separate data from preambles */
  /* recvData = recv(length(tx.preambles)+1:length(tx.preambles)+(hDataDemod.NumSymbols)*(tx.FFTLength+hDataDemod.CyclicPrefixLength)); */
  emlrtVectorVectorIndexCheckR2012b(1280, 1, 1, 960, &w_emlrtECI, sp);

  /*  CG */
  /*  OFDM Demod */
  st.site = &bs_emlrtRSI;
  obj = hDataDemod;
  if (!obj->isReleased) {
  } else {
    i_y = NULL;
    m49 = mxCreateCharArray(2, iv207);
    for (i = 0; i < 45; i++) {
      cv241[i] = cv242[i];
    }

    emlrtInitCharArrayR2013a(&st, 45, m49, cv241);
    emlrtAssign(&i_y, m49);
    j_y = NULL;
    m49 = mxCreateCharArray(2, iv208);
    for (i = 0; i < 4; i++) {
      cv243[i] = cv244[i];
    }

    emlrtInitCharArrayR2013a(&st, 4, m49, cv243);
    emlrtAssign(&j_y, m49);
    b_st.site = &cb_emlrtRSI;
    c_error(&b_st, message(&b_st, i_y, j_y, &emlrtMCI), &emlrtMCI);
  }

  if (!obj->isInitialized) {
    b_st.site = &cb_emlrtRSI;
    if (!obj->isInitialized) {
    } else {
      k_y = NULL;
      m49 = mxCreateCharArray(2, iv209);
      for (i = 0; i < 51; i++) {
        cv245[i] = cv246[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 51, m49, cv245);
      emlrtAssign(&k_y, m49);
      l_y = NULL;
      m49 = mxCreateCharArray(2, iv210);
      for (i = 0; i < 5; i++) {
        cv247[i] = cv248[i];
      }

      emlrtInitCharArrayR2013a(&b_st, 5, m49, cv247);
      emlrtAssign(&l_y, m49);
      c_st.site = &cb_emlrtRSI;
      c_error(&c_st, message(&c_st, k_y, l_y, &emlrtMCI), &emlrtMCI);
    }

    c_st.site = &cb_emlrtRSI;
    g_SystemProp_matlabCodegenSetAn(obj);
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    b_SystemCore_validateProperties();
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    d_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    c_st.site = &cb_emlrtRSI;
    memset(&b_fullGrid[0], 1, 768U * sizeof(int8_T));
    for (k = 0; k < 12; k++) {
      for (ii = 0; ii < 11; ii++) {
        b_fullGrid[iv202[ii] + (k << 6)] = 0;
      }

      b_fullGrid[32 + (k << 6)] = 0;
    }

    d_st.site = &st_emlrtRSI;
    d_st.site = &st_emlrtRSI;
    for (k = 0; k < 48; k++) {
      b_fullGrid[iv211[k]] = 2;
    }

    d_st.site = &fs_emlrtRSI;
    for (k = 0; k < 768; k++) {
      c_fullGrid[k] = (b_fullGrid[k] == 1);
    }

    eml_find(c_fullGrid, c_ii_data, ii_size);
    b_ii_size[0] = ii_size[0];
    i = ii_size[0];
    for (k = 0; k < i; k++) {
      d_ii_data[k] = c_ii_data[k];
    }

    d_st.site = &fs_emlrtRSI;
    h_SystemProp_matlabCodegenSetAn(&d_st, obj, d_ii_data, b_ii_size);
    c_st.site = &cb_emlrtRSI;
  }

  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  c_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_st.site = &cb_emlrtRSI;
  b_OFDMDemodulator_stepImpl(SD, &b_st, obj, *(creal_T (*)[960])&recv_data[320],
    Rraw, RXPilots);

  /*  Expand equalizer gains to full frame size */
  st.site = &cs_emlrtRSI;
  i = 0;
  for (ii = 0; ii < 12; ii++) {
    ia = 0;
    for (k = 0; k < 53; k++) {
      preambleGainsFull[i] = RConj[ia];
      b_st.site = &ng_emlrtRSI;
      ia++;
      b_st.site = &og_emlrtRSI;
      i++;
    }
  }

  /*  Isolate pilot gains from preamble equalizer */
  /*  Needed to correctly adjust pilot gains */
  /*  Apply preamble equalizer gains to data and pilots */
  /* Correct pilots */
  for (i = 0; i < 3; i++) {
    iv212[i] = iv213[i];
  }

  for (k = 0; k < 3; k++) {
    b_Rraw[k] = Rraw->size[k];
  }

  emlrtSizeEqCheckNDR2012b(iv212, b_Rraw, &v_emlrtECI, sp);

  /* Correct data */
  /*     %% Pilot Equalization */
  /*  Get pilot-based equalizer gains */
  st.site = &ds_emlrtRSI;

  /*  Calculate Equalizer Taps with pilot symbols */
  /*  Calculate non-normalized channel gains */
  b_st.site = &vt_emlrtRSI;
  c_st.site = &k_emlrtRSI;
  for (k = 0; k < 12; k++) {
    for (ii = 0; ii < 4; ii++) {
      pilotEqGains_re = preambleGainsFull[((int32_T)
        c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].re * RXPilots[ii + (k
        << 2)].re - preambleGainsFull[((int32_T)
        c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].im * RXPilots[ii + (k
        << 2)].im;
      pilotEqGains_im = preambleGainsFull[((int32_T)
        c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].re * RXPilots[ii + (k
        << 2)].im + preambleGainsFull[((int32_T)
        c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].im * RXPilots[ii + (k
        << 2)].re;
      if (pilotEqGains_im == 0.0) {
        PilotNormal[ii + (k << 2)].re = pilotEqGains_re / tx_pilots[ii + (k << 2)];
        PilotNormal[ii + (k << 2)].im = 0.0;
      } else if (pilotEqGains_re == 0.0) {
        PilotNormal[ii + (k << 2)].re = 0.0;
        PilotNormal[ii + (k << 2)].im = pilotEqGains_im / tx_pilots[ii + (k << 2)];
      } else {
        PilotNormal[ii + (k << 2)].re = pilotEqGains_re / tx_pilots[ii + (k << 2)];
        PilotNormal[ii + (k << 2)].im = pilotEqGains_im / tx_pilots[ii + (k << 2)];
      }
    }
  }

  /*  Scale channel gains */
  b_st.site = &wt_emlrtRSI;
  for (k = 0; k < 48; k++) {
    c_st.site = &qc_emlrtRSI;
    d_st.site = &co_emlrtRSI;
    a[k] = muDoubleScalarHypot(PilotNormal[k].re, PilotNormal[k].im);
  }

  b_st.site = &wt_emlrtRSI;
  c_st.site = &n_emlrtRSI;
  d_st.site = &hp_emlrtRSI;
  for (k = 0; k < 48; k++) {
    d_st.site = &o_emlrtRSI;
    PilotEnergy[k] = a[k] * a[k];
  }

  b_st.site = &xt_emlrtRSI;
  c_st.site = &k_emlrtRSI;

  /*  Interpolate to data carrier size */
  for (k = 0; k < 48; k++) {
    if (-PilotNormal[k].im == 0.0) {
      b_PilotNormal[k].re = PilotNormal[k].re / PilotEnergy[k];
      b_PilotNormal[k].im = 0.0;
    } else if (PilotNormal[k].re == 0.0) {
      b_PilotNormal[k].re = 0.0;
      b_PilotNormal[k].im = -PilotNormal[k].im / PilotEnergy[k];
    } else {
      b_PilotNormal[k].re = PilotNormal[k].re / PilotEnergy[k];
      b_PilotNormal[k].im = -PilotNormal[k].im / PilotEnergy[k];
    }
  }

  b_st.site = &yt_emlrtRSI;
  resample(SD, &b_st, b_PilotNormal, pilotEqGains);

  /*  Apply Equalizer from Pilots */
  for (k = 0; k < 12; k++) {
    for (ii = 0; ii < 48; ii++) {
      preambleGainsFull_data[ii + 48 * k] = preambleGainsFull[((int32_T)
        tx_dataSubcarrierIndexies_data[tx_dataSubcarrierIndexies_size[0] * ii] +
        53 * k) - 1];
    }
  }

  for (k = 0; k < 12; k++) {
    memcpy(&b_preambleGainsFull_data[48 * k], &preambleGainsFull_data[48 * k],
           48U * sizeof(creal_T));
  }

  i = Rraw->size[0];
  for (k = 0; k < 12; k++) {
    for (ii = 0; ii < 48; ii++) {
      c_preambleGainsFull_data[ii + 48 * k].re = b_preambleGainsFull_data[ii +
        48 * k].re * Rraw->data[ii + i * k].re - b_preambleGainsFull_data[ii +
        48 * k].im * Rraw->data[ii + i * k].im;
      c_preambleGainsFull_data[ii + 48 * k].im = b_preambleGainsFull_data[ii +
        48 * k].re * Rraw->data[ii + i * k].im + b_preambleGainsFull_data[ii +
        48 * k].im * Rraw->data[ii + i * k].re;
    }
  }

  for (k = 0; k < 12; k++) {
    for (ii = 0; ii < 48; ii++) {
      pilotEqGains_re = pilotEqGains[ii + 48 * k].re;
      pilotEqGains_im = pilotEqGains[ii + 48 * k].im;
      preambleGainsFull_data_re = c_preambleGainsFull_data[ii + 48 * k].re;
      preambleGainsFull_data_im = c_preambleGainsFull_data[ii + 48 * k].im;
      R[ii + 48 * k].re = pilotEqGains_re * preambleGainsFull_data_re -
        pilotEqGains_im * preambleGainsFull_data_im;
      R[ii + 48 * k].im = pilotEqGains_re * preambleGainsFull_data_im +
        pilotEqGains_im * preambleGainsFull_data_re;
    }
  }

  /*  Save Gains for visualization */
  estimate->pilotEqGains.size[0] = 48;
  estimate->pilotEqGains.size[1] = 12;
  for (k = 0; k < 576; k++) {
    estimate->pilotEqGains.data[k] = pilotEqGains[k];
  }

  estimate->preambleEqGains.size[0] = 53;
  for (k = 0; k < 53; k++) {
    estimate->preambleEqGains.data[k] = RConj[k];
  }

  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Пример #8
0
/* Function Definitions */
void rsf2csf(const emxArray_real_T *Ur, const emxArray_real_T *Tr,
             emxArray_creal_T *U, emxArray_creal_T *T)
{
  int32_T y;
  int32_T loop_ub;
  int16_T varargin_1[2];
  int32_T mtmp;
  int32_T m;
  real_T c;
  real_T b;
  real_T temp;
  real_T p;
  real_T bcmax;
  real_T scale;
  real_T bb;
  real_T b_p;
  real_T cs;
  int32_T b_scale;
  real_T b_c;
  real_T mu1_re;
  emlrtPushRtStackR2012b(&bh_emlrtRSI, emlrtRootTLSGlobal);
  y = T->size[0] * T->size[1];
  T->size[0] = Tr->size[0];
  T->size[1] = Tr->size[1];
  emxEnsureCapacity((emxArray__common *)T, y, (int32_T)sizeof(creal_T),
                    &v_emlrtRTEI);
  loop_ub = Tr->size[0] * Tr->size[1];
  for (y = 0; y < loop_ub; y++) {
    T->data[y].re = Tr->data[y];
    T->data[y].im = 0.0;
  }

  y = U->size[0] * U->size[1];
  U->size[0] = Ur->size[0];
  U->size[1] = Ur->size[1];
  emxEnsureCapacity((emxArray__common *)U, y, (int32_T)sizeof(creal_T),
                    &v_emlrtRTEI);
  loop_ub = Ur->size[0] * Ur->size[1];
  for (y = 0; y < loop_ub; y++) {
    U->data[y].re = Ur->data[y];
    U->data[y].im = 0.0;
  }

  for (y = 0; y < 2; y++) {
    varargin_1[y] = (int16_T)Tr->size[y];
  }

  mtmp = varargin_1[0];
  if (varargin_1[1] < varargin_1[0]) {
    mtmp = varargin_1[1];
  }

  for (y = 0; y < 2; y++) {
    varargin_1[y] = (int16_T)Ur->size[y];
  }

  loop_ub = varargin_1[0];
  if (varargin_1[1] < varargin_1[0]) {
    loop_ub = varargin_1[1];
  }

  mtmp = (int32_T)muDoubleScalarMin(mtmp, loop_ub);
  if (mtmp == 0) {
  } else {
    for (m = mtmp - 1; m + 1 >= 2; m--) {
      if (Tr->data[m + Tr->size[0] * (m - 1)] != 0.0) {
        emlrtPushRtStackR2012b(&ch_emlrtRSI, emlrtRootTLSGlobal);
        c = Tr->data[m + Tr->size[0] * (m - 1)];
        b = Tr->data[(m + Tr->size[0] * m) - 1];
        temp = Tr->data[(m + Tr->size[0] * (m - 1)) - 1];
        if (Tr->data[m + Tr->size[0] * (m - 1)] == 0.0) {
        } else if (Tr->data[(m + Tr->size[0] * m) - 1] == 0.0) {
          temp = Tr->data[m + Tr->size[0] * m];
          b = -Tr->data[m + Tr->size[0] * (m - 1)];
          c = 0.0;
        } else if ((Tr->data[(m + Tr->size[0] * (m - 1)) - 1] - Tr->data[m +
                    Tr->size[0] * m] == 0.0) && ((Tr->data[(m + Tr->size[0] * m)
          - 1] < 0.0) != (Tr->data[m + Tr->size[0] * (m - 1)] < 0.0))) {
        } else {
          temp = Tr->data[(m + Tr->size[0] * (m - 1)) - 1] - Tr->data[m +
            Tr->size[0] * m];
          p = 0.5 * temp;
          bcmax = muDoubleScalarMax(muDoubleScalarAbs(Tr->data[(m + Tr->size[0] *
            m) - 1]), muDoubleScalarAbs(Tr->data[m + Tr->size[0] * (m - 1)]));
          if (!(Tr->data[(m + Tr->size[0] * m) - 1] < 0.0)) {
            loop_ub = 1;
          } else {
            loop_ub = -1;
          }

          if (!(Tr->data[m + Tr->size[0] * (m - 1)] < 0.0)) {
            y = 1;
          } else {
            y = -1;
          }

          scale = muDoubleScalarMax(muDoubleScalarAbs(p), bcmax);
          bcmax = p / scale * p + bcmax / scale * (muDoubleScalarMin
            (muDoubleScalarAbs(Tr->data[(m + Tr->size[0] * m) - 1]),
             muDoubleScalarAbs(Tr->data[m + Tr->size[0] * (m - 1)])) * (real_T)
            loop_ub * (real_T)y);
          if (bcmax >= 8.8817841970012523E-16) {
            emlrtPushRtStackR2012b(&gg_emlrtRSI, emlrtRootTLSGlobal);
            bb = muDoubleScalarSqrt(scale) * muDoubleScalarSqrt(bcmax);
            emlrtPopRtStackR2012b(&gg_emlrtRSI, emlrtRootTLSGlobal);
            if (!(p < 0.0)) {
              b_p = bb;
            } else {
              b_p = -bb;
            }

            temp = Tr->data[m + Tr->size[0] * m] + (p + b_p);
            b = Tr->data[(m + Tr->size[0] * m) - 1] - Tr->data[m + Tr->size[0] *
              (m - 1)];
            c = 0.0;
          } else {
            scale = Tr->data[(m + Tr->size[0] * m) - 1] + Tr->data[m + Tr->size
              [0] * (m - 1)];
            bcmax = muDoubleScalarHypot(scale, temp);
            emlrtPushRtStackR2012b(&hg_emlrtRSI, emlrtRootTLSGlobal);
            bb = 0.5 * (1.0 + muDoubleScalarAbs(scale) / bcmax);
            if (bb < 0.0) {
              emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
              eml_error();
              emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal);
            }

            cs = muDoubleScalarSqrt(bb);
            emlrtPopRtStackR2012b(&hg_emlrtRSI, emlrtRootTLSGlobal);
            if (!(scale < 0.0)) {
              b_scale = 1;
            } else {
              b_scale = -1;
            }

            bcmax = -(p / (bcmax * cs)) * (real_T)b_scale;
            scale = Tr->data[(m + Tr->size[0] * (m - 1)) - 1] * cs + Tr->data[(m
              + Tr->size[0] * m) - 1] * bcmax;
            bb = -Tr->data[(m + Tr->size[0] * (m - 1)) - 1] * bcmax + Tr->data
              [(m + Tr->size[0] * m) - 1] * cs;
            p = Tr->data[m + Tr->size[0] * (m - 1)] * cs + Tr->data[m + Tr->
              size[0] * m] * bcmax;
            temp = -Tr->data[m + Tr->size[0] * (m - 1)] * bcmax + Tr->data[m +
              Tr->size[0] * m] * cs;
            b = bb * cs + temp * bcmax;
            c = -scale * bcmax + p * cs;
            temp = 0.5 * ((scale * cs + p * bcmax) + (-bb * bcmax + temp * cs));
            if (c != 0.0) {
              if (b != 0.0) {
                if ((b < 0.0) == (c < 0.0)) {
                  emlrtPushRtStackR2012b(&ig_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPopRtStackR2012b(&ig_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPushRtStackR2012b(&jg_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPopRtStackR2012b(&jg_emlrtRSI, emlrtRootTLSGlobal);
                  bb = muDoubleScalarSqrt(muDoubleScalarAbs(b)) *
                    muDoubleScalarSqrt(muDoubleScalarAbs(c));
                  emlrtPushRtStackR2012b(&kg_emlrtRSI, emlrtRootTLSGlobal);
                  emlrtPopRtStackR2012b(&kg_emlrtRSI, emlrtRootTLSGlobal);
                  if (!(c < 0.0)) {
                    b_c = bb;
                  } else {
                    b_c = -bb;
                  }

                  temp += b_c;
                  b -= c;
                  c = 0.0;
                }
              } else {
                b = -c;
                c = 0.0;
              }
            }
          }
        }

        if (c == 0.0) {
          bcmax = 0.0;
        } else {
          emlrtPushRtStackR2012b(&lg_emlrtRSI, emlrtRootTLSGlobal);
          bcmax = muDoubleScalarSqrt(muDoubleScalarAbs(b)) * muDoubleScalarSqrt
            (muDoubleScalarAbs(c));
          emlrtPopRtStackR2012b(&lg_emlrtRSI, emlrtRootTLSGlobal);
        }

        emlrtPopRtStackR2012b(&ch_emlrtRSI, emlrtRootTLSGlobal);
        mu1_re = temp - Tr->data[m + Tr->size[0] * m];
        scale = muDoubleScalarHypot(muDoubleScalarHypot(mu1_re, bcmax), Tr->
          data[m + Tr->size[0] * (m - 1)]);
        if (bcmax == 0.0) {
          mu1_re /= scale;
          cs = 0.0;
        } else if (mu1_re == 0.0) {
          mu1_re = 0.0;
          cs = bcmax / scale;
        } else {
          mu1_re /= scale;
          cs = bcmax / scale;
        }

        c = Tr->data[m + Tr->size[0] * (m - 1)] / scale;
        emlrtPushRtStackR2012b(&dh_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&dh_emlrtRSI, emlrtRootTLSGlobal);
        for (loop_ub = m - 1; loop_ub + 1 <= mtmp; loop_ub++) {
          b = T->data[(m + T->size[0] * loop_ub) - 1].re;
          temp = T->data[(m + T->size[0] * loop_ub) - 1].im;
          bb = T->data[(m + T->size[0] * loop_ub) - 1].re;
          p = T->data[(m + T->size[0] * loop_ub) - 1].im;
          bcmax = T->data[(m + T->size[0] * loop_ub) - 1].im;
          scale = T->data[(m + T->size[0] * loop_ub) - 1].re;
          T->data[(m + T->size[0] * loop_ub) - 1].re = (mu1_re * bb + cs * p) +
            c * T->data[m + T->size[0] * loop_ub].re;
          T->data[(m + T->size[0] * loop_ub) - 1].im = (mu1_re * bcmax - cs *
            scale) + c * T->data[m + T->size[0] * loop_ub].im;
          bcmax = mu1_re * T->data[m + T->size[0] * loop_ub].re - cs * T->data[m
            + T->size[0] * loop_ub].im;
          scale = mu1_re * T->data[m + T->size[0] * loop_ub].im + cs * T->data[m
            + T->size[0] * loop_ub].re;
          T->data[m + T->size[0] * loop_ub].re = bcmax - c * b;
          T->data[m + T->size[0] * loop_ub].im = scale - c * temp;
        }

        emlrtPushRtStackR2012b(&eh_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&eh_emlrtRSI, emlrtRootTLSGlobal);
        for (loop_ub = 0; loop_ub + 1 <= m + 1; loop_ub++) {
          b = T->data[loop_ub + T->size[0] * (m - 1)].re;
          temp = T->data[loop_ub + T->size[0] * (m - 1)].im;
          bcmax = mu1_re * T->data[loop_ub + T->size[0] * (m - 1)].re - cs *
            T->data[loop_ub + T->size[0] * (m - 1)].im;
          scale = mu1_re * T->data[loop_ub + T->size[0] * (m - 1)].im + cs *
            T->data[loop_ub + T->size[0] * (m - 1)].re;
          bb = T->data[loop_ub + T->size[0] * m].re;
          p = T->data[loop_ub + T->size[0] * m].im;
          T->data[loop_ub + T->size[0] * (m - 1)].re = bcmax + c * bb;
          T->data[loop_ub + T->size[0] * (m - 1)].im = scale + c * p;
          bb = T->data[loop_ub + T->size[0] * m].re;
          p = T->data[loop_ub + T->size[0] * m].im;
          bcmax = T->data[loop_ub + T->size[0] * m].im;
          scale = T->data[loop_ub + T->size[0] * m].re;
          T->data[loop_ub + T->size[0] * m].re = (mu1_re * bb + cs * p) - c * b;
          T->data[loop_ub + T->size[0] * m].im = (mu1_re * bcmax - cs * scale) -
            c * temp;
        }

        emlrtPushRtStackR2012b(&fh_emlrtRSI, emlrtRootTLSGlobal);
        emlrtPopRtStackR2012b(&fh_emlrtRSI, emlrtRootTLSGlobal);
        for (loop_ub = 0; loop_ub + 1 <= mtmp; loop_ub++) {
          b = U->data[loop_ub + U->size[0] * (m - 1)].re;
          temp = U->data[loop_ub + U->size[0] * (m - 1)].im;
          bcmax = mu1_re * U->data[loop_ub + U->size[0] * (m - 1)].re - cs *
            U->data[loop_ub + U->size[0] * (m - 1)].im;
          scale = mu1_re * U->data[loop_ub + U->size[0] * (m - 1)].im + cs *
            U->data[loop_ub + U->size[0] * (m - 1)].re;
          bb = U->data[loop_ub + U->size[0] * m].re;
          p = U->data[loop_ub + U->size[0] * m].im;
          U->data[loop_ub + U->size[0] * (m - 1)].re = bcmax + c * bb;
          U->data[loop_ub + U->size[0] * (m - 1)].im = scale + c * p;
          bb = U->data[loop_ub + U->size[0] * m].re;
          p = U->data[loop_ub + U->size[0] * m].im;
          bcmax = U->data[loop_ub + U->size[0] * m].im;
          scale = U->data[loop_ub + U->size[0] * m].re;
          U->data[loop_ub + U->size[0] * m].re = (mu1_re * bb + cs * p) - c * b;
          U->data[loop_ub + U->size[0] * m].im = (mu1_re * bcmax - cs * scale) -
            c * temp;
        }

        T->data[m + T->size[0] * (m - 1)].re = 0.0;
        T->data[m + T->size[0] * (m - 1)].im = 0.0;
      }
    }
  }

  emlrtPopRtStackR2012b(&bh_emlrtRSI, emlrtRootTLSGlobal);
}
Пример #9
0
/* Function Definitions */
boolean_T relop(const creal_T a, const creal_T b)
{
  boolean_T p;
  real_T absbi;
  real_T y;
  real_T absxk;
  int32_T exponent;
  real_T absar;
  real_T absbr;
  real_T Ma;
  int32_T b_exponent;
  int32_T c_exponent;
  int32_T d_exponent;
  if ((muDoubleScalarAbs(a.re) > 8.9884656743115785E+307) || (muDoubleScalarAbs
       (a.im) > 8.9884656743115785E+307) || (muDoubleScalarAbs(b.re) >
       8.9884656743115785E+307) || (muDoubleScalarAbs(b.im) >
       8.9884656743115785E+307)) {
    absbi = muDoubleScalarHypot(a.re / 2.0, a.im / 2.0);
    y = muDoubleScalarHypot(b.re / 2.0, b.im / 2.0);
  } else {
    absbi = muDoubleScalarHypot(a.re, a.im);
    y = muDoubleScalarHypot(b.re, b.im);
  }

  absxk = y / 2.0;
  if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
    if (absxk <= 2.2250738585072014E-308) {
      absxk = 4.94065645841247E-324;
    } else {
      frexp(absxk, &exponent);
      absxk = ldexp(1.0, exponent - 53);
    }
  } else {
    absxk = rtNaN;
  }

  if ((muDoubleScalarAbs(y - absbi) < absxk) || (muDoubleScalarIsInf(absbi) &&
       muDoubleScalarIsInf(y) && ((absbi > 0.0) == (y > 0.0)))) {
    p = true;
  } else {
    p = false;
  }

  if (p) {
    absar = muDoubleScalarAbs(a.re);
    absxk = muDoubleScalarAbs(a.im);
    absbr = muDoubleScalarAbs(b.re);
    absbi = muDoubleScalarAbs(b.im);
    if (absar > absxk) {
      Ma = absar;
      absar = absxk;
    } else {
      Ma = absxk;
    }

    if (absbr > absbi) {
      absxk = absbr;
      absbr = absbi;
    } else {
      absxk = absbi;
    }

    if (Ma > absxk) {
      if (absar < absbr) {
        absbi = Ma - absxk;
        y = (absar / 2.0 + absbr / 2.0) / (Ma / 2.0 + absxk / 2.0) * (absbr -
          absar);
      } else {
        absbi = Ma;
        y = absxk;
      }
    } else if (Ma < absxk) {
      if (absar > absbr) {
        y = absxk - Ma;
        absbi = (absar / 2.0 + absbr / 2.0) / (Ma / 2.0 + absxk / 2.0) * (absar
          - absbr);
      } else {
        absbi = Ma;
        y = absxk;
      }
    } else {
      absbi = absar;
      y = absbr;
    }

    absxk = muDoubleScalarAbs(y / 2.0);
    if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
      if (absxk <= 2.2250738585072014E-308) {
        absxk = 4.94065645841247E-324;
      } else {
        frexp(absxk, &b_exponent);
        absxk = ldexp(1.0, b_exponent - 53);
      }
    } else {
      absxk = rtNaN;
    }

    if ((muDoubleScalarAbs(y - absbi) < absxk) || (muDoubleScalarIsInf(absbi) &&
         muDoubleScalarIsInf(y) && ((absbi > 0.0) == (y > 0.0)))) {
      p = true;
    } else {
      p = false;
    }

    if (p) {
      absbi = muDoubleScalarAtan2(a.im, a.re);
      y = muDoubleScalarAtan2(b.im, b.re);
      absxk = muDoubleScalarAbs(y / 2.0);
      if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
        if (absxk <= 2.2250738585072014E-308) {
          absxk = 4.94065645841247E-324;
        } else {
          frexp(absxk, &c_exponent);
          absxk = ldexp(1.0, c_exponent - 53);
        }
      } else {
        absxk = rtNaN;
      }

      if ((muDoubleScalarAbs(y - absbi) < absxk) || (muDoubleScalarIsInf(absbi) &&
           muDoubleScalarIsInf(y) && ((absbi > 0.0) == (y > 0.0)))) {
        p = true;
      } else {
        p = false;
      }

      if (p) {
        if (absbi > 0.78539816339744828) {
          if (absbi > 2.3561944901923448) {
            absbi = -a.im;
            y = -b.im;
          } else {
            absbi = -a.re;
            y = -b.re;
          }
        } else if (absbi > -0.78539816339744828) {
          absbi = a.im;
          y = b.im;
        } else if (absbi > -2.3561944901923448) {
          absbi = a.re;
          y = b.re;
        } else {
          absbi = -a.im;
          y = -b.im;
        }

        absxk = muDoubleScalarAbs(y / 2.0);
        if ((!muDoubleScalarIsInf(absxk)) && (!muDoubleScalarIsNaN(absxk))) {
          if (absxk <= 2.2250738585072014E-308) {
            absxk = 4.94065645841247E-324;
          } else {
            frexp(absxk, &d_exponent);
            absxk = ldexp(1.0, d_exponent - 53);
          }
        } else {
          absxk = rtNaN;
        }

        if ((muDoubleScalarAbs(y - absbi) < absxk) || (muDoubleScalarIsInf(absbi)
             && muDoubleScalarIsInf(y) && ((absbi > 0.0) == (y > 0.0)))) {
          p = true;
        } else {
          p = false;
        }

        if (p) {
          absbi = 0.0;
          y = 0.0;
        }
      }
    }
  }

  return absbi <= y;
}