Esempio n. 1
0
/*
 * Arguments    : const mxArray *prhs[5]
 *                const mxArray *plhs[1]
 * Return Type  : void
 */
void SpringForce_api(const mxArray *prhs[5], const mxArray *plhs[1])
{
  emxArray_real_T *particleDist;
  emxArray_real_T *springConst;
  emxArray_boolean_T *connectivityMap;
  emxArray_real_T *minParticleDist;
  emxArray_real_T *fixedParticleNum;
  emxArray_real_T *force;
  emlrtStack st = { NULL, NULL, NULL };

  st.tls = emlrtRootTLSGlobal;
  emlrtHeapReferenceStackEnterFcnR2012b(&st);
  emxInit_real_T(&st, &particleDist, 2, true);
  emxInit_real_T(&st, &springConst, 2, true);
  emxInit_boolean_T(&st, &connectivityMap, 2, true);
  emxInit_real_T(&st, &minParticleDist, 2, true);
  emxInit_real_T(&st, &fixedParticleNum, 2, true);
  emxInit_real_T(&st, &force, 2, true);
  prhs[0] = emlrtProtectR2012b(prhs[0], 0, false, -1);
  prhs[1] = emlrtProtectR2012b(prhs[1], 1, false, -1);
  prhs[2] = emlrtProtectR2012b(prhs[2], 2, false, -1);
  prhs[3] = emlrtProtectR2012b(prhs[3], 3, false, -1);
  prhs[4] = emlrtProtectR2012b(prhs[4], 4, false, -1);

  /* Marshall function inputs */
  emlrt_marshallIn(&st, emlrtAlias(prhs[0]), "particleDist", particleDist);
  emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "springConst", springConst);
  c_emlrt_marshallIn(&st, emlrtAlias(prhs[2]), "connectivityMap",
                     connectivityMap);
  emlrt_marshallIn(&st, emlrtAlias(prhs[3]), "minParticleDist", minParticleDist);
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[4]), "fixedParticleNum",
                     fixedParticleNum);

  /* Invoke the target function */
  SpringForce(particleDist, springConst, connectivityMap, minParticleDist,
              fixedParticleNum, force);

  /* Marshall function outputs */
  plhs[0] = emlrt_marshallOut(force);
  force->canFreeData = false;
  emxFree_real_T(&force);
  fixedParticleNum->canFreeData = false;
  emxFree_real_T(&fixedParticleNum);
  minParticleDist->canFreeData = false;
  emxFree_real_T(&minParticleDist);
  connectivityMap->canFreeData = false;
  emxFree_boolean_T(&connectivityMap);
  springConst->canFreeData = false;
  emxFree_real_T(&springConst);
  particleDist->canFreeData = false;
  emxFree_real_T(&particleDist);
  emlrtHeapReferenceStackLeaveFcnR2012b(&st);
}
Esempio n. 2
0
/* Function Definitions */
void MechanicalPointForce(const emlrtStack *sp, const emxArray_real_T
  *particlePosition, const emxArray_real_T *pointSourcePosition, real_T
  forceDirection, real_T forceMagnitude, real_T cutoff, emxArray_real_T *force)
{
  uint32_T sz[2];
  int32_T ix;
  emxArray_real_T *forceTemp;
  int32_T loop_ub;
  emxArray_real_T *forceMag;
  int32_T vlen;
  int32_T sIdx;
  emxArray_real_T *forceDir;
  emxArray_real_T *distToSource;
  emxArray_int32_T *r0;
  emxArray_boolean_T *r1;
  emxArray_int32_T *r2;
  emxArray_real_T *x;
  emxArray_real_T *b_x;
  emxArray_real_T *r3;
  emxArray_real_T *r4;
  emxArray_real_T *b_pointSourcePosition;
  emxArray_real_T *b_forceDir;
  emxArray_real_T *c_forceDir;
  int32_T k;
  int32_T vstride;
  int32_T iy;
  int32_T ixstart;
  boolean_T overflow;
  real_T s;
  boolean_T b0;
  uint32_T varargin_2[2];
  boolean_T p;
  boolean_T exitg1;
  int32_T iv0[1];
  int32_T iv1[2];
  int32_T b_force[2];
  int32_T iv2[1];
  int32_T b_iy;
  int32_T c_iy;
  int32_T b_forceTemp[2];
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_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;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);

  /*  apply mechanical (push or pull) force on particles */
  /*  mechanicalForce is a logical flag  */
  /*  particlPosition is a N by 3 vector of particle position */
  /*  pointSourcePosition is the position of force sources  */
  /*  forceDirection is either  -1 for 'in' or 1 for 'out' */
  /*  forceMagnitude is a positive number between 0 and 1 */
  /*  cutoff is the maximal direction the force operates on particle relative */
  /*  to the pointSourcePosition  */
  /*  the output is a vector of N by 3 of delta position to th */
  for (ix = 0; ix < 2; ix++) {
    sz[ix] = (uint32_T)particlePosition->size[ix];
  }

  emxInit_real_T(sp, &forceTemp, 2, &c_emlrtRTEI, true);
  ix = forceTemp->size[0] * forceTemp->size[1];
  forceTemp->size[0] = (int32_T)sz[0];
  emxEnsureCapacity(sp, (emxArray__common *)forceTemp, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  ix = forceTemp->size[0] * forceTemp->size[1];
  forceTemp->size[1] = (int32_T)sz[1];
  emxEnsureCapacity(sp, (emxArray__common *)forceTemp, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  loop_ub = (int32_T)sz[0] * (int32_T)sz[1];
  for (ix = 0; ix < loop_ub; ix++) {
    forceTemp->data[ix] = 0.0;
  }

  for (ix = 0; ix < 2; ix++) {
    sz[ix] = (uint32_T)particlePosition->size[ix];
  }

  ix = force->size[0] * force->size[1];
  force->size[0] = (int32_T)sz[0];
  emxEnsureCapacity(sp, (emxArray__common *)force, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  ix = force->size[0] * force->size[1];
  force->size[1] = (int32_T)sz[1];
  emxEnsureCapacity(sp, (emxArray__common *)force, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  loop_ub = (int32_T)sz[0] * (int32_T)sz[1];
  for (ix = 0; ix < loop_ub; ix++) {
    force->data[ix] = 0.0;
  }

  emxInit_real_T(sp, &forceMag, 2, &d_emlrtRTEI, true);
  vlen = particlePosition->size[0];
  ix = forceMag->size[0] * forceMag->size[1];
  forceMag->size[0] = vlen;
  emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  vlen = particlePosition->size[0];
  ix = forceMag->size[0] * forceMag->size[1];
  forceMag->size[1] = vlen;
  emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  loop_ub = particlePosition->size[0] * particlePosition->size[0];
  for (ix = 0; ix < loop_ub; ix++) {
    forceMag->data[ix] = 0.0;
  }

  sIdx = 0;
  emxInit_real_T(sp, &forceDir, 2, &e_emlrtRTEI, true);
  b_emxInit_real_T(sp, &distToSource, 1, &f_emlrtRTEI, true);
  emxInit_int32_T(sp, &r0, 1, &emlrtRTEI, true);
  emxInit_boolean_T(sp, &r1, 2, &emlrtRTEI, true);
  emxInit_int32_T(sp, &r2, 1, &emlrtRTEI, true);
  emxInit_real_T(sp, &x, 2, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &b_x, 1, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &r3, 1, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &r4, 1, &emlrtRTEI, true);
  emxInit_real_T(sp, &b_pointSourcePosition, 2, &emlrtRTEI, true);
  b_emxInit_real_T(sp, &b_forceDir, 1, &emlrtRTEI, true);
  emxInit_real_T(sp, &c_forceDir, 2, &emlrtRTEI, true);
  while (sIdx <= pointSourcePosition->size[0] - 1) {
    loop_ub = pointSourcePosition->size[1];
    ix = pointSourcePosition->size[0];
    if ((sIdx + 1 >= 1) && (sIdx + 1 < ix)) {
      vlen = sIdx + 1;
    } else {
      vlen = emlrtDynamicBoundsCheckR2012b(sIdx + 1, 1, ix, (emlrtBCInfo *)
        &e_emlrtBCI, sp);
    }

    ix = b_pointSourcePosition->size[0] * b_pointSourcePosition->size[1];
    b_pointSourcePosition->size[0] = 1;
    b_pointSourcePosition->size[1] = loop_ub;
    emxEnsureCapacity(sp, (emxArray__common *)b_pointSourcePosition, ix,
                      (int32_T)sizeof(real_T), &emlrtRTEI);
    for (ix = 0; ix < loop_ub; ix++) {
      b_pointSourcePosition->data[b_pointSourcePosition->size[0] * ix] =
        pointSourcePosition->data[(vlen + pointSourcePosition->size[0] * ix) - 1];
    }

    st.site = &emlrtRSI;
    bsxfun(&st, particlePosition, b_pointSourcePosition, forceDir);

    /*  Find the distance between the particles and the source */
    st.site = &b_emlrtRSI;
    b_st.site = &h_emlrtRSI;
    c_st.site = &i_emlrtRSI;
    d_st.site = &j_emlrtRSI;
    for (ix = 0; ix < 2; ix++) {
      sz[ix] = (uint32_T)forceDir->size[ix];
    }

    ix = x->size[0] * x->size[1];
    x->size[0] = (int32_T)sz[0];
    x->size[1] = (int32_T)sz[1];
    emxEnsureCapacity(&d_st, (emxArray__common *)x, ix, (int32_T)sizeof(real_T),
                      &b_emlrtRTEI);
    if (dimagree(x, forceDir)) {
    } else {
      emlrtErrorWithMessageIdR2012b(&d_st, &b_emlrtRTEI, "MATLAB:dimagree", 0);
    }

    ix = (int32_T)sz[0] * (int32_T)sz[1];
    for (k = 0; k < ix; k++) {
      x->data[k] = forceDir->data[k] * forceDir->data[k];
    }

    st.site = &b_emlrtRSI;
    b_st.site = &k_emlrtRSI;
    c_st.site = &l_emlrtRSI;
    for (ix = 0; ix < 2; ix++) {
      sz[ix] = (uint32_T)x->size[ix];
    }

    ix = b_x->size[0];
    b_x->size[0] = (int32_T)sz[0];
    emxEnsureCapacity(&c_st, (emxArray__common *)b_x, ix, (int32_T)sizeof(real_T),
                      &emlrtRTEI);
    if ((x->size[0] == 0) || (x->size[1] == 0)) {
      ix = b_x->size[0];
      b_x->size[0] = (int32_T)sz[0];
      emxEnsureCapacity(&c_st, (emxArray__common *)b_x, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      loop_ub = (int32_T)sz[0];
      for (ix = 0; ix < loop_ub; ix++) {
        b_x->data[ix] = 0.0;
      }
    } else {
      vlen = x->size[1];
      vstride = x->size[0];
      iy = -1;
      ixstart = -1;
      d_st.site = &m_emlrtRSI;
      overflow = (x->size[0] > 2147483646);
      if (overflow) {
        e_st.site = &g_emlrtRSI;
        check_forloop_overflow_error(&e_st);
      }

      for (loop_ub = 1; loop_ub <= vstride; loop_ub++) {
        ixstart++;
        ix = ixstart;
        s = x->data[ixstart];
        d_st.site = &n_emlrtRSI;
        if (2 > vlen) {
          b0 = false;
        } else {
          b0 = (vlen > 2147483646);
        }

        if (b0) {
          e_st.site = &g_emlrtRSI;
          check_forloop_overflow_error(&e_st);
        }

        for (k = 2; k <= vlen; k++) {
          ix += vstride;
          s += x->data[ix];
        }

        iy++;
        b_x->data[iy] = s;
      }
    }

    st.site = &b_emlrtRSI;
    ix = distToSource->size[0];
    distToSource->size[0] = b_x->size[0];
    emxEnsureCapacity(&st, (emxArray__common *)distToSource, ix, (int32_T)sizeof
                      (real_T), &emlrtRTEI);
    loop_ub = b_x->size[0];
    for (ix = 0; ix < loop_ub; ix++) {
      distToSource->data[ix] = b_x->data[ix];
    }

    for (k = 0; k < b_x->size[0]; k++) {
      if (b_x->data[k] < 0.0) {
        b_st.site = &o_emlrtRSI;
        eml_error(&b_st);
      }
    }

    for (k = 0; k < b_x->size[0]; k++) {
      distToSource->data[k] = muDoubleScalarSqrt(distToSource->data[k]);
    }

    /*  Normalize the forceDirection */
    iy = 0;
    while (iy < 3) {
      loop_ub = forceDir->size[0];
      ix = r2->size[0];
      r2->size[0] = loop_ub;
      emxEnsureCapacity(sp, (emxArray__common *)r2, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        r2->data[ix] = ix;
      }

      ix = forceDir->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&c_emlrtBCI,
        sp);
      st.site = &c_emlrtRSI;
      ix = forceDir->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&d_emlrtBCI,
        &st);
      ix = forceDir->size[0];
      sz[0] = (uint32_T)ix;
      sz[1] = 1U;
      varargin_2[0] = (uint32_T)distToSource->size[0];
      varargin_2[1] = 1U;
      overflow = false;
      p = true;
      k = 0;
      exitg1 = false;
      while ((!exitg1) && (k < 2)) {
        if (!((int32_T)sz[k] == (int32_T)varargin_2[k])) {
          p = false;
          exitg1 = true;
        } else {
          k++;
        }
      }

      if (!p) {
      } else {
        overflow = true;
      }

      if (overflow) {
      } else {
        emlrtErrorWithMessageIdR2012b(&st, &l_emlrtRTEI, "MATLAB:dimagree", 0);
      }

      loop_ub = forceDir->size[0];
      ix = b_x->size[0];
      b_x->size[0] = loop_ub;
      emxEnsureCapacity(&st, (emxArray__common *)b_x, ix, (int32_T)sizeof(real_T),
                        &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        b_x->data[ix] = forceDir->data[ix + forceDir->size[0] * iy] /
          distToSource->data[ix];
      }

      iv0[0] = r2->size[0];
      emlrtSubAssignSizeCheckR2012b(iv0, 1, *(int32_T (*)[1])b_x->size, 1,
        (emlrtECInfo *)&d_emlrtECI, sp);
      loop_ub = b_x->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        forceDir->data[r2->data[ix] + forceDir->size[0] * iy] = b_x->data[ix];
      }

      /*  bsxfun(@rdivide,forceDir,distToSource); */
      iy++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }

    /*  Multiply the */
    if (forceDirection == -1.0) {
      ix = r4->size[0];
      r4->size[0] = distToSource->size[0];
      emxEnsureCapacity(sp, (emxArray__common *)r4, ix, (int32_T)sizeof(real_T),
                        &emlrtRTEI);
      loop_ub = distToSource->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        r4->data[ix] = 1.0 + distToSource->data[ix];
      }

      rdivide(sp, forceMagnitude, r4, b_x);
      vlen = b_x->size[0];
      ix = forceMag->size[0] * forceMag->size[1];
      forceMag->size[0] = vlen;
      emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      ix = forceMag->size[0] * forceMag->size[1];
      forceMag->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      loop_ub = b_x->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        forceMag->data[ix] = 1.0 - b_x->data[ix];
      }
    } else {
      if (forceDirection == 1.0) {
        ix = r3->size[0];
        r3->size[0] = distToSource->size[0];
        emxEnsureCapacity(sp, (emxArray__common *)r3, ix, (int32_T)sizeof(real_T),
                          &emlrtRTEI);
        loop_ub = distToSource->size[0];
        for (ix = 0; ix < loop_ub; ix++) {
          r3->data[ix] = 1.0 + distToSource->data[ix];
        }

        rdivide(sp, forceMagnitude, r3, b_x);
        vlen = b_x->size[0];
        ix = forceMag->size[0] * forceMag->size[1];
        forceMag->size[0] = vlen;
        emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                          (real_T), &emlrtRTEI);
        ix = forceMag->size[0] * forceMag->size[1];
        forceMag->size[1] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)forceMag, ix, (int32_T)sizeof
                          (real_T), &emlrtRTEI);
        loop_ub = b_x->size[0];
        for (ix = 0; ix < loop_ub; ix++) {
          forceMag->data[ix] = b_x->data[ix];
        }
      }
    }

    iy = 0;
    while (iy < 3) {
      ix = forceDir->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&b_emlrtBCI,
        sp);
      ix = forceDir->size[0];
      iv1[0] = ix;
      iv1[1] = 1;
      for (ix = 0; ix < 2; ix++) {
        b_force[ix] = forceMag->size[ix];
      }

      if ((iv1[0] != b_force[0]) || (1 != b_force[1])) {
        emlrtSizeEqCheckNDR2012b(iv1, b_force, (emlrtECInfo *)&c_emlrtECI, sp);
      }

      loop_ub = forceTemp->size[0];
      ix = r2->size[0];
      r2->size[0] = loop_ub;
      emxEnsureCapacity(sp, (emxArray__common *)r2, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        r2->data[ix] = ix;
      }

      ix = forceTemp->size[1];
      ixstart = 1 + iy;
      emlrtDynamicBoundsCheckR2012b(ixstart, 1, ix, (emlrtBCInfo *)&emlrtBCI, sp);
      loop_ub = forceDir->size[0];
      vlen = forceDir->size[0];
      vstride = forceDir->size[0];
      ix = b_forceDir->size[0];
      b_forceDir->size[0] = vstride;
      emxEnsureCapacity(sp, (emxArray__common *)b_forceDir, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < vstride; ix++) {
        b_forceDir->data[ix] = forceDir->data[ix + forceDir->size[0] * iy];
      }

      ix = c_forceDir->size[0] * c_forceDir->size[1];
      c_forceDir->size[0] = loop_ub;
      c_forceDir->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)c_forceDir, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < loop_ub; ix++) {
        c_forceDir->data[ix] = b_forceDir->data[ix];
      }

      ix = b_x->size[0];
      b_x->size[0] = vlen;
      emxEnsureCapacity(sp, (emxArray__common *)b_x, ix, (int32_T)sizeof(real_T),
                        &emlrtRTEI);
      for (ix = 0; ix < vlen; ix++) {
        b_x->data[ix] = c_forceDir->data[ix] * forceMag->data[ix];
      }

      iv2[0] = r2->size[0];
      emlrtSubAssignSizeCheckR2012b(iv2, 1, *(int32_T (*)[1])b_x->size, 1,
        (emlrtECInfo *)&b_emlrtECI, sp);
      loop_ub = b_x->size[0];
      for (ix = 0; ix < loop_ub; ix++) {
        forceTemp->data[r2->data[ix] + forceTemp->size[0] * iy] = b_x->data[ix];
      }

      /*  bsxfun(@times,forceDir,forceTemp); */
      iy++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }

    iy = distToSource->size[0] - 1;
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (distToSource->data[vstride] > cutoff) {
        vlen++;
      }
    }

    ix = r2->size[0];
    r2->size[0] = vlen;
    emxEnsureCapacity(sp, (emxArray__common *)r2, ix, (int32_T)sizeof(int32_T),
                      &emlrtRTEI);
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (distToSource->data[vstride] > cutoff) {
        r2->data[vlen] = vstride + 1;
        vlen++;
      }
    }

    loop_ub = forceTemp->size[1];
    vstride = forceTemp->size[0];
    vlen = r2->size[0];
    for (ix = 0; ix < loop_ub; ix++) {
      for (ixstart = 0; ixstart < vlen; ixstart++) {
        iy = r2->data[ixstart];
        if ((iy >= 1) && (iy < vstride)) {
          b_iy = iy;
        } else {
          b_iy = emlrtDynamicBoundsCheckR2012b(iy, 1, vstride, (emlrtBCInfo *)
            &f_emlrtBCI, sp);
        }

        forceTemp->data[(b_iy + forceTemp->size[0] * ix) - 1] = 0.0;
      }
    }

    ix = r1->size[0] * r1->size[1];
    r1->size[0] = forceTemp->size[0];
    r1->size[1] = forceTemp->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)r1, ix, (int32_T)sizeof(boolean_T),
                      &emlrtRTEI);
    loop_ub = forceTemp->size[0] * forceTemp->size[1];
    for (ix = 0; ix < loop_ub; ix++) {
      r1->data[ix] = muDoubleScalarIsNaN(forceTemp->data[ix]);
    }

    iy = r1->size[0] * r1->size[1] - 1;
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (r1->data[vstride]) {
        vlen++;
      }
    }

    ix = r0->size[0];
    r0->size[0] = vlen;
    emxEnsureCapacity(sp, (emxArray__common *)r0, ix, (int32_T)sizeof(int32_T),
                      &emlrtRTEI);
    vlen = 0;
    for (vstride = 0; vstride <= iy; vstride++) {
      if (r1->data[vstride]) {
        r0->data[vlen] = vstride + 1;
        vlen++;
      }
    }

    vstride = forceTemp->size[0];
    vlen = forceTemp->size[1];
    loop_ub = r0->size[0];
    for (ix = 0; ix < loop_ub; ix++) {
      ixstart = vstride * vlen;
      iy = r0->data[ix];
      if ((iy >= 1) && (iy < ixstart)) {
        c_iy = iy;
      } else {
        c_iy = emlrtDynamicBoundsCheckR2012b(iy, 1, ixstart, (emlrtBCInfo *)
          &g_emlrtBCI, sp);
      }

      forceTemp->data[c_iy - 1] = 0.0;
    }

    for (ix = 0; ix < 2; ix++) {
      b_force[ix] = force->size[ix];
    }

    for (ix = 0; ix < 2; ix++) {
      b_forceTemp[ix] = forceTemp->size[ix];
    }

    if ((b_force[0] != b_forceTemp[0]) || (b_force[1] != b_forceTemp[1])) {
      emlrtSizeEqCheckNDR2012b(b_force, b_forceTemp, (emlrtECInfo *)&emlrtECI,
        sp);
    }

    ix = force->size[0] * force->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)force, ix, (int32_T)sizeof(real_T),
                      &emlrtRTEI);
    vlen = force->size[0];
    vstride = force->size[1];
    loop_ub = vlen * vstride;
    for (ix = 0; ix < loop_ub; ix++) {
      force->data[ix] += forceTemp->data[ix];
    }

    sIdx++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_real_T(&c_forceDir);
  emxFree_real_T(&b_forceDir);
  emxFree_real_T(&b_pointSourcePosition);
  emxFree_real_T(&r4);
  emxFree_real_T(&r3);
  emxFree_real_T(&b_x);
  emxFree_real_T(&x);
  emxFree_int32_T(&r2);
  emxFree_boolean_T(&r1);
  emxFree_int32_T(&r0);
  emxFree_real_T(&distToSource);
  emxFree_real_T(&forceDir);
  emxFree_real_T(&forceMag);
  emxFree_real_T(&forceTemp);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
/* Function Definitions */
void compmat(const emlrtStack *sp, const emxArray_uint8_T *x, real_T dims,
             emxArray_real_T *y)
{
  int32_T i1;
  real_T d3;
  int32_T ii;
  int32_T i;
  emxArray_boolean_T *b_x;
  emxArray_int32_T *b_ii;
  int32_T nx;
  int32_T idx;
  boolean_T overflow;
  boolean_T exitg1;
  boolean_T guard1 = false;
  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);

  /* UNTITLED Summary of this function goes here */
  /*    Detailed explanation goes here */
  i1 = y->size[0] * y->size[1];
  y->size[0] = 1;
  if (!(dims >= 0.0)) {
    emlrtNonNegativeCheckR2012b(dims, (emlrtDCInfo *)&j_emlrtDCI, sp);
  }

  d3 = dims;
  if (d3 != (int32_T)muDoubleScalarFloor(d3)) {
    emlrtIntegerCheckR2012b(d3, (emlrtDCInfo *)&i_emlrtDCI, sp);
  }

  y->size[1] = (int32_T)d3;
  emxEnsureCapacity(sp, (emxArray__common *)y, i1, (int32_T)sizeof(real_T),
                    &f_emlrtRTEI);
  if (!(dims >= 0.0)) {
    emlrtNonNegativeCheckR2012b(dims, (emlrtDCInfo *)&j_emlrtDCI, sp);
  }

  if (d3 != (int32_T)muDoubleScalarFloor(d3)) {
    emlrtIntegerCheckR2012b(d3, (emlrtDCInfo *)&i_emlrtDCI, sp);
  }

  ii = (int32_T)d3;
  for (i1 = 0; i1 < ii; i1++) {
    y->data[i1] = 0.0;
  }

  emlrtForLoopVectorCheckR2012b(1.0, 1.0, dims, mxDOUBLE_CLASS, (int32_T)dims,
    (emlrtRTEInfo *)&n_emlrtRTEI, sp);
  i = 0;
  emxInit_boolean_T(sp, &b_x, 2, &f_emlrtRTEI, true);
  emxInit_int32_T(sp, &b_ii, 2, &g_emlrtRTEI, true);
  while (i <= (int32_T)dims - 1) {
    st.site = &k_emlrtRSI;
    i1 = b_x->size[0] * b_x->size[1];
    b_x->size[0] = 1;
    b_x->size[1] = x->size[1];
    emxEnsureCapacity(&st, (emxArray__common *)b_x, i1, (int32_T)sizeof
                      (boolean_T), &f_emlrtRTEI);
    ii = x->size[0] * x->size[1];
    for (i1 = 0; i1 < ii; i1++) {
      b_x->data[i1] = (x->data[i1] == 1.0 + (real_T)i);
    }

    b_st.site = &h_emlrtRSI;
    nx = b_x->size[1];
    idx = 0;
    i1 = b_ii->size[0] * b_ii->size[1];
    b_ii->size[0] = 1;
    b_ii->size[1] = b_x->size[1];
    emxEnsureCapacity(&b_st, (emxArray__common *)b_ii, i1, (int32_T)sizeof
                      (int32_T), &f_emlrtRTEI);
    c_st.site = &i_emlrtRSI;
    overflow = ((!(1 > b_x->size[1])) && (b_x->size[1] > 2147483646));
    if (overflow) {
      d_st.site = &j_emlrtRSI;
      check_forloop_overflow_error(&d_st);
    }

    ii = 1;
    exitg1 = false;
    while ((!exitg1) && (ii <= nx)) {
      guard1 = false;
      if (b_x->data[ii - 1]) {
        idx++;
        b_ii->data[idx - 1] = ii;
        if (idx >= nx) {
          exitg1 = true;
        } else {
          guard1 = true;
        }
      } else {
        guard1 = true;
      }

      if (guard1) {
        ii++;
      }
    }

    if (idx <= b_x->size[1]) {
    } else {
      emlrtErrorWithMessageIdR2012b(&b_st, &k_emlrtRTEI,
        "Coder:builtins:AssertionFailed", 0);
    }

    if (b_x->size[1] == 1) {
      if (idx == 0) {
        i1 = b_ii->size[0] * b_ii->size[1];
        b_ii->size[0] = 1;
        b_ii->size[1] = 0;
        emxEnsureCapacity(&b_st, (emxArray__common *)b_ii, i1, (int32_T)sizeof
                          (int32_T), &f_emlrtRTEI);
      }
    } else {
      i1 = b_ii->size[0] * b_ii->size[1];
      if (1 > idx) {
        b_ii->size[1] = 0;
      } else {
        b_ii->size[1] = idx;
      }

      emxEnsureCapacity(&b_st, (emxArray__common *)b_ii, i1, (int32_T)sizeof
                        (int32_T), &b_emlrtRTEI);
    }

    i1 = y->size[1];
    if (!((i + 1 >= 1) && (i + 1 <= i1))) {
      emlrtDynamicBoundsCheckR2012b(i + 1, 1, i1, (emlrtBCInfo *)&w_emlrtBCI, sp);
    }

    y->data[i] = b_ii->size[1];
    i++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_int32_T(&b_ii);
  emxFree_boolean_T(&b_x);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Esempio n. 4
0
/* Function Definitions */
void occflow(const emlrtStack *sp, const emxArray_real_T *cgridvec,
             emxArray_real_T *cgridvecprev, emxArray_real_T *context, const
             emxArray_real_T *nei_idx, const emxArray_real_T *nei_weight, real_T
             nei_filter_n, const emxArray_real_T *nei4u_idx, const
             emxArray_real_T *nei4u_weight, real_T nei4u_filter_n, real_T occval,
             real_T minthreshold, real_T maxthreshold, real_T reinitval, real_T
             intensifyrate, real_T nocc_attenuaterate, real_T
             unknown_attenuaterate, real_T sigm_coef, real_T
             do_attenuation_first, emxArray_real_T *predvec, emxArray_real_T
             *maxvec)
{
  emxArray_boolean_T *x;
  int32_T ix;
  int32_T idx;
  emxArray_boolean_T *r0;
  int32_T nx;
  emxArray_int32_T *ii;
  boolean_T overflow;
  int32_T iy;
  boolean_T exitg6;
  boolean_T guard3 = false;
  boolean_T guard4 = false;
  emxArray_real_T *newlyoccidx;
  boolean_T exitg5;
  boolean_T guard2 = false;
  boolean_T b_guard3 = false;
  emxArray_real_T *occidx;
  boolean_T exitg4;
  boolean_T guard1 = false;
  boolean_T b_guard2 = false;
  emxArray_real_T *noccidx;
  int32_T nrnocc;
  int32_T j;
  emxArray_real_T *curr_col;
  emxArray_real_T *updt_col;
  emxArray_real_T *z;
  int32_T coccidx;
  boolean_T b_guard1 = false;
  int32_T ixstart;
  int32_T n;
  real_T mtmp;
  boolean_T exitg3;
  int32_T varargin_1[2];
  int32_T k;
  int32_T iv3[2];
  int32_T iv4[2];
  real_T d0;
  emxArray_real_T *tempcontext;
  emxArray_real_T *b_nei4u_weight;
  real_T sumval;
  int32_T m;
  int32_T iv5[2];
  boolean_T b_ix;
  boolean_T exitg2;
  boolean_T b_ixstart;
  int32_T varargin_2[2];
  boolean_T p;
  boolean_T exitg1;
  emlrtStack st;
  emlrtStack b_st;
  emlrtStack c_st;
  emlrtStack d_st;
  emlrtStack e_st;
  emlrtStack f_st;
  (void)unknown_attenuaterate;
  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;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_boolean_T(sp, &x, 1, &emlrtRTEI, true);

  /*  */
  /*  Occupancy flow with vector input  */
  /*  */
  /*  Compute indices first  */
  ix = x->size[0];
  x->size[0] = cgridvec->size[0];
  emxEnsureCapacity(sp, (emxArray__common *)x, ix, (int32_T)sizeof(boolean_T),
                    &emlrtRTEI);
  idx = cgridvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    x->data[ix] = (cgridvec->data[ix] == occval);
  }

  emxInit_boolean_T(sp, &r0, 1, &emlrtRTEI, true);
  ix = r0->size[0];
  r0->size[0] = cgridvecprev->size[0];
  emxEnsureCapacity(sp, (emxArray__common *)r0, ix, (int32_T)sizeof(boolean_T),
                    &emlrtRTEI);
  idx = cgridvecprev->size[0];
  for (ix = 0; ix < idx; ix++) {
    r0->data[ix] = (cgridvecprev->data[ix] != occval);
  }

  ix = x->size[0];
  nx = r0->size[0];
  if (ix != nx) {
    emlrtSizeEqCheck1DR2012b(ix, nx, &emlrtECI, sp);
  }

  st.site = &emlrtRSI;
  ix = x->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)x, ix, (int32_T)sizeof(boolean_T),
                    &emlrtRTEI);
  idx = x->size[0];
  for (ix = 0; ix < idx; ix++) {
    x->data[ix] = (x->data[ix] && r0->data[ix]);
  }

  emxFree_boolean_T(&r0);
  emxInit_int32_T(&st, &ii, 1, &l_emlrtRTEI, true);
  b_st.site = &i_emlrtRSI;
  nx = x->size[0];
  idx = 0;
  ix = ii->size[0];
  ii->size[0] = x->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)ii, ix, (int32_T)sizeof(int32_T),
                    &emlrtRTEI);
  c_st.site = &j_emlrtRSI;
  if (1 > x->size[0]) {
    overflow = false;
  } else {
    overflow = (x->size[0] > 2147483646);
  }

  if (overflow) {
    d_st.site = &l_emlrtRSI;
    check_forloop_overflow_error(&d_st);
  }

  iy = 1;
  exitg6 = false;
  while ((!exitg6) && (iy <= nx)) {
    guard3 = false;
    if (x->data[iy - 1]) {
      idx++;
      ii->data[idx - 1] = iy;
      if (idx >= nx) {
        exitg6 = true;
      } else {
        guard3 = true;
      }
    } else {
      guard3 = true;
    }

    if (guard3) {
      iy++;
    }
  }

  if (idx <= x->size[0]) {
  } else {
    emlrtErrorWithMessageIdR2012b(&b_st, &s_emlrtRTEI,
      "Coder:builtins:AssertionFailed", 0);
  }

  if (x->size[0] == 1) {
    if (idx == 0) {
      ix = ii->size[0];
      ii->size[0] = 0;
      emxEnsureCapacity(&b_st, (emxArray__common *)ii, ix, (int32_T)sizeof
                        (int32_T), &emlrtRTEI);
    }
  } else {
    if (1 > idx) {
      ix = 0;
    } else {
      ix = idx;
    }

    c_st.site = &k_emlrtRSI;
    overflow = !(ii->size[0] != 1);
    guard4 = false;
    if (overflow) {
      overflow = false;
      if (ix != 1) {
        overflow = true;
      }

      if (overflow) {
        overflow = true;
      } else {
        guard4 = true;
      }
    } else {
      guard4 = true;
    }

    if (guard4) {
      overflow = false;
    }

    d_st.site = &m_emlrtRSI;
    if (!overflow) {
    } else {
      emlrtErrorWithMessageIdR2012b(&d_st, &t_emlrtRTEI,
        "Coder:FE:PotentialVectorVector", 0);
    }

    nx = ii->size[0];
    ii->size[0] = ix;
    emxEnsureCapacity(&b_st, (emxArray__common *)ii, nx, (int32_T)sizeof(int32_T),
                      &c_emlrtRTEI);
  }

  emxInit_real_T(&b_st, &newlyoccidx, 1, &f_emlrtRTEI, true);
  ix = newlyoccidx->size[0];
  newlyoccidx->size[0] = ii->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)newlyoccidx, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = ii->size[0];
  for (ix = 0; ix < idx; ix++) {
    newlyoccidx->data[ix] = ii->data[ix];
  }

  st.site = &b_emlrtRSI;
  ix = x->size[0];
  x->size[0] = cgridvec->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)x, ix, (int32_T)sizeof(boolean_T),
                    &emlrtRTEI);
  idx = cgridvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    x->data[ix] = (cgridvec->data[ix] == occval);
  }

  b_st.site = &i_emlrtRSI;
  nx = x->size[0];
  idx = 0;
  ix = ii->size[0];
  ii->size[0] = x->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)ii, ix, (int32_T)sizeof(int32_T),
                    &emlrtRTEI);
  c_st.site = &j_emlrtRSI;
  if (1 > x->size[0]) {
    overflow = false;
  } else {
    overflow = (x->size[0] > 2147483646);
  }

  if (overflow) {
    d_st.site = &l_emlrtRSI;
    check_forloop_overflow_error(&d_st);
  }

  iy = 1;
  exitg5 = false;
  while ((!exitg5) && (iy <= nx)) {
    guard2 = false;
    if (x->data[iy - 1]) {
      idx++;
      ii->data[idx - 1] = iy;
      if (idx >= nx) {
        exitg5 = true;
      } else {
        guard2 = true;
      }
    } else {
      guard2 = true;
    }

    if (guard2) {
      iy++;
    }
  }

  if (idx <= x->size[0]) {
  } else {
    emlrtErrorWithMessageIdR2012b(&b_st, &s_emlrtRTEI,
      "Coder:builtins:AssertionFailed", 0);
  }

  if (x->size[0] == 1) {
    if (idx == 0) {
      ix = ii->size[0];
      ii->size[0] = 0;
      emxEnsureCapacity(&b_st, (emxArray__common *)ii, ix, (int32_T)sizeof
                        (int32_T), &emlrtRTEI);
    }
  } else {
    if (1 > idx) {
      ix = 0;
    } else {
      ix = idx;
    }

    c_st.site = &k_emlrtRSI;
    overflow = !(ii->size[0] != 1);
    b_guard3 = false;
    if (overflow) {
      overflow = false;
      if (ix != 1) {
        overflow = true;
      }

      if (overflow) {
        overflow = true;
      } else {
        b_guard3 = true;
      }
    } else {
      b_guard3 = true;
    }

    if (b_guard3) {
      overflow = false;
    }

    d_st.site = &m_emlrtRSI;
    if (!overflow) {
    } else {
      emlrtErrorWithMessageIdR2012b(&d_st, &t_emlrtRTEI,
        "Coder:FE:PotentialVectorVector", 0);
    }

    nx = ii->size[0];
    ii->size[0] = ix;
    emxEnsureCapacity(&b_st, (emxArray__common *)ii, nx, (int32_T)sizeof(int32_T),
                      &c_emlrtRTEI);
  }

  emxInit_real_T(&b_st, &occidx, 1, &g_emlrtRTEI, true);
  ix = occidx->size[0];
  occidx->size[0] = ii->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)occidx, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  idx = ii->size[0];
  for (ix = 0; ix < idx; ix++) {
    occidx->data[ix] = ii->data[ix];
  }

  st.site = &c_emlrtRSI;
  ix = x->size[0];
  x->size[0] = cgridvec->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)x, ix, (int32_T)sizeof(boolean_T),
                    &emlrtRTEI);
  idx = cgridvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    x->data[ix] = (cgridvec->data[ix] != occval);
  }

  b_st.site = &i_emlrtRSI;
  nx = x->size[0];
  idx = 0;
  ix = ii->size[0];
  ii->size[0] = x->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)ii, ix, (int32_T)sizeof(int32_T),
                    &emlrtRTEI);
  c_st.site = &j_emlrtRSI;
  if (1 > x->size[0]) {
    overflow = false;
  } else {
    overflow = (x->size[0] > 2147483646);
  }

  if (overflow) {
    d_st.site = &l_emlrtRSI;
    check_forloop_overflow_error(&d_st);
  }

  iy = 1;
  exitg4 = false;
  while ((!exitg4) && (iy <= nx)) {
    guard1 = false;
    if (x->data[iy - 1]) {
      idx++;
      ii->data[idx - 1] = iy;
      if (idx >= nx) {
        exitg4 = true;
      } else {
        guard1 = true;
      }
    } else {
      guard1 = true;
    }

    if (guard1) {
      iy++;
    }
  }

  if (idx <= x->size[0]) {
  } else {
    emlrtErrorWithMessageIdR2012b(&b_st, &s_emlrtRTEI,
      "Coder:builtins:AssertionFailed", 0);
  }

  if (x->size[0] == 1) {
    if (idx == 0) {
      ix = ii->size[0];
      ii->size[0] = 0;
      emxEnsureCapacity(&b_st, (emxArray__common *)ii, ix, (int32_T)sizeof
                        (int32_T), &emlrtRTEI);
    }
  } else {
    if (1 > idx) {
      ix = 0;
    } else {
      ix = idx;
    }

    c_st.site = &k_emlrtRSI;
    overflow = !(ii->size[0] != 1);
    b_guard2 = false;
    if (overflow) {
      overflow = false;
      if (ix != 1) {
        overflow = true;
      }

      if (overflow) {
        overflow = true;
      } else {
        b_guard2 = true;
      }
    } else {
      b_guard2 = true;
    }

    if (b_guard2) {
      overflow = false;
    }

    d_st.site = &m_emlrtRSI;
    if (!overflow) {
    } else {
      emlrtErrorWithMessageIdR2012b(&d_st, &t_emlrtRTEI,
        "Coder:FE:PotentialVectorVector", 0);
    }

    nx = ii->size[0];
    ii->size[0] = ix;
    emxEnsureCapacity(&b_st, (emxArray__common *)ii, nx, (int32_T)sizeof(int32_T),
                      &c_emlrtRTEI);
  }

  emxFree_boolean_T(&x);
  emxInit_real_T(&b_st, &noccidx, 1, &h_emlrtRTEI, true);
  ix = noccidx->size[0];
  noccidx->size[0] = ii->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)noccidx, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  idx = ii->size[0];
  for (ix = 0; ix < idx; ix++) {
    noccidx->data[ix] = ii->data[ix];
  }

  nrnocc = noccidx->size[0] - 1;

  /*  1 Intensify newly occupied cells  */
  j = 0;
  emxInit_real_T1(sp, &curr_col, 2, &i_emlrtRTEI, true);
  emxInit_real_T1(sp, &updt_col, 2, &j_emlrtRTEI, true);
  emxInit_real_T1(sp, &z, 2, &emlrtRTEI, true);
  while (j <= newlyoccidx->size[0] - 1) {
    /*  For newly occupied cells  */
    ix = newlyoccidx->size[0];
    if (!((j + 1 >= 1) && (j + 1 <= ix))) {
      emlrtDynamicBoundsCheckR2012b(j + 1, 1, ix, &eb_emlrtBCI, sp);
    }

    coccidx = (int32_T)newlyoccidx->data[j] - 1;
    ix = context->size[0];
    nx = (int32_T)newlyoccidx->data[j];
    if (!((nx >= 1) && (nx <= ix))) {
      emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &emlrtBCI, sp);
    }

    st.site = &d_emlrtRSI;
    b_st.site = &n_emlrtRSI;
    c_st.site = &o_emlrtRSI;
    ix = context->size[1];
    b_guard1 = false;
    if (ix == 1) {
      b_guard1 = true;
    } else {
      ix = context->size[1];
      if (ix != 1) {
        b_guard1 = true;
      } else {
        overflow = false;
      }
    }

    if (b_guard1) {
      overflow = true;
    }

    if (overflow) {
    } else {
      emlrtErrorWithMessageIdR2012b(&c_st, &u_emlrtRTEI,
        "Coder:toolbox:autoDimIncompatibility", 0);
    }

    ix = context->size[1];
    if (ix > 0) {
    } else {
      emlrtErrorWithMessageIdR2012b(&c_st, &v_emlrtRTEI,
        "Coder:toolbox:eml_min_or_max_varDimZero", 0);
    }

    d_st.site = &p_emlrtRSI;
    ixstart = 1;
    n = context->size[1];
    nx = (int32_T)newlyoccidx->data[j];
    mtmp = context->data[nx - 1];
    ix = context->size[1];
    if (ix > 1) {
      if (muDoubleScalarIsNaN(mtmp)) {
        e_st.site = &r_emlrtRSI;
        ix = context->size[1];
        if (2 > ix) {
          overflow = false;
        } else {
          ix = context->size[1];
          overflow = (ix > 2147483646);
        }

        if (overflow) {
          f_st.site = &l_emlrtRSI;
          check_forloop_overflow_error(&f_st);
        }

        ix = 2;
        exitg3 = false;
        while ((!exitg3) && (ix <= n)) {
          ixstart = ix;
          if (!muDoubleScalarIsNaN(context->data[coccidx + context->size[0] *
               (ix - 1)])) {
            mtmp = context->data[coccidx + context->size[0] * (ix - 1)];
            exitg3 = true;
          } else {
            ix++;
          }
        }
      }

      ix = context->size[1];
      if (ixstart < ix) {
        e_st.site = &q_emlrtRSI;
        ix = context->size[1];
        if (ixstart + 1 > ix) {
          overflow = false;
        } else {
          ix = context->size[1];
          overflow = (ix > 2147483646);
        }

        if (overflow) {
          f_st.site = &l_emlrtRSI;
          check_forloop_overflow_error(&f_st);
        }

        for (ix = ixstart + 1; ix <= n; ix++) {
          if (context->data[coccidx + context->size[0] * (ix - 1)] > mtmp) {
            mtmp = context->data[coccidx + context->size[0] * (ix - 1)];
          }
        }
      }
    }

    if (mtmp < minthreshold) {
      idx = context->size[1];
      iy = context->size[0];
      nx = (int32_T)newlyoccidx->data[j];
      if (!((nx >= 1) && (nx <= iy))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, iy, &b_emlrtBCI, sp);
      }

      for (ix = 0; ix < idx; ix++) {
        context->data[(nx + context->size[0] * ix) - 1] = reinitval;
      }

      /*  Reinitialize */
    } else {
      idx = context->size[1];
      nx = (int32_T)newlyoccidx->data[j];
      ix = updt_col->size[0] * updt_col->size[1];
      updt_col->size[0] = 1;
      updt_col->size[1] = idx;
      emxEnsureCapacity(sp, (emxArray__common *)updt_col, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < idx; ix++) {
        updt_col->data[updt_col->size[0] * ix] = intensifyrate * context->data
          [(nx + context->size[0] * ix) - 1];
      }

      /*  Intensify */
      st.site = &e_emlrtRSI;
      b_st.site = &s_emlrtRSI;
      c_st.site = &o_emlrtRSI;
      d_st.site = &t_emlrtRSI;
      ix = curr_col->size[0] * curr_col->size[1];
      curr_col->size[0] = 1;
      curr_col->size[1] = updt_col->size[1];
      emxEnsureCapacity(&d_st, (emxArray__common *)curr_col, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      idx = updt_col->size[0] * updt_col->size[1];
      for (ix = 0; ix < idx; ix++) {
        curr_col->data[ix] = updt_col->data[ix];
      }

      e_st.site = &u_emlrtRSI;
      for (ix = 0; ix < 2; ix++) {
        varargin_1[ix] = updt_col->size[ix];
      }

      ix = z->size[0] * z->size[1];
      z->size[0] = 1;
      z->size[1] = updt_col->size[1];
      emxEnsureCapacity(&e_st, (emxArray__common *)z, ix, (int32_T)sizeof(real_T),
                        &d_emlrtRTEI);
      iy = updt_col->size[1];
      ix = updt_col->size[0] * updt_col->size[1];
      updt_col->size[0] = 1;
      updt_col->size[1] = varargin_1[1];
      emxEnsureCapacity(&e_st, (emxArray__common *)updt_col, ix, (int32_T)sizeof
                        (real_T), &e_emlrtRTEI);
      if (dimagree(updt_col, curr_col)) {
      } else {
        emlrtErrorWithMessageIdR2012b(&e_st, &x_emlrtRTEI, "MATLAB:dimagree", 0);
      }

      e_st.site = &v_emlrtRSI;
      if (1 > z->size[1]) {
        overflow = false;
      } else {
        overflow = (z->size[1] > 2147483646);
      }

      if (overflow) {
        f_st.site = &l_emlrtRSI;
        check_forloop_overflow_error(&f_st);
      }

      for (k = 0; k + 1 <= iy; k++) {
        updt_col->data[k] = muDoubleScalarMin(curr_col->data[k], maxthreshold);
      }

      /*  Max-thesholding */
      ix = context->size[0];
      nx = (int32_T)newlyoccidx->data[j];
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &c_emlrtBCI, sp);
      }

      idx = context->size[1];
      ix = ii->size[0];
      ii->size[0] = idx;
      emxEnsureCapacity(sp, (emxArray__common *)ii, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < idx; ix++) {
        ii->data[ix] = ix;
      }

      iv3[0] = 1;
      iv3[1] = ii->size[0];
      emlrtSubAssignSizeCheckR2012b(iv3, 2, *(int32_T (*)[2])updt_col->size, 2,
        &b_emlrtECI, sp);
      nx = (int32_T)newlyoccidx->data[j];
      idx = updt_col->size[1];
      for (ix = 0; ix < idx; ix++) {
        context->data[(nx + context->size[0] * ii->data[ix]) - 1] =
          updt_col->data[updt_col->size[0] * ix];
      }
    }

    j++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_real_T(&z);

  /*  2 Attenuate unoccupied cells */
  if (do_attenuation_first == 1.0) {
    j = 0;
    while (j <= nrnocc) {
      /*  For unoccupied cells */
      ix = noccidx->size[0];
      nx = j + 1;
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &d_emlrtBCI, sp);
      }

      ix = context->size[0];
      nx = (int32_T)noccidx->data[j];
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &e_emlrtBCI, sp);
      }

      idx = context->size[1];
      iy = (int32_T)noccidx->data[j];
      ix = updt_col->size[0] * updt_col->size[1];
      updt_col->size[0] = 1;
      updt_col->size[1] = idx;
      emxEnsureCapacity(sp, (emxArray__common *)updt_col, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < idx; ix++) {
        updt_col->data[updt_col->size[0] * ix] = context->data[(iy +
          context->size[0] * ix) - 1] * nocc_attenuaterate;
      }

      /*  Attenuate */
      ix = context->size[0];
      nx = (int32_T)noccidx->data[j];
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &f_emlrtBCI, sp);
      }

      idx = context->size[1];
      ix = ii->size[0];
      ii->size[0] = idx;
      emxEnsureCapacity(sp, (emxArray__common *)ii, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < idx; ix++) {
        ii->data[ix] = ix;
      }

      iv4[0] = 1;
      iv4[1] = ii->size[0];
      emlrtSubAssignSizeCheckR2012b(iv4, 2, *(int32_T (*)[2])updt_col->size, 2,
        &c_emlrtECI, sp);
      iy = (int32_T)noccidx->data[j];
      idx = updt_col->size[1];
      for (ix = 0; ix < idx; ix++) {
        context->data[(iy + context->size[0] * ii->data[ix]) - 1] =
          updt_col->data[updt_col->size[0] * ix];
      }

      j++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }
  }

  /*  4 Propagation  */
  j = 0;
  while (j <= occidx->size[0] - 1) {
    /*  For occupied cells  */
    ix = occidx->size[0];
    if (!((j + 1 >= 1) && (j + 1 <= ix))) {
      emlrtDynamicBoundsCheckR2012b(j + 1, 1, ix, &bb_emlrtBCI, sp);
    }

    idx = context->size[1];
    ix = context->size[0];
    iy = (int32_T)occidx->data[j];
    if (!((iy >= 1) && (iy <= ix))) {
      emlrtDynamicBoundsCheckR2012b(iy, 1, ix, &g_emlrtBCI, sp);
    }

    ix = curr_col->size[0] * curr_col->size[1];
    curr_col->size[0] = 1;
    curr_col->size[1] = idx;
    emxEnsureCapacity(sp, (emxArray__common *)curr_col, ix, (int32_T)sizeof
                      (real_T), &emlrtRTEI);
    for (ix = 0; ix < idx; ix++) {
      curr_col->data[curr_col->size[0] * ix] = context->data[(iy + context->
        size[0] * ix) - 1];
    }

    ix = nei_idx->size[0];
    nx = (int32_T)occidx->data[j];
    if (!((nx >= 1) && (nx <= ix))) {
      emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &h_emlrtBCI, sp);
    }

    ix = nei_weight->size[0];
    nx = (int32_T)occidx->data[j];
    if (!((nx >= 1) && (nx <= ix))) {
      emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &i_emlrtBCI, sp);
    }

    emlrtForLoopVectorCheckR2012b(1.0, 1.0, nei_filter_n, mxDOUBLE_CLASS,
      (int32_T)nei_filter_n, &p_emlrtRTEI, sp);
    k = 0;
    while (k <= (int32_T)nei_filter_n - 1) {
      /*  For all neighbor cells  */
      ix = curr_col->size[1];
      nx = k + 1;
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &j_emlrtBCI, sp);
      }

      ix = nei_idx->size[1];
      nx = k + 1;
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &k_emlrtBCI, sp);
      }

      ix = nei_weight->size[1];
      nx = k + 1;
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &l_emlrtBCI, sp);
      }

      iy = (int32_T)occidx->data[j];
      if (nei_idx->data[(iy + nei_idx->size[0] * k) - 1] != 0.0) {
        /*  If properly connected, propagate */
        iy = (int32_T)occidx->data[j];
        d0 = nei_idx->data[(iy + nei_idx->size[0] * k) - 1];
        if (d0 != (int32_T)muDoubleScalarFloor(d0)) {
          emlrtIntegerCheckR2012b(d0, &emlrtDCI, sp);
        }

        ix = context->size[0];
        nx = (int32_T)d0;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &m_emlrtBCI, sp);
        }

        ix = context->size[1];
        nx = k + 1;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &n_emlrtBCI, sp);
        }

        /*  Maximum value thresholding  */
        iy = (int32_T)occidx->data[j];
        idx = (int32_T)occidx->data[j];
        nx = (int32_T)occidx->data[j];
        ix = context->size[0];
        nx = (int32_T)nei_idx->data[(nx + nei_idx->size[0] * k) - 1];
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &cb_emlrtBCI, sp);
        }

        ix = context->size[1];
        if (!((k + 1 >= 1) && (k + 1 <= ix))) {
          emlrtDynamicBoundsCheckR2012b(k + 1, 1, ix, &db_emlrtBCI, sp);
        }

        context->data[(nx + context->size[0] * k) - 1] = muDoubleScalarMax
          (context->data[((int32_T)nei_idx->data[(iy + nei_idx->size[0] * k) - 1]
                          + context->size[0] * k) - 1], muDoubleScalarMin
           (nei_weight->data[(idx + nei_weight->size[0] * k) - 1] *
            curr_col->data[k], maxthreshold));

        /*  Make sure current context propagation does not weaken the flow information */
      }

      k++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }

    j++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_real_T(&occidx);
  emxInit_real_T1(sp, &tempcontext, 2, &k_emlrtRTEI, true);

  /*  5 Uncertainty in acceleration */
  ix = tempcontext->size[0] * tempcontext->size[1];
  tempcontext->size[0] = context->size[0];
  tempcontext->size[1] = context->size[1];
  emxEnsureCapacity(sp, (emxArray__common *)tempcontext, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = context->size[0] * context->size[1];
  for (ix = 0; ix < idx; ix++) {
    tempcontext->data[ix] = context->data[ix];
  }

  emlrtForLoopVectorCheckR2012b(1.0, 1.0, nei_filter_n, mxDOUBLE_CLASS, (int32_T)
    nei_filter_n, &q_emlrtRTEI, sp);
  j = 0;
  emxInit_real_T1(sp, &b_nei4u_weight, 2, &emlrtRTEI, true);
  while (j <= (int32_T)nei_filter_n - 1) {
    /*  For all context level */
    k = 0;
    while (k <= nei_idx->size[0] - 1) {
      /*  For all cells */
      sumval = 0.0;
      emlrtForLoopVectorCheckR2012b(1.0, 1.0, nei4u_filter_n, mxDOUBLE_CLASS,
        (int32_T)nei4u_filter_n, &r_emlrtRTEI, sp);
      m = 0;
      while (m <= (int32_T)nei4u_filter_n - 1) {
        ix = nei4u_idx->size[0];
        nx = k + 1;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &o_emlrtBCI, sp);
        }

        ix = nei4u_idx->size[1];
        nx = m + 1;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &p_emlrtBCI, sp);
        }

        ix = nei4u_weight->size[0];
        nx = k + 1;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &q_emlrtBCI, sp);
        }

        ix = nei4u_weight->size[1];
        nx = m + 1;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &r_emlrtBCI, sp);
        }

        idx = nei4u_weight->size[1];
        ix = nei4u_weight->size[0];
        nx = 1 + k;
        if (!((nx >= 1) && (nx <= ix))) {
          emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &s_emlrtBCI, sp);
        }

        ix = b_nei4u_weight->size[0] * b_nei4u_weight->size[1];
        b_nei4u_weight->size[0] = 1;
        b_nei4u_weight->size[1] = idx;
        emxEnsureCapacity(sp, (emxArray__common *)b_nei4u_weight, ix, (int32_T)
                          sizeof(real_T), &emlrtRTEI);
        for (ix = 0; ix < idx; ix++) {
          b_nei4u_weight->data[b_nei4u_weight->size[0] * ix] =
            nei4u_weight->data[(nx + nei4u_weight->size[0] * ix) - 1];
        }

        st.site = &f_emlrtRSI;
        mtmp = sum(&st, b_nei4u_weight);
        if (nei4u_idx->data[k + nei4u_idx->size[0] * m] != 0.0) {
          d0 = nei4u_idx->data[k + nei4u_idx->size[0] * m];
          if (d0 != (int32_T)muDoubleScalarFloor(d0)) {
            emlrtIntegerCheckR2012b(d0, &b_emlrtDCI, sp);
          }

          ix = context->size[0];
          nx = (int32_T)d0;
          if (!((nx >= 1) && (nx <= ix))) {
            emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &t_emlrtBCI, sp);
          }

          ix = context->size[1];
          nx = j + 1;
          if (!((nx >= 1) && (nx <= ix))) {
            emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &u_emlrtBCI, sp);
          }

          sumval += nei4u_weight->data[k + nei4u_weight->size[0] * m] / mtmp *
            context->data[((int32_T)nei4u_idx->data[k + nei4u_idx->size[0] * m]
                           + context->size[0] * j) - 1];
        }

        m++;
        if (*emlrtBreakCheckR2012bFlagVar != 0) {
          emlrtBreakCheckR2012b(sp);
        }
      }

      ix = tempcontext->size[0];
      nx = 1 + k;
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &y_emlrtBCI, sp);
      }

      ix = tempcontext->size[1];
      if (!((j + 1 >= 1) && (j + 1 <= ix))) {
        emlrtDynamicBoundsCheckR2012b(j + 1, 1, ix, &ab_emlrtBCI, sp);
      }

      tempcontext->data[(nx + tempcontext->size[0] * j) - 1] = sumval;
      k++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }

    j++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_real_T(&b_nei4u_weight);
  ix = context->size[0] * context->size[1];
  context->size[0] = tempcontext->size[0];
  context->size[1] = tempcontext->size[1];
  emxEnsureCapacity(sp, (emxArray__common *)context, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  idx = tempcontext->size[1];
  for (ix = 0; ix < idx; ix++) {
    iy = tempcontext->size[0];
    for (nx = 0; nx < iy; nx++) {
      context->data[nx + context->size[0] * ix] = tempcontext->data[nx +
        tempcontext->size[0] * ix];
    }
  }

  if (do_attenuation_first == 0.0) {
    /*  2 Attenuate unoccupied cells */
    j = 0;
    while (j <= nrnocc) {
      /*  For unoccupied cells, attenuate */
      ix = noccidx->size[0];
      nx = j + 1;
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &v_emlrtBCI, sp);
      }

      ix = context->size[0];
      nx = (int32_T)noccidx->data[j];
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &w_emlrtBCI, sp);
      }

      idx = context->size[1];
      iy = (int32_T)noccidx->data[j];
      ix = updt_col->size[0] * updt_col->size[1];
      updt_col->size[0] = 1;
      updt_col->size[1] = idx;
      emxEnsureCapacity(sp, (emxArray__common *)updt_col, ix, (int32_T)sizeof
                        (real_T), &emlrtRTEI);
      for (ix = 0; ix < idx; ix++) {
        updt_col->data[updt_col->size[0] * ix] = context->data[(iy +
          context->size[0] * ix) - 1] * nocc_attenuaterate;
      }

      ix = context->size[0];
      nx = (int32_T)noccidx->data[j];
      if (!((nx >= 1) && (nx <= ix))) {
        emlrtDynamicBoundsCheckR2012b(nx, 1, ix, &x_emlrtBCI, sp);
      }

      idx = context->size[1];
      ix = ii->size[0];
      ii->size[0] = idx;
      emxEnsureCapacity(sp, (emxArray__common *)ii, ix, (int32_T)sizeof(int32_T),
                        &emlrtRTEI);
      for (ix = 0; ix < idx; ix++) {
        ii->data[ix] = ix;
      }

      iv5[0] = 1;
      iv5[1] = ii->size[0];
      emlrtSubAssignSizeCheckR2012b(iv5, 2, *(int32_T (*)[2])updt_col->size, 2,
        &d_emlrtECI, sp);
      iy = (int32_T)noccidx->data[j];
      idx = updt_col->size[1];
      for (ix = 0; ix < idx; ix++) {
        context->data[(iy + context->size[0] * ii->data[ix]) - 1] =
          updt_col->data[updt_col->size[0] * ix];
      }

      j++;
      if (*emlrtBreakCheckR2012bFlagVar != 0) {
        emlrtBreakCheckR2012b(sp);
      }
    }
  }

  emxFree_int32_T(&ii);
  emxFree_real_T(&updt_col);
  emxFree_real_T(&noccidx);

  /*  6 Prediction */
  st.site = &g_emlrtRSI;
  ix = tempcontext->size[0] * tempcontext->size[1];
  tempcontext->size[0] = context->size[1];
  tempcontext->size[1] = context->size[0];
  emxEnsureCapacity(&st, (emxArray__common *)tempcontext, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = context->size[0];
  for (ix = 0; ix < idx; ix++) {
    iy = context->size[1];
    for (nx = 0; nx < iy; nx++) {
      tempcontext->data[nx + tempcontext->size[0] * ix] = context->data[ix +
        context->size[0] * nx];
    }
  }

  b_st.site = &n_emlrtRSI;
  c_st.site = &o_emlrtRSI;
  if (((tempcontext->size[0] == 1) && (tempcontext->size[1] == 1)) ||
      (tempcontext->size[0] != 1)) {
    overflow = true;
  } else {
    overflow = false;
  }

  if (overflow) {
  } else {
    emlrtErrorWithMessageIdR2012b(&c_st, &u_emlrtRTEI,
      "Coder:toolbox:autoDimIncompatibility", 0);
  }

  if (tempcontext->size[0] > 0) {
  } else {
    emlrtErrorWithMessageIdR2012b(&c_st, &v_emlrtRTEI,
      "Coder:toolbox:eml_min_or_max_varDimZero", 0);
  }

  ix = curr_col->size[0] * curr_col->size[1];
  curr_col->size[0] = 1;
  curr_col->size[1] = tempcontext->size[1];
  emxEnsureCapacity(&c_st, (emxArray__common *)curr_col, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  n = tempcontext->size[0];
  ix = 0;
  iy = -1;
  d_st.site = &ab_emlrtRSI;
  if (1 > tempcontext->size[1]) {
    overflow = false;
  } else {
    overflow = (tempcontext->size[1] > 2147483646);
  }

  if (overflow) {
    e_st.site = &l_emlrtRSI;
    check_forloop_overflow_error(&e_st);
  }

  for (nx = 1; nx <= tempcontext->size[1]; nx++) {
    d_st.site = &bb_emlrtRSI;
    ixstart = ix;
    idx = ix + n;
    mtmp = tempcontext->data[ix];
    if (n > 1) {
      if (muDoubleScalarIsNaN(tempcontext->data[ix])) {
        e_st.site = &r_emlrtRSI;
        if (ix + 2 > idx) {
          b_ix = false;
        } else {
          b_ix = (idx > 2147483646);
        }

        if (b_ix) {
          f_st.site = &l_emlrtRSI;
          check_forloop_overflow_error(&f_st);
        }

        k = ix + 1;
        exitg2 = false;
        while ((!exitg2) && (k + 1 <= idx)) {
          ixstart = k;
          if (!muDoubleScalarIsNaN(tempcontext->data[k])) {
            mtmp = tempcontext->data[k];
            exitg2 = true;
          } else {
            k++;
          }
        }
      }

      if (ixstart + 1 < idx) {
        e_st.site = &q_emlrtRSI;
        if (ixstart + 2 > idx) {
          b_ixstart = false;
        } else {
          b_ixstart = (idx > 2147483646);
        }

        if (b_ixstart) {
          f_st.site = &l_emlrtRSI;
          check_forloop_overflow_error(&f_st);
        }

        for (k = ixstart + 1; k + 1 <= idx; k++) {
          if (tempcontext->data[k] > mtmp) {
            mtmp = tempcontext->data[k];
          }
        }
      }
    }

    iy++;
    curr_col->data[iy] = mtmp;
    ix += n;
  }

  emxFree_real_T(&tempcontext);
  ix = maxvec->size[0];
  maxvec->size[0] = curr_col->size[1];
  emxEnsureCapacity(sp, (emxArray__common *)maxvec, ix, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  idx = curr_col->size[1];
  for (ix = 0; ix < idx; ix++) {
    maxvec->data[ix] = curr_col->data[curr_col->size[0] * ix];
  }

  emxFree_real_T(&curr_col);
  st.site = &h_emlrtRSI;

  /*  sigm_a  <= if we increase the value, than the sigm function gets peaky! */
  b_st.site = &cb_emlrtRSI;
  ix = predvec->size[0];
  predvec->size[0] = maxvec->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)predvec, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = maxvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    predvec->data[ix] = -sigm_coef * maxvec->data[ix];
  }

  c_st.site = &cb_emlrtRSI;
  b_exp(&c_st, predvec);
  ix = predvec->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)predvec, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = predvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    predvec->data[ix] = 1.0 - predvec->data[ix];
  }

  ix = newlyoccidx->size[0];
  newlyoccidx->size[0] = maxvec->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)newlyoccidx, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = maxvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    newlyoccidx->data[ix] = -sigm_coef * maxvec->data[ix];
  }

  c_st.site = &cb_emlrtRSI;
  b_exp(&c_st, newlyoccidx);
  ix = newlyoccidx->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)newlyoccidx, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = newlyoccidx->size[0];
  for (ix = 0; ix < idx; ix++) {
    newlyoccidx->data[ix]++;
  }

  varargin_1[0] = predvec->size[0];
  varargin_1[1] = 1;
  varargin_2[0] = newlyoccidx->size[0];
  varargin_2[1] = 1;
  overflow = false;
  p = true;
  k = 0;
  exitg1 = false;
  while ((!exitg1) && (k < 2)) {
    if (!(varargin_1[k] == varargin_2[k])) {
      p = false;
      exitg1 = true;
    } else {
      k++;
    }
  }

  if (!p) {
  } else {
    overflow = true;
  }

  if (overflow) {
  } else {
    emlrtErrorWithMessageIdR2012b(&b_st, &w_emlrtRTEI, "MATLAB:dimagree", 0);
  }

  ix = predvec->size[0];
  emxEnsureCapacity(&b_st, (emxArray__common *)predvec, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = predvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    predvec->data[ix] /= newlyoccidx->data[ix];
  }

  emxFree_real_T(&newlyoccidx);

  /*  7 Save previous grid */
  ix = cgridvecprev->size[0];
  cgridvecprev->size[0] = cgridvec->size[0];
  emxEnsureCapacity(sp, (emxArray__common *)cgridvecprev, ix, (int32_T)sizeof
                    (real_T), &emlrtRTEI);
  idx = cgridvec->size[0];
  for (ix = 0; ix < idx; ix++) {
    cgridvecprev->data[ix] = cgridvec->data[ix];
  }

  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Esempio n. 5
0
/* Function Definitions */
void features_bta(const emxArray_real_T *tap, double ft[2])
{
  int i12;
  emxArray_real_T *t;
  int loop_ub;
  double tapdt;
  emxArray_real_T *tapx;
  emxArray_real_T *dx;
  emxArray_boolean_T *i;
  emxArray_int32_T *r12;
  double tapiqr;

  /*  Computes basic tapping test features. */
  /*  Inputs: */
  /*   tap - tapping data vector: tap(:,1) - time points, */
  /*         tap(:,2:3) - X,Y touch screen coordinates */
  /*  */
  /*  (CC BY-SA 3.0) Max Little, 2014 */
  /*  Output feature vector */
  for (i12 = 0; i12 < 2; i12++) {
    ft[i12] = rtNaN;
  }

  /*  Ignore zero-length inputs */
  if (tap->size[0] == 0) {
  } else {
    b_emxInit_real_T(&t, 1);

    /*  Calculate relative time */
    loop_ub = tap->size[0];
    tapdt = tap->data[0];
    i12 = t->size[0];
    t->size[0] = loop_ub;
    emxEnsureCapacity((emxArray__common *)t, i12, (int)sizeof(double));
    for (i12 = 0; i12 < loop_ub; i12++) {
      t->data[i12] = tap->data[i12] - tapdt;
    }

    b_emxInit_real_T(&tapx, 1);

    /*  X,Y offset */
    loop_ub = tap->size[0];
    i12 = tapx->size[0];
    tapx->size[0] = loop_ub;
    emxEnsureCapacity((emxArray__common *)tapx, i12, (int)sizeof(double));
    for (i12 = 0; i12 < loop_ub; i12++) {
      tapx->data[i12] = tap->data[i12 + tap->size[0]];
    }

    tapdt = mean(tapx);
    i12 = tapx->size[0];
    emxEnsureCapacity((emxArray__common *)tapx, i12, (int)sizeof(double));
    loop_ub = tapx->size[0];
    for (i12 = 0; i12 < loop_ub; i12++) {
      tapx->data[i12] -= tapdt;
    }

    b_emxInit_real_T(&dx, 1);
    emxInit_boolean_T(&i, 1);

    /*  Find left/right finger 'depress' events */
    diff(tapx, dx);
    b_abs(dx, tapx);
    i12 = i->size[0];
    i->size[0] = tapx->size[0];
    emxEnsureCapacity((emxArray__common *)i, i12, (int)sizeof(boolean_T));
    loop_ub = tapx->size[0];
    for (i12 = 0; i12 < loop_ub; i12++) {
      i->data[i12] = (tapx->data[i12] > 20.0);
    }

    emxInit_int32_T(&r12, 1);
    eml_li_find(i, r12);
    i12 = dx->size[0];
    dx->size[0] = r12->size[0];
    emxEnsureCapacity((emxArray__common *)dx, i12, (int)sizeof(double));
    loop_ub = r12->size[0];
    emxFree_boolean_T(&i);
    for (i12 = 0; i12 < loop_ub; i12++) {
      dx->data[i12] = t->data[r12->data[i12] - 1];
    }

    emxFree_int32_T(&r12);
    emxFree_real_T(&t);

    /*  Find depress event intervals */
    diff(dx, tapx);

    /*  Median and spread of tapping rate */
    emxFree_real_T(&dx);
    if (tapx->size[0] == 0) {
      tapdt = rtNaN;
    } else {
      tapdt = vectormedian(tapx);
    }

    tapiqr = iqr(tapx);

    /*  Output tapping test feature vector */
    ft[0] = tapdt;
    ft[1] = tapiqr;
    emxFree_real_T(&tapx);
  }
}
Esempio n. 6
0
/* Function Definitions */
real_T is_match_multi_points(const real_T mono[44100], real_T Fs, const real_T
  keys[20], real_T threshold)
{
  real_T hits;
  static creal_T Y[16384];
  int32_T i0;
  real_T y;
  real_T Y_im;
  static real_T f[8193];
  int32_T k;
  int32_T idx;
  int8_T ii_data[20];
  int32_T ii;
  boolean_T exitg3;
  boolean_T guard2 = FALSE;
  int8_T b_ii_data[20];
  int32_T key_start;
  int8_T key_points_data[20];
  int32_T i;
  emxArray_real_T *key_hits;
  emxArray_real_T *possible_matches;
  emxArray_boolean_T *x;
  int32_T i1;
  int32_T j;
  boolean_T bv0[8193];
  boolean_T bv1[8193];
  int32_T b_idx;
  int16_T c_ii_data[8193];
  int16_T ii_size[2];
  boolean_T exitg2;
  boolean_T guard1 = FALSE;
  int32_T tmp_data[8193];
  int16_T d_ii_data[8193];
  boolean_T exitg1;

  /* some comments are required here */
  /*  mono      - the single mono track audio */
  /*  Fs        - the sampling rate of the track */
  /*  keys      - a simple integer data structure representing keys. Format is */
  /*  as follows:  */
  /*    */
  /*  [f1,f2,f3, 0, g1,g2,g3, -1.....] -- where f and g are different keys */
  /*   */
  /*  Note that the number of points must be symetric.  */
  /*  */
  /*  threshold - the minimum spectral density of a match */
  /*  2^nextpow2(length(mono)); % */
  fft(mono, Y);
  for (i0 = 0; i0 < 16384; i0++) {
    y = Y[i0].re * Y[i0].re - Y[i0].im * -Y[i0].im;
    Y_im = Y[i0].re * -Y[i0].im + Y[i0].im * Y[i0].re;
    if (Y_im == 0.0) {
      Y[i0].re = y / 16384.0;
      Y[i0].im = 0.0;
    } else if (y == 0.0) {
      Y[i0].re = 0.0;
      Y[i0].im = Y_im / 16384.0;
    } else {
      Y[i0].re = y / 16384.0;
      Y[i0].im = Y_im / 16384.0;
    }
  }

  y = Fs / 2.0;
  f[8192] = 1.0;
  f[0] = 0.0;
  for (k = 0; k < 8191; k++) {
    f[1 + k] = (1.0 + (real_T)k) * 0.0001220703125;
  }

  for (i0 = 0; i0 < 8193; i0++) {
    f[i0] *= y;
  }

  idx = 0;
  ii = 1;
  exitg3 = FALSE;
  while ((exitg3 == 0U) && (ii < 21)) {
    guard2 = FALSE;
    if (keys[ii - 1] == 0.0) {
      idx++;
      ii_data[idx - 1] = (int8_T)ii;
      if (idx >= 20) {
        exitg3 = TRUE;
      } else {
        guard2 = TRUE;
      }
    } else {
      guard2 = TRUE;
    }

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

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

  key_start = idx - 1;
  for (i0 = 0; i0 <= key_start; i0++) {
    b_ii_data[i0] = ii_data[i0];
  }

  key_start = idx - 1;
  for (i0 = 0; i0 <= key_start; i0++) {
    ii_data[i0] = b_ii_data[i0];
  }

  key_start = idx - 1;
  for (i0 = 0; i0 <= key_start; i0++) {
    key_points_data[i0] = ii_data[i0];
  }

  key_start = 1;
  hits = 0.0;

  /*  for each key, loop through and extract this key. */
  i = 0;
  emxInit_real_T(&key_hits, 2);
  emxInit_real_T(&possible_matches, 2);
  emxInit_boolean_T(&x, 2);
  while (i <= idx - 1) {
    /*  extract the key */
    if (key_start > key_points_data[i] - 1) {
      i0 = 0;
      i1 = 1;
    } else {
      i0 = key_start - 1;
      i1 = key_points_data[i];
    }

    k = key_hits->size[0] * key_hits->size[1];
    key_hits->size[0] = 1;
    emxEnsureCapacity((emxArray__common *)key_hits, k, (int32_T)sizeof(real_T));
    k = key_hits->size[0] * key_hits->size[1];
    key_hits->size[1] = (i1 - i0) - 1;
    emxEnsureCapacity((emxArray__common *)key_hits, k, (int32_T)sizeof(real_T));
    key_start = (i1 - i0) - 1;
    key_start--;
    for (k = 0; k <= key_start; k++) {
      key_hits->data[k] = 0.0;
    }

    /*  for each key, find matches. */
    for (j = 0; j <= (i1 - i0) - 2; j++) {
      /*  fprintf('Looking at Key: %d\n', key(j)); */
      for (k = 0; k < 8193; k++) {
        bv0[k] = (f[k] >= keys[i0 + j] - 100.0);
        bv1[k] = (f[k] <= keys[i0 + j] + 100.0);
      }

      b_idx = 0;
      for (k = 0; k < 2; k++) {
        ii_size[k] = (int16_T)(1 + (k << 13));
      }

      ii = 1;
      exitg2 = FALSE;
      while ((exitg2 == 0U) && (ii < 8194)) {
        guard1 = FALSE;
        if (bv0[ii - 1] && bv1[ii - 1]) {
          b_idx++;
          c_ii_data[b_idx - 1] = (int16_T)ii;
          if (b_idx >= 8193) {
            exitg2 = TRUE;
          } else {
            guard1 = TRUE;
          }
        } else {
          guard1 = TRUE;
        }

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

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

      key_start = b_idx - 1;
      for (k = 0; k <= key_start; k++) {
        tmp_data[k] = 1 + k;
      }

      key_start = b_idx - 1;
      for (k = 0; k <= key_start; k++) {
        ii = 0;
        while (ii <= 0) {
          d_ii_data[k] = c_ii_data[tmp_data[k] - 1];
          ii = 1;
        }
      }

      ii_size[0] = 1;
      ii_size[1] = (int16_T)b_idx;
      key_start = b_idx - 1;
      for (k = 0; k <= key_start; k++) {
        c_ii_data[k] = d_ii_data[k];
      }

      k = possible_matches->size[0] * possible_matches->size[1];
      possible_matches->size[0] = 1;
      possible_matches->size[1] = ii_size[1];
      emxEnsureCapacity((emxArray__common *)possible_matches, k, (int32_T)sizeof
                        (real_T));
      key_start = ii_size[1] - 1;
      for (k = 0; k <= key_start; k++) {
        possible_matches->data[k] = (real_T)c_ii_data[k];
      }

      for (key_start = 0; key_start <= possible_matches->size[1] - 1; key_start
           ++) {
        if (Y[(int32_T)possible_matches->data[key_start] - 1].re >= threshold) {
          /*  one more hit -- every key must be hit at least once. */
          key_hits->data[j]++;
        }
      }
    }

    /*  after looking at this entire key, if there aren't any keys that */
    /*  didn't hit, see if we want to up the max */
    i0 = x->size[0] * x->size[1];
    x->size[0] = 1;
    x->size[1] = key_hits->size[1];
    emxEnsureCapacity((emxArray__common *)x, i0, (int32_T)sizeof(boolean_T));
    key_start = key_hits->size[0] * key_hits->size[1] - 1;
    for (i0 = 0; i0 <= key_start; i0++) {
      x->data[i0] = (key_hits->data[i0] == 0.0);
    }

    key_start = x->size[1];
    if (1 <= key_start) {
      k = 1;
    } else {
      k = key_start;
    }

    b_idx = 0;
    ii = 1;
    exitg1 = FALSE;
    while ((exitg1 == 0U) && (ii <= key_start)) {
      if (x->data[ii - 1]) {
        b_idx = 1;
        exitg1 = TRUE;
      } else {
        ii++;
      }
    }

    if (k == 1) {
      if (b_idx == 0) {
        k = 0;
      }
    } else {
      if (1 > b_idx) {
        i0 = -1;
      } else {
        i0 = 0;
      }

      k = i0 + 1;
    }

    if (k == 0) {
      if (key_hits->size[1] == 0) {
        y = 0.0;
      } else {
        key_start = key_hits->size[1];
        y = key_hits->data[0];
        for (k = 2; k <= key_start; k++) {
          y += key_hits->data[k - 1];
        }
      }

      if (y > hits) {
        if (key_hits->size[1] == 0) {
          hits = 0.0;
        } else {
          key_start = key_hits->size[1];
          hits = key_hits->data[0];
          for (k = 2; k <= key_start; k++) {
            hits += key_hits->data[k - 1];
          }
        }
      }
    }

    /*  update the key position */
    key_start = key_points_data[i] + 1;
    i++;
  }

  emxFree_boolean_T(&x);
  emxFree_real_T(&possible_matches);
  emxFree_real_T(&key_hits);
  return hits;
}
Esempio n. 7
0
/*
 * function [counts] = get_unique_counts(a,uniques)
 */
void get_unique_counts(const emlrtStack *sp, const emxArray_real_T *a, const
  emxArray_real_T *uniques, emxArray_real_T *counts)
{
  int32_T i0;
  int32_T loop_ub;
  int32_T i;
  emxArray_boolean_T *s;
  real_T b_uniques;
  int32_T k;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);

  /* 'get_unique_counts:3' counts = zeros(numel(uniques),1); */
  i0 = counts->size[0];
  counts->size[0] = uniques->size[0];
  emxEnsureCapacity(sp, (emxArray__common *)counts, i0, (int32_T)sizeof(real_T),
                    &emlrtRTEI);
  loop_ub = uniques->size[0];
  for (i0 = 0; i0 < loop_ub; i0++) {
    counts->data[i0] = 0.0;
  }

  /* 'get_unique_counts:5' for i = 1:numel(uniques) */
  i = 1;
  emxInit_boolean_T(sp, &s, 3, &emlrtRTEI, true);
  while (i - 1 <= uniques->size[0] - 1) {
    /* 'get_unique_counts:6' counts(i) = nnz(a==uniques(i)); */
    i0 = s->size[0] * s->size[1] * s->size[2];
    s->size[0] = a->size[0];
    s->size[1] = a->size[1];
    s->size[2] = a->size[2];
    emxEnsureCapacity(sp, (emxArray__common *)s, i0, (int32_T)sizeof(boolean_T),
                      &emlrtRTEI);
    i0 = uniques->size[0];
    if (!((i >= 1) && (i <= i0))) {
      emlrtDynamicBoundsCheckR2012b(i, 1, i0, &emlrtBCI, sp);
    }

    b_uniques = uniques->data[i - 1];
    loop_ub = a->size[0] * a->size[1] * a->size[2];
    for (i0 = 0; i0 < loop_ub; i0++) {
      s->data[i0] = (a->data[i0] == b_uniques);
    }

    loop_ub = 0;
    i0 = s->size[0] * s->size[1] * s->size[2];
    for (k = 0; k < i0; k++) {
      if (s->data[k]) {
        loop_ub++;
      }
    }

    i0 = counts->size[0];
    if (!((i >= 1) && (i <= i0))) {
      emlrtDynamicBoundsCheckR2012b(i, 1, i0, &b_emlrtBCI, sp);
    }

    counts->data[i - 1] = loop_ub;
    i++;
    if (*emlrtBreakCheckR2012bFlagVar != 0) {
      emlrtBreakCheckR2012b(sp);
    }
  }

  emxFree_boolean_T(&s);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Esempio n. 8
0
void b_Acoeff(const emlrtStack *sp, real_T ksi, real_T j, const emxArray_real_T *
              x, real_T t, const emxArray_real_T *gridT, emxArray_real_T *vals)
{
  emxArray_real_T *b;
  emxArray_real_T *r8;
  int32_T b_x;
  int32_T i;
  emxArray_boolean_T *b_t;
  real_T c_x;
  emxArray_boolean_T *c_t;
  emxArray_real_T *z0;
  emxArray_real_T *d_x;
  emxArray_real_T *e_x;
  emxArray_real_T *r9;
  int32_T b_b[2];
  int32_T f_x[2];
  emxArray_real_T *g_x;
  emxArray_real_T *r10;
  const mxArray *y;
  static const int32_T iv16[2] = { 1, 45 };

  const mxArray *m6;
  char_T cv18[45];
  static const char_T cv19[45] = { 'C', 'o', 'd', 'e', 'r', ':', 't', 'o', 'o',
    'l', 'b', 'o', 'x', ':', 'm', 't', 'i', 'm', 'e', 's', '_', 'n', 'o', 'D',
    'y', 'n', 'a', 'm', 'i', 'c', 'S', 'c', 'a', 'l', 'a', 'r', 'E', 'x', 'p',
    'a', 'n', 's', 'i', 'o', 'n' };

  const mxArray *b_y;
  static const int32_T iv17[2] = { 1, 21 };

  char_T cv20[21];
  static const char_T cv21[21] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T',
    'L', 'A', 'B', ':', 'i', 'n', 'n', 'e', 'r', 'd', 'i', 'm' };

  emxArray_boolean_T *d_t;
  real_T h_x;
  emxArray_boolean_T *e_t;
  emxArray_real_T *i_x;
  emxArray_real_T *r11;
  emxArray_real_T *j_x;
  emxArray_real_T *r12;
  emxArray_real_T *z1;
  int32_T b_z0[2];
  emxArray_real_T *c_z0;
  emxArray_real_T *k_x;
  const mxArray *c_y;
  static const int32_T iv18[2] = { 1, 45 };

  const mxArray *d_y;
  static const int32_T iv19[2] = { 1, 21 };

  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 = &b_st;
  d_st.tls = b_st.tls;
  emlrtHeapReferenceStackEnterFcnR2012b(sp);
  emxInit_real_T(sp, &b, 2, &bb_emlrtRTEI, true);
  emxInit_real_T(sp, &r8, 2, &bb_emlrtRTEI, true);

  /*  evaluate the coefficient A at the  boundary ksi=0 or ksi=1; */
  /*  for the index j which describes the time steps timePoints_j, at time t and space */
  /*  point x */
  /*  timePoints is a vector describing the time descritized domain */
  b_x = gridT->size[1];
  i = (int32_T)emlrtIntegerCheckFastR2012b(j, &emlrtDCI, sp);
  if (t <= gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &d_emlrtBCI,
       sp) - 1]) {
    b_x = vals->size[0] * vals->size[1];
    vals->size[0] = 1;
    vals->size[1] = 1;
    emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof(real_T),
                      &bb_emlrtRTEI);
    vals->data[0] = 0.0;
  } else {
    emxInit_boolean_T(sp, &b_t, 2, &bb_emlrtRTEI, true);
    b_x = b_t->size[0] * b_t->size[1];
    b_t->size[0] = 1;
    b_t->size[1] = 2 + x->size[1];
    emxEnsureCapacity(sp, (emxArray__common *)b_t, b_x, (int32_T)sizeof
                      (boolean_T), &bb_emlrtRTEI);
    b_x = gridT->size[1];
    i = (int32_T)j;
    b_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
      &e_emlrtBCI, sp) - 1]);
    b_x = gridT->size[1];
    i = (int32_T)((uint32_T)j + 1U);
    b_t->data[b_t->size[0]] = (t <= gridT->
      data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &f_emlrtBCI, sp) - 1]);
    i = x->size[1];
    for (b_x = 0; b_x < i; b_x++) {
      b_t->data[b_t->size[0] * (b_x + 2)] = (x->data[x->size[0] * b_x] == ksi);
    }

    st.site = &pe_emlrtRSI;
    if (all(&st, b_t)) {
      b_x = gridT->size[1];
      i = (int32_T)j;
      emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &c_emlrtBCI, sp);
      c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
      st.site = &emlrtRSI;
      if (c_x < 0.0) {
        b_st.site = &f_emlrtRSI;
        eml_error(&b_st);
      }

      b_x = vals->size[0] * vals->size[1];
      vals->size[0] = 1;
      vals->size[1] = 1;
      emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                        (real_T), &bb_emlrtRTEI);
      vals->data[0] = muDoubleScalarSqrt(c_x);
    } else {
      emxInit_boolean_T(sp, &c_t, 2, &bb_emlrtRTEI, true);
      b_x = c_t->size[0] * c_t->size[1];
      c_t->size[0] = 1;
      c_t->size[1] = 2 + x->size[1];
      emxEnsureCapacity(sp, (emxArray__common *)c_t, b_x, (int32_T)sizeof
                        (boolean_T), &bb_emlrtRTEI);
      b_x = gridT->size[1];
      i = (int32_T)j;
      c_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
        b_x, &g_emlrtBCI, sp) - 1]);
      b_x = gridT->size[1];
      i = (int32_T)((uint32_T)j + 1U);
      c_t->data[c_t->size[0]] = (t <= gridT->
        data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &h_emlrtBCI, sp) - 1]);
      i = x->size[1];
      for (b_x = 0; b_x < i; b_x++) {
        c_t->data[c_t->size[0] * (b_x + 2)] = (x->data[x->size[0] * b_x] != ksi);
      }

      emxInit_real_T(sp, &z0, 2, &cb_emlrtRTEI, true);
      emxInit_real_T(sp, &d_x, 2, &bb_emlrtRTEI, true);
      st.site = &qe_emlrtRSI;
      if (all(&st, c_t)) {
        st.site = &b_emlrtRSI;
        b_x = gridT->size[1];
        i = (int32_T)j;
        c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
          &m_emlrtBCI, &st) - 1];
        if (c_x < 0.0) {
          b_st.site = &f_emlrtRSI;
          eml_error(&b_st);
        }

        emxInit_real_T(&st, &e_x, 2, &bb_emlrtRTEI, true);
        b_x = e_x->size[0] * e_x->size[1];
        e_x->size[0] = 1;
        e_x->size[1] = x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)e_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = x->size[0] * x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          e_x->data[b_x] = x->data[b_x] - ksi;
        }

        emxInit_real_T(sp, &r9, 2, &bb_emlrtRTEI, true);
        b_abs(sp, e_x, r9);
        b_x = r8->size[0] * r8->size[1];
        r8->size[0] = 1;
        r8->size[1] = r9->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = r9->size[0] * r9->size[1];
        emxFree_real_T(&e_x);
        for (b_x = 0; b_x < i; b_x++) {
          r8->data[b_x] = r9->data[b_x];
        }

        emxFree_real_T(&r9);
        rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z0);
        st.site = &re_emlrtRSI;
        mpower(&st, z0, d_x);
        b_x = d_x->size[0] * d_x->size[1];
        d_x->size[0] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = d_x->size[0];
        b_x = d_x->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          d_x->data[b_x] = -d_x->data[b_x];
        }

        b_x = b->size[0] * b->size[1];
        b->size[0] = 1;
        b->size[1] = d_x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)b, b_x, (int32_T)sizeof(real_T),
                          &bb_emlrtRTEI);
        i = d_x->size[0] * d_x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          b->data[b_x] = d_x->data[b_x];
        }

        for (i = 0; i < d_x->size[1]; i++) {
          b->data[i] = muDoubleScalarExp(b->data[i]);
        }

        st.site = &re_emlrtRSI;
        b_mrdivide(&st, b, z0);
        for (b_x = 0; b_x < 2; b_x++) {
          i = d_x->size[0] * d_x->size[1];
          d_x->size[b_x] = z0->size[b_x];
          emxEnsureCapacity(sp, (emxArray__common *)d_x, i, (int32_T)sizeof
                            (real_T), &ab_emlrtRTEI);
        }

        for (i = 0; i < z0->size[1]; i++) {
          d_x->data[i] = scalar_erf(z0->data[i]);
        }

        b_x = d_x->size[0] * d_x->size[1];
        d_x->size[0] = 1;
        emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = d_x->size[0];
        b_x = d_x->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          d_x->data[b_x] *= 1.7724538509055159;
        }

        for (b_x = 0; b_x < 2; b_x++) {
          b_b[b_x] = b->size[b_x];
        }

        for (b_x = 0; b_x < 2; b_x++) {
          f_x[b_x] = d_x->size[b_x];
        }

        emxInit_real_T(sp, &g_x, 2, &bb_emlrtRTEI, true);
        emlrtSizeEqCheck2DFastR2012b(b_b, f_x, &o_emlrtECI, sp);
        b_x = g_x->size[0] * g_x->size[1];
        g_x->size[0] = 1;
        g_x->size[1] = x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)g_x, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = x->size[0] * x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          g_x->data[b_x] = x->data[b_x] - ksi;
        }

        emxInit_real_T(sp, &r10, 2, &bb_emlrtRTEI, true);
        b_abs(sp, g_x, r10);
        b_x = r8->size[0] * r8->size[1];
        r8->size[0] = 1;
        r8->size[1] = r10->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = r10->size[0] * r10->size[1];
        emxFree_real_T(&g_x);
        for (b_x = 0; b_x < i; b_x++) {
          r8->data[b_x] = r10->data[b_x];
        }

        emxFree_real_T(&r10);
        rdivide(sp, r8, 3.5449077018110318, vals);
        st.site = &re_emlrtRSI;
        b_x = b->size[0] * b->size[1];
        b->size[0] = 1;
        emxEnsureCapacity(&st, (emxArray__common *)b, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = b->size[0];
        b_x = b->size[1];
        i *= b_x;
        for (b_x = 0; b_x < i; b_x++) {
          b->data[b_x] -= d_x->data[b_x];
        }

        b_st.site = &he_emlrtRSI;
        if (!(vals->size[1] == 1)) {
          if ((vals->size[1] == 1) || (b->size[1] == 1)) {
            y = NULL;
            m6 = emlrtCreateCharArray(2, iv16);
            for (i = 0; i < 45; i++) {
              cv18[i] = cv19[i];
            }

            emlrtInitCharArrayR2013a(&b_st, 45, m6, cv18);
            emlrtAssign(&y, m6);
            c_st.site = &fh_emlrtRSI;
            d_st.site = &vg_emlrtRSI;
            b_error(&c_st, message(&d_st, y, &j_emlrtMCI), &k_emlrtMCI);
          } else {
            b_y = NULL;
            m6 = emlrtCreateCharArray(2, iv17);
            for (i = 0; i < 21; i++) {
              cv20[i] = cv21[i];
            }

            emlrtInitCharArrayR2013a(&b_st, 21, m6, cv20);
            emlrtAssign(&b_y, m6);
            c_st.site = &gh_emlrtRSI;
            d_st.site = &wg_emlrtRSI;
            b_error(&c_st, message(&d_st, b_y, &l_emlrtMCI), &m_emlrtMCI);
          }
        }

        c_x = vals->data[0];
        b_x = vals->size[0] * vals->size[1];
        vals->size[0] = 1;
        vals->size[1] = b->size[1];
        emxEnsureCapacity(&st, (emxArray__common *)vals, b_x, (int32_T)sizeof
                          (real_T), &bb_emlrtRTEI);
        i = b->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          vals->data[vals->size[0] * b_x] = c_x * b->data[b->size[0] * b_x];
        }
      } else {
        emxInit_boolean_T(sp, &d_t, 2, &bb_emlrtRTEI, true);
        b_x = d_t->size[0] * d_t->size[1];
        d_t->size[0] = 1;
        d_t->size[1] = 1 + x->size[1];
        emxEnsureCapacity(sp, (emxArray__common *)d_t, b_x, (int32_T)sizeof
                          (boolean_T), &bb_emlrtRTEI);
        b_x = gridT->size[1];
        i = (int32_T)((uint32_T)j + 1U);
        d_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
          b_x, &i_emlrtBCI, sp) - 1]);
        i = x->size[1];
        for (b_x = 0; b_x < i; b_x++) {
          d_t->data[d_t->size[0] * (b_x + 1)] = (x->data[x->size[0] * b_x] ==
            ksi);
        }

        st.site = &se_emlrtRSI;
        if (all(&st, d_t)) {
          b_x = gridT->size[1];
          i = (int32_T)j;
          emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &b_emlrtBCI, sp);
          c_x = (t - gridT->data[(int32_T)j - 1]) / 3.1415926535897931;
          b_x = gridT->size[1];
          i = (int32_T)(j + 1.0);
          emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x, &emlrtBCI, sp);
          h_x = (t - gridT->data[(int32_T)(j + 1.0) - 1]) / 3.1415926535897931;
          st.site = &c_emlrtRSI;
          if (c_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          st.site = &c_emlrtRSI;
          if (h_x < 0.0) {
            b_st.site = &f_emlrtRSI;
            eml_error(&b_st);
          }

          b_x = vals->size[0] * vals->size[1];
          vals->size[0] = 1;
          vals->size[1] = 1;
          emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                            (real_T), &bb_emlrtRTEI);
          vals->data[0] = muDoubleScalarSqrt(c_x) - muDoubleScalarSqrt(h_x);
        } else {
          emxInit_boolean_T(sp, &e_t, 2, &bb_emlrtRTEI, true);
          b_x = e_t->size[0] * e_t->size[1];
          e_t->size[0] = 1;
          e_t->size[1] = 1 + x->size[1];
          emxEnsureCapacity(sp, (emxArray__common *)e_t, b_x, (int32_T)sizeof
                            (boolean_T), &bb_emlrtRTEI);
          b_x = gridT->size[1];
          i = (int32_T)((uint32_T)j + 1U);
          e_t->data[0] = (t > gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1,
            b_x, &j_emlrtBCI, sp) - 1]);
          i = x->size[1];
          for (b_x = 0; b_x < i; b_x++) {
            e_t->data[e_t->size[0] * (b_x + 1)] = (x->data[x->size[0] * b_x] !=
              ksi);
          }

          st.site = &te_emlrtRSI;
          if (all(&st, e_t)) {
            st.site = &d_emlrtRSI;
            b_x = gridT->size[1];
            i = (int32_T)j;
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
              &k_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            emxInit_real_T(&st, &i_x, 2, &bb_emlrtRTEI, true);
            b_x = i_x->size[0] * i_x->size[1];
            i_x->size[0] = 1;
            i_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)i_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              i_x->data[b_x] = x->data[b_x] - ksi;
            }

            emxInit_real_T(sp, &r11, 2, &bb_emlrtRTEI, true);
            b_abs(sp, i_x, r11);
            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = r11->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = r11->size[0] * r11->size[1];
            emxFree_real_T(&i_x);
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = r11->data[b_x];
            }

            emxFree_real_T(&r11);
            rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z0);
            st.site = &e_emlrtRSI;
            b_x = gridT->size[1];
            i = (int32_T)((uint32_T)j + 1U);
            c_x = t - gridT->data[emlrtDynamicBoundsCheckFastR2012b(i, 1, b_x,
              &l_emlrtBCI, &st) - 1];
            if (c_x < 0.0) {
              b_st.site = &f_emlrtRSI;
              eml_error(&b_st);
            }

            emxInit_real_T(&st, &j_x, 2, &bb_emlrtRTEI, true);
            b_x = j_x->size[0] * j_x->size[1];
            j_x->size[0] = 1;
            j_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)j_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              j_x->data[b_x] = x->data[b_x] - ksi;
            }

            emxInit_real_T(sp, &r12, 2, &bb_emlrtRTEI, true);
            b_abs(sp, j_x, r12);
            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = r12->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = r12->size[0] * r12->size[1];
            emxFree_real_T(&j_x);
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = r12->data[b_x];
            }

            emxFree_real_T(&r12);
            emxInit_real_T(sp, &z1, 2, &db_emlrtRTEI, true);
            rdivide(sp, r8, 2.0 * muDoubleScalarSqrt(c_x), z1);
            st.site = &ue_emlrtRSI;
            mpower(&st, z0, d_x);
            b_x = d_x->size[0] * d_x->size[1];
            d_x->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0];
            b_x = d_x->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              d_x->data[b_x] = -d_x->data[b_x];
            }

            b_x = b->size[0] * b->size[1];
            b->size[0] = 1;
            b->size[1] = d_x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)b, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0] * d_x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              b->data[b_x] = d_x->data[b_x];
            }

            for (i = 0; i < d_x->size[1]; i++) {
              b->data[i] = muDoubleScalarExp(b->data[i]);
            }

            st.site = &ue_emlrtRSI;
            b_mrdivide(&st, b, z0);
            st.site = &ue_emlrtRSI;
            mpower(&st, z1, d_x);
            b_x = d_x->size[0] * d_x->size[1];
            d_x->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)d_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0];
            b_x = d_x->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              d_x->data[b_x] = -d_x->data[b_x];
            }

            b_x = r8->size[0] * r8->size[1];
            r8->size[0] = 1;
            r8->size[1] = d_x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)r8, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = d_x->size[0] * d_x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              r8->data[b_x] = d_x->data[b_x];
            }

            for (i = 0; i < d_x->size[1]; i++) {
              r8->data[i] = muDoubleScalarExp(r8->data[i]);
            }

            st.site = &ue_emlrtRSI;
            b_mrdivide(&st, r8, z1);
            for (b_x = 0; b_x < 2; b_x++) {
              b_b[b_x] = b->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = r8->size[b_x];
            }

            emxInit_real_T(sp, &c_z0, 2, &bb_emlrtRTEI, true);
            emlrtSizeEqCheck2DFastR2012b(b_b, b_z0, &m_emlrtECI, sp);
            b_x = c_z0->size[0] * c_z0->size[1];
            c_z0->size[0] = 1;
            c_z0->size[1] = z0->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)c_z0, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = z0->size[0] * z0->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              c_z0->data[b_x] = z0->data[b_x];
            }

            b_erf(sp, c_z0, z0);
            b_erf(sp, z1, d_x);
            emxFree_real_T(&c_z0);
            emxFree_real_T(&z1);
            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = z0->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              f_x[b_x] = d_x->size[b_x];
            }

            emlrtSizeEqCheck2DFastR2012b(b_z0, f_x, &n_emlrtECI, sp);
            b_x = z0->size[0] * z0->size[1];
            z0->size[0] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)z0, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = z0->size[0];
            b_x = z0->size[1];
            i *= b_x;
            for (b_x = 0; b_x < i; b_x++) {
              z0->data[b_x] = 1.7724538509055159 * (z0->data[b_x] - d_x->
                data[b_x]);
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_b[b_x] = b->size[b_x];
            }

            for (b_x = 0; b_x < 2; b_x++) {
              b_z0[b_x] = z0->size[b_x];
            }

            emxInit_real_T(sp, &k_x, 2, &bb_emlrtRTEI, true);
            emlrtSizeEqCheck2DFastR2012b(b_b, b_z0, &m_emlrtECI, sp);
            b_x = k_x->size[0] * k_x->size[1];
            k_x->size[0] = 1;
            k_x->size[1] = x->size[1];
            emxEnsureCapacity(sp, (emxArray__common *)k_x, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = x->size[0] * x->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              k_x->data[b_x] = x->data[b_x] - ksi;
            }

            b_abs(sp, k_x, d_x);
            rdivide(sp, d_x, 3.5449077018110318, vals);
            st.site = &ue_emlrtRSI;
            b_x = b->size[0] * b->size[1];
            b->size[0] = 1;
            emxEnsureCapacity(&st, (emxArray__common *)b, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            i = b->size[0];
            b_x = b->size[1];
            i *= b_x;
            emxFree_real_T(&k_x);
            for (b_x = 0; b_x < i; b_x++) {
              b->data[b_x] = (b->data[b_x] - r8->data[b_x]) + z0->data[b_x];
            }

            b_st.site = &he_emlrtRSI;
            if (!(vals->size[1] == 1)) {
              if ((vals->size[1] == 1) || (b->size[1] == 1)) {
                c_y = NULL;
                m6 = emlrtCreateCharArray(2, iv18);
                for (i = 0; i < 45; i++) {
                  cv18[i] = cv19[i];
                }

                emlrtInitCharArrayR2013a(&b_st, 45, m6, cv18);
                emlrtAssign(&c_y, m6);
                c_st.site = &fh_emlrtRSI;
                d_st.site = &vg_emlrtRSI;
                b_error(&c_st, message(&d_st, c_y, &j_emlrtMCI), &k_emlrtMCI);
              } else {
                d_y = NULL;
                m6 = emlrtCreateCharArray(2, iv19);
                for (i = 0; i < 21; i++) {
                  cv20[i] = cv21[i];
                }

                emlrtInitCharArrayR2013a(&b_st, 21, m6, cv20);
                emlrtAssign(&d_y, m6);
                c_st.site = &gh_emlrtRSI;
                d_st.site = &wg_emlrtRSI;
                b_error(&c_st, message(&d_st, d_y, &l_emlrtMCI), &m_emlrtMCI);
              }
            }

            c_x = vals->data[0];
            b_x = vals->size[0] * vals->size[1];
            vals->size[0] = 1;
            vals->size[1] = b->size[1];
            emxEnsureCapacity(&st, (emxArray__common *)vals, b_x, (int32_T)
                              sizeof(real_T), &bb_emlrtRTEI);
            i = b->size[1];
            for (b_x = 0; b_x < i; b_x++) {
              vals->data[vals->size[0] * b_x] = c_x * b->data[b->size[0] * b_x];
            }
          } else {
            b_x = vals->size[0] * vals->size[1];
            vals->size[0] = 1;
            vals->size[1] = 1;
            emxEnsureCapacity(sp, (emxArray__common *)vals, b_x, (int32_T)sizeof
                              (real_T), &bb_emlrtRTEI);
            vals->data[0] = 0.0;
          }

          emxFree_boolean_T(&e_t);
        }

        emxFree_boolean_T(&d_t);
      }

      emxFree_boolean_T(&c_t);
      emxFree_real_T(&d_x);
      emxFree_real_T(&z0);
    }

    emxFree_boolean_T(&b_t);
  }

  emxFree_real_T(&r8);
  emxFree_real_T(&b);
  emlrtHeapReferenceStackLeaveFcnR2012b(sp);
}
Esempio n. 9
0
void a_melcepst(const real_T s[512], real_T fs, int32_T nc, emxArray_real_T *c)
{
  real_T b_s[512];
  int32_T i;
  static const real_T dv0[512] = { 0.080000000000000016, 0.080034772851092173,
    0.080139086147189731, 0.080312924117550422, 0.0805562604802531,
    0.08086905844617126, 0.081251270724534919, 0.0817028395300804,
    0.082223696591786744, 0.082813763163197218, 0.083472950034324755,
    0.084201157545139238, 0.084998275600634943, 0.085864183687475115,
    0.086798750892212118, 0.0878018359210796, 0.0888732871213544,
    0.0900129425042841, 0.091220629769577732, 0.092496166331455187,
    0.093839359346251483, 0.095250005741572386, 0.09672789224699585,
    0.09827279542631584, 0.099884481711322914, 0.10156270743711604,
    0.10330721887894206, 0.10511775229055487, 0.10699403394409035,
    0.10893578017145067, 0.11094269740719032, 0.11301448223289995,
    0.11515082142307836, 0.11735139199248851, 0.11961586124498802,
    0.12194388682382867, 0.12433511676341558, 0.12678918954252011,
    0.12930573413893637, 0.1318843700855753, 0.13452470752798562,
    0.13722634728329447, 0.13998888090055894, 0.1428118907225176,
    0.14569494994873494, 0.14863762270012759, 0.1516394640848634,
    0.15470002026562302, 0.15781882852821355, 0.16099541735152506,
    0.16422930647881784, 0.16752000699033076, 0.17086702137719906,
    0.17426984361667108, 0.177727959248612, 0.181240845453283,
    0.18480797113038444, 0.18842879697935122, 0.19210277558088723,
    0.19582935147972808, 0.19960796126861807, 0.20343803367348967,
    0.20731898963983236, 0.211250242420238, 0.21523119766310839,
    0.2192612535025138, 0.2233398006491864, 0.22746622248263659,
    0.23163989514437766, 0.23586018763224437, 0.24012646189579223,
    0.24443807293276187, 0.24879436888659412, 0.25319469114498255,
    0.25763837443944609, 0.26212474694590859, 0.26665313038626953,
    0.27122284013095055, 0.27583318530240147, 0.28048346887955239,
    0.28517298780319289, 0.2899010330822655, 0.29466688990105527,
    0.29946983772726005, 0.30430915042092521, 0.30918409634422606,
    0.31409393847208128, 0.31903793450358153, 0.32401533697421447,
    0.32902539336887182, 0.33406734623561868, 0.33914043330021065,
    0.34424388758133867, 0.34937693750658638, 0.35453880702908114,
    0.35972871574482179, 0.36494587901066489, 0.3701895080629527,
    0.37545881013676219, 0.38075298858576168, 0.38607124300265128,
    0.39141276934017522, 0.39677676003268147, 0.40216240411821519,
    0.40756888736112512, 0.41299539237516436, 0.41844109874706864,
    0.42390518316059117, 0.4293868195209769, 0.43488517907985663,
    0.44039943056054276, 0.44592874028370622, 0.45147227229341824,
    0.45702918848353491, 0.46259864872440754, 0.46817981098989864,
    0.47377183148468471, 0.47937386477182686, 0.48498506390058893,
    0.490604580534485, 0.49623156507953636, 0.50186516681271842,
    0.50750453401057793, 0.51314881407800261, 0.51879715367712187,
    0.524448698856319, 0.53010259517933778, 0.53575798785446094,
    0.54141402186374354, 0.5470698420922796, 0.55272459345748381,
    0.55837742103836852, 0.5640274702047956, 0.56967388674668551,
    0.57531581700316159, 0.58095240799161241, 0.58658280753665026,
    0.59220616439894935, 0.59782162840394082, 0.60342835057034794,
    0.60902548323854022, 0.61461218019868813, 0.62018759681869828,
    0.62575089017190988, 0.63130121916453474, 0.63683774466281806,
    0.64235962961990467, 0.64786603920238861, 0.65335614091652849,
    0.65882910473410994, 0.66428410321793319, 0.6697203116469117,
    0.67513690814075755, 0.68053307378423888, 0.68590799275098879,
    0.69126085242684687, 0.69659084353271583, 0.70189716024691284,
    0.70717900032699887, 0.7124355652310671, 0.717666060238471,
    0.72286969456997574, 0.72804568150731275, 0.73319323851212115,
    0.73831158734425673, 0.74339995417945037, 0.74845756972630173,
    0.75348366934258248, 0.75847749315084323, 0.76343828615329357,
    0.7683652983459498, 0.77325778483202323, 0.77811500593454008,
    0.78293622730816892, 0.78772072005024552, 0.7924677608109707,
    0.79717663190277332, 0.80184662140881269, 0.80647702329061177,
    0.81106713749480042, 0.8156162700589541, 0.82012373321651044,
    0.82458884550075162, 0.82901093184783137, 0.83338932369883667,
    0.83772335910086348, 0.84201238280709623, 0.84625574637587087,
    0.85045280826871128, 0.8546029339473209, 0.85870549596951617,
    0.86275987408408694, 0.86676545532457061, 0.8707216341019236,
    0.87462781229607822, 0.87848339934637087, 0.88228781234082576,
    0.88604047610428438, 0.88974082328536275, 0.89338829444222823,
    0.89698233812717909, 0.90052241097001584, 0.90400797776019148,
    0.90743851152772792, 0.91081349362288644, 0.91413241379458121,
    0.91739477026752081, 0.92060006981807141, 0.92374782784882448,
    0.92683756846186127, 0.9298688245307023, 0.93284113777093092,
    0.93575405880947859, 0.938607147252565, 0.94139997175227874,
    0.94413211007179187, 0.94680314914919594, 0.94941268515995136,
    0.95196032357793992, 0.95444567923511281, 0.95686837637972111,
    0.9592280487331255, 0.96152433954517225, 0.96375690164812866,
    0.965925397509171, 0.96802949928141335, 0.970068888853475,
    0.97204325789757351, 0.97395230791614062, 0.97579575028695,
    0.97757330630675354, 0.97928470723341743, 0.98092969432655219,
    0.98250801888663064, 0.98401944229258809, 0.98546373603789827,
    0.98684068176512052, 0.98815007129891252, 0.98939170667750365,
    0.99056540018262351, 0.99167097436788332, 0.99270826208560237,
    0.99367710651207919, 0.99457736117130091, 0.99540888995708832,
    0.9961715671536735, 0.99686527745470577, 0.99748991598068559,
    0.99804538829481926, 0.9985316104172981, 0.99894850883799369,
    0.99929602052757294, 0.99957409294702582, 0.99978268405560977,
    0.99992176231720475, 0.99999130670508207, 0.99999130670508207,
    0.99992176231720475, 0.99978268405560977, 0.99957409294702582,
    0.99929602052757294, 0.99894850883799369, 0.9985316104172981,
    0.99804538829481926, 0.99748991598068559, 0.99686527745470577,
    0.9961715671536735, 0.99540888995708832, 0.99457736117130091,
    0.99367710651207919, 0.99270826208560237, 0.99167097436788332,
    0.99056540018262351, 0.98939170667750365, 0.98815007129891264,
    0.98684068176512052, 0.98546373603789827, 0.9840194422925882,
    0.98250801888663064, 0.98092969432655219, 0.97928470723341743,
    0.97757330630675365, 0.97579575028695009, 0.97395230791614062,
    0.97204325789757351, 0.970068888853475, 0.96802949928141335,
    0.96592539750917106, 0.96375690164812866, 0.96152433954517225,
    0.9592280487331255, 0.95686837637972122, 0.95444567923511281,
    0.95196032357794014, 0.94941268515995125, 0.94680314914919594,
    0.94413211007179187, 0.94139997175227885, 0.938607147252565,
    0.93575405880947871, 0.93284113777093114, 0.92986882453070241,
    0.92683756846186127, 0.92374782784882448, 0.92060006981807163,
    0.91739477026752092, 0.91413241379458121, 0.91081349362288655,
    0.90743851152772792, 0.90400797776019148, 0.900522410970016,
    0.89698233812717909, 0.89338829444222834, 0.88974082328536275,
    0.8860404761042846, 0.88228781234082587, 0.878483399346371,
    0.87462781229607822, 0.87072163410192371, 0.86676545532457072,
    0.86275987408408716, 0.85870549596951617, 0.854602933947321,
    0.85045280826871128, 0.84625574637587087, 0.84201238280709623,
    0.83772335910086393, 0.83338932369883678, 0.82901093184783159,
    0.82458884550075162, 0.82012373321651089, 0.81561627005895421,
    0.81106713749480042, 0.80647702329061177, 0.80184662140881269,
    0.79717663190277355, 0.79246776081097081, 0.78772072005024563,
    0.78293622730816925, 0.7781150059345403, 0.77325778483202334,
    0.76836529834594991, 0.7634382861532939, 0.75847749315084312,
    0.7534836693425826, 0.7484575697263014, 0.74339995417945093,
    0.73831158734425684, 0.73319323851212148, 0.72804568150731264,
    0.72286969456997607, 0.717666060238471, 0.71243556523106721,
    0.70717900032699887, 0.701897160246913, 0.696590843532716,
    0.69126085242684687, 0.68590799275098913, 0.680533073784239,
    0.67513690814075789, 0.66972031164691181, 0.66428410321793374,
    0.65882910473411, 0.65335614091652838, 0.6478660392023885,
    0.64235962961990478, 0.63683774466281828, 0.63130121916453463,
    0.62575089017190988, 0.62018759681869828, 0.61461218019868846,
    0.60902548323854022, 0.603428350570348, 0.597821628403941,
    0.59220616439894924, 0.58658280753665026, 0.58095240799161219,
    0.57531581700316192, 0.56967388674668551, 0.56402747020479571,
    0.55837742103836829, 0.55272459345748415, 0.54706984209227971,
    0.54141402186374377, 0.53575798785446127, 0.53010259517933778,
    0.52444869885631917, 0.51879715367712176, 0.51314881407800306,
    0.50750453401057793, 0.50186516681271853, 0.49623156507953631,
    0.49060458053448541, 0.48498506390058904, 0.47937386477182709,
    0.47377183148468466, 0.46817981098989869, 0.46259864872440776,
    0.45702918848353485, 0.45147227229341824, 0.44592874028370633,
    0.440399430560543, 0.43488517907985663, 0.429386819520977,
    0.42390518316059139, 0.41844109874706892, 0.41299539237516436,
    0.40756888736112484, 0.40216240411821547, 0.39677676003268147,
    0.39141276934017533, 0.3860712430026515, 0.3807529885857619,
    0.3754588101367623, 0.37018950806295287, 0.36494587901066522,
    0.35972871574482168, 0.35453880702908119, 0.34937693750658616,
    0.34424388758133895, 0.33914043330021071, 0.33406734623561879,
    0.3290253933688716, 0.32401533697421481, 0.31903793450358164,
    0.31409393847208145, 0.30918409634422594, 0.30430915042092521,
    0.29946983772726016, 0.29466688990105516, 0.2899010330822655,
    0.285172987803193, 0.28048346887955261, 0.27583318530240147,
    0.2712228401309506, 0.2666531303862697, 0.26212474694590882,
    0.25763837443944609, 0.25319469114498266, 0.24879436888659429,
    0.24443807293276176, 0.24012646189579229, 0.23586018763224448,
    0.23163989514437777, 0.22746622248263659, 0.22333980064918652,
    0.21926125350251396, 0.21523119766310861, 0.21125024242023804,
    0.20731898963983225, 0.20343803367348989, 0.19960796126861807,
    0.19582935147972819, 0.19210277558088712, 0.18842879697935144,
    0.1848079711303845, 0.18124084545328312, 0.17772795924861196,
    0.17426984361667136, 0.17086702137719911, 0.16752000699033065,
    0.16422930647881784, 0.16099541735152512, 0.15781882852821361,
    0.15470002026562296, 0.15163946408486367, 0.14863762270012765,
    0.14569494994873505, 0.1428118907225176, 0.13998888090055922,
    0.13722634728329458, 0.13452470752798557, 0.1318843700855753,
    0.12930573413893648, 0.12678918954252016, 0.12433511676341558,
    0.12194388682382873, 0.11961586124498813, 0.11735139199248862,
    0.11515082142307836, 0.1130144822329, 0.11094269740719043,
    0.10893578017145061, 0.10699403394409041, 0.10511775229055476,
    0.10330721887894218, 0.10156270743711604, 0.09988448171132297,
    0.09827279542631584, 0.0967278922469959, 0.095250005741572386,
    0.093839359346251427, 0.092496166331455243, 0.091220629769577788,
    0.0900129425042841, 0.088873287121354339, 0.087801835921079707,
    0.086798750892212118, 0.085864183687475171, 0.084998275600634943,
    0.084201157545139349, 0.083472950034324811, 0.082813763163197218,
    0.082223696591786744, 0.081702839530080451, 0.081251270724534919,
    0.08086905844617126, 0.0805562604802531, 0.080312924117550422,
    0.080139086147189731, 0.080034772851092173, 0.080000000000000016 };

  emxArray_creal_T *f;
  emxArray_real_T *m;
  int32_T ia;
  int32_T a;
  int32_T i0;
  int32_T i1;
  int32_T br;
  emxArray_creal_T *pw;
  int32_T b_f[2];
  int32_T c_f[2];
  int32_T ar;
  emxArray_creal_T d_f;
  emxArray_creal_T e_f;
  real_T b_a;
  real_T b;
  real_T f_re;
  real_T f_im;
  creal_T ath;
  boolean_T exitg1;
  creal_T b_pw;
  emxArray_creal_T *f_f;
  int32_T g_f[2];
  emxArray_real_T *b_b;
  emxArray_real_T *y;
  int32_T c_k;
  uint32_T unnamed_idx_0;
  int32_T b_m;
  int32_T ic;
  int64_T i2;
  emxArray_int32_T *r0;
  emxArray_int32_T *idx;
  emxArray_boolean_T *c_b;
  emxArray_real_T *b_c;
  emxArray_real_T *c_c;

  /* MELCEPST Calculate the mel cepstrum of a signal C=(S,FS,W,NC,P,N,INC,FL,FH) */
  /*  */
  /*  */
  /*  Simple use: c=melcepst(s,fs)	% calculate mel cepstrum with 12 coefs, 256 sample frames */
  /* 				  c=melcepst(s,fs,'e0dD') % include log energy, 0th cepstral coef, delta and delta-delta coefs */
  /*  */
  /*  Inputs: */
  /*      s	 speech signal */
  /*      fs  sample rate in Hz (default 11025) */
  /*      nc  number of cepstral coefficients excluding 0'th coefficient (default 12) */
  /*      n   length of frame in samples (default power of 2 < (0.03*fs)) */
  /*      p   number of filters in filterbank (default: floor(3*log(fs)) = approx 2.1 per ocatave) */
  /*      inc frame increment (default n/2) */
  /*      fl  low end of the lowest filter as a fraction of fs (default = 0) */
  /*      fh  high end of highest filter as a fraction of fs (default = 0.5) */
  /*  */
  /* 		w   any sensible combination of the following: */
  /*  */
  /* 				'R'  rectangular window in time domain */
  /* 				'N'	Hanning window in time domain */
  /* 				'M'	Hamming window in time domain (default) */
  /*  */
  /* 		      't'  triangular shaped filters in mel domain (default) */
  /* 		      'n'  hanning shaped filters in mel domain */
  /* 		      'm'  hamming shaped filters in mel domain */
  /*  */
  /* 				'p'	filters act in the power domain */
  /* 				'a'	filters act in the absolute magnitude domain (default) */
  /*  */
  /* 			   '0'  include 0'th order cepstral coefficient */
  /* 				'E'  include log energy */
  /* 				'd'	include delta coefficients (dc/dt) */
  /* 				'D'	include delta-delta coefficients (d^2c/dt^2) */
  /*  */
  /* 		      'z'  highest and lowest filters taper down to zero (default) */
  /* 		      'y'  lowest filter remains at 1 down to 0 frequency and */
  /* 			   	  highest filter remains at 1 up to nyquist freqency */
  /*  */
  /* 		       If 'ty' or 'ny' is specified, the total power in the fft is preserved. */
  /*  */
  /*  Outputs:	c     mel cepstrum output: one frame per row. Log energy, if requested, is the */
  /*                  first element of each row followed by the delta and then the delta-delta */
  /*                  coefficients. */
  /*  */
  /*  BUGS: (1) should have power limit as 1e-16 rather than 1e-6 (or possibly a better way of choosing this) */
  /*            and put into VOICEBOX */
  /*        (2) get rdct to change the data length (properly) instead of doing it explicitly (wrongly) */
  /*       Copyright (C) Mike Brookes 1997 */
  /*       Version: $Id: melcepst.m,v 1.8 2011/09/02 16:24:14 dmb Exp $ */
  /*  */
  /*    VOICEBOX is a MATLAB toolbox for speech processing. */
  /*    Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html */
  /*  */
  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
  /*    This program is free software; you can redistribute it and/or modify */
  /*    it under the terms of the GNU General Public License as published by */
  /*    the Free Software Foundation; either version 2 of the License, or */
  /*    (at your option) any later version. */
  /*  */
  /*    This program is distributed in the hope that it will be useful, */
  /*    but WITHOUT ANY WARRANTY; without even the implied warranty of */
  /*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the */
  /*    GNU General Public License for more details. */
  /*  */
  /*    You can obtain a copy of the GNU General Public License from */
  /*    http://www.gnu.org/copyleft/gpl.html or by writing to */
  /*    Free Software Foundation, Inc.,675 Mass Ave, Cambridge, MA 02139, USA. */
  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
  /* floor(3*log(fs)); */
  /* 256; %20 / 1000 * fs;  % 10 ms window */
  /* nc = 20; */
  /* z=a_enframe(s,a_hamming(n),inc); */
  /*  HAMMING.M */
  /*  */
  /*  COPYRIGHT : (c) NUHAG, Dept.Math., University of Vienna, AUSTRIA */
  /*              http://nuhag.eu/ */
  /*              Permission is granted to modify and re-distribute this */
  /*              code in any manner as long as this notice is preserved. */
  /*              All standard disclaimers apply. */
  /*  */
  /*  HAMMING.M	- returns the N-point Hamming window. */
  /*  */
  /*  Input		: n = number */
  /*  */
  /*  Output	: w = vector */
  /*  */
  /*  Usage		: w = hamming (n) */
  /*  */
  /*  Comments	: allows also the call:  hamming(xx), taking only format from signal xx */
  /*  */
  /*  See also	: HAMMING2 */
  /*  modification of original MATLAB (3.5)  file */
  /*  HGFei, 1990   */
  /* z=enframe(s,hamming(n),inc); */
  for (i = 0; i < 512; i++) {
    b_s[i] = s[i] * dv0[i];
  }

  emxInit_creal_T(&f, 1);
  emxInit_real_T(&m, 2);
  a_rfft(b_s, f);
  a_melbankm(m, &a, &ia);

  /* [m,a,b]=melbankm(p,n,fs,fl,fh, 'M'); */
  if (a > ia) {
    i0 = 0;
    i1 = 0;
  } else {
    i0 = a - 1;
    i1 = ia;
  }

  if (a > ia) {
    br = 0;
  } else {
    br = a - 1;
  }

  emxInit_creal_T(&pw, 1);
  b_f[0] = f->size[0];
  b_f[1] = 1;
  c_f[0] = f->size[0];
  c_f[1] = 1;
  i = pw->size[0];
  pw->size[0] = i1 - i0;
  emxEnsureCapacity((emxArray__common *)pw, i, (int32_T)sizeof(creal_T));
  ar = (i1 - i0) - 1;
  for (i1 = 0; i1 <= ar; i1++) {
    d_f = *f;
    d_f.size = (int32_T *)&b_f;
    d_f.numDimensions = 1;
    e_f = *f;
    e_f.size = (int32_T *)&c_f;
    e_f.numDimensions = 1;
    b_a = e_f.data[br + i1].re;
    b = -e_f.data[br + i1].im;
    f_re = d_f.data[i0 + i1].re;
    f_im = d_f.data[i0 + i1].im;
    pw->data[i1].re = f_re * b_a - f_im * b;
    pw->data[i1].im = f_re * b + f_im * b_a;
  }

  i = 1;
  br = pw->size[0];
  ath = pw->data[0];
  if (br > 1) {
    if (rtIsNaN(pw->data[0].re) || rtIsNaN(pw->data[0].im)) {
      ar = 1;
      exitg1 = 0U;
      while ((exitg1 == 0U) && (ar + 1 <= br)) {
        i = ar + 1;
        if (!(rtIsNaN(pw->data[ar].re) || rtIsNaN(pw->data[ar].im))) {
          ath = pw->data[ar];
          exitg1 = 1U;
        } else {
          ar++;
        }
      }
    }

    if (i < br) {
      while (i + 1 <= br) {
        b_pw = pw->data[i];
        if (eml_relop(b_pw, ath, TRUE)) {
          ath = pw->data[i];
        }

        i++;
      }
    }
  }

  ath.re *= 1.0E-20;
  ath.im *= 1.0E-20;
  b_sqrt(&ath);
  if (a > ia) {
    i0 = 0;
    ia = 0;
  } else {
    i0 = a - 1;
  }

  emxInit_creal_T(&f_f, 1);
  g_f[0] = f->size[0];
  g_f[1] = 1;
  i1 = f_f->size[0];
  f_f->size[0] = ia - i0;
  emxEnsureCapacity((emxArray__common *)f_f, i1, (int32_T)sizeof(creal_T));
  ar = (ia - i0) - 1;
  for (i1 = 0; i1 <= ar; i1++) {
    d_f = *f;
    d_f.size = (int32_T *)&g_f;
    d_f.numDimensions = 1;
    f_f->data[i1] = d_f.data[i0 + i1];
  }

  b_emxInit_real_T(&b_b, 1);
  b_abs(f_f, b_b);
  emxFree_creal_T(&f_f);
  b_emxInit_real_T(&y, 1);
  if ((m->size[1] == 1) || (b_b->size[0] == 1)) {
    i0 = y->size[0];
    y->size[0] = m->size[0];
    emxEnsureCapacity((emxArray__common *)y, i0, (int32_T)sizeof(real_T));
    ar = m->size[0] - 1;
    for (i0 = 0; i0 <= ar; i0++) {
      y->data[i0] = 0.0;
      i = b_b->size[0] - 1;
      for (i1 = 0; i1 <= i; i1++) {
        y->data[i0] += m->data[i0 + m->size[0] * i1] * b_b->data[i1];
      }
    }
  } else {
    c_k = m->size[1];
    unnamed_idx_0 = (uint32_T)m->size[0];
    i0 = y->size[0];
    y->size[0] = (int32_T)unnamed_idx_0;
    emxEnsureCapacity((emxArray__common *)y, i0, (int32_T)sizeof(real_T));
    b_m = m->size[0];
    i = y->size[0];
    i0 = y->size[0];
    y->size[0] = i;
    emxEnsureCapacity((emxArray__common *)y, i0, (int32_T)sizeof(real_T));
    ar = i - 1;
    for (i0 = 0; i0 <= ar; i0++) {
      y->data[i0] = 0.0;
    }

    if (b_m == 0) {
    } else {
      for (i = 0; i <= 0; i += b_m) {
        i0 = i + b_m;
        for (ic = i; ic + 1 <= i0; ic++) {
          y->data[ic] = 0.0;
        }
      }

      br = 0;
      for (i = 0; i <= 0; i += b_m) {
        ar = 0;
        i0 = br + c_k;
        for (a = br; a + 1 <= i0; a++) {
          if (b_b->data[a] != 0.0) {
            ia = ar;
            i1 = i + b_m;
            for (ic = i; ic + 1 <= i1; ic++) {
              ia++;
              y->data[ic] += b_b->data[a] * m->data[ia - 1];
            }
          }

          ar += b_m;
        }

        br += c_k;
      }
    }
  }

  emxFree_real_T(&m);
  unnamed_idx_0 = (uint32_T)y->size[0];
  i0 = f->size[0];
  f->size[0] = (int32_T)unnamed_idx_0;
  emxEnsureCapacity((emxArray__common *)f, i0, (int32_T)sizeof(creal_T));
  i0 = f->size[0];
  for (c_k = 0; c_k + 1 <= i0; c_k++) {
    if (b_eml_relop(y->data[c_k], ath, TRUE) || rtIsNaN(y->data[c_k])) {
      b_a = ath.re;
      b = ath.im;
    } else {
      b_a = y->data[c_k];
      b = 0.0;
    }

    f->data[c_k].re = b_a;
    f->data[c_k].im = b;
  }

  emxFree_real_T(&y);
  i0 = pw->size[0];
  pw->size[0] = f->size[0];
  emxEnsureCapacity((emxArray__common *)pw, i0, (int32_T)sizeof(creal_T));
  ar = f->size[0] - 1;
  for (i0 = 0; i0 <= ar; i0++) {
    pw->data[i0] = f->data[i0];
  }

  for (c_k = 0; c_k <= f->size[0] - 1; c_k++) {
    ath = pw->data[c_k];
    if ((pw->data[c_k].im == 0.0) && rtIsNaN(pw->data[c_k].re)) {
    } else if ((fabs(pw->data[c_k].re) > 8.9884656743115785E+307) || (fabs
                (pw->data[c_k].im) > 8.9884656743115785E+307)) {
      b_a = fabs(pw->data[c_k].re / 2.0);
      b = fabs(pw->data[c_k].im / 2.0);
      if (b_a < b) {
        b_a /= b;
        b *= sqrt(b_a * b_a + 1.0);
      } else if (b_a > b) {
        b /= b_a;
        b = sqrt(b * b + 1.0) * b_a;
      } else if (rtIsNaN(b)) {
      } else {
        b = b_a * 1.4142135623730951;
      }

      ath.re = log(b) + 0.69314718055994529;
      ath.im = rt_atan2d_snf(pw->data[c_k].im, pw->data[c_k].re);
    } else {
      b_a = fabs(pw->data[c_k].re);
      b = fabs(pw->data[c_k].im);
      if (b_a < b) {
        b_a /= b;
        b *= sqrt(b_a * b_a + 1.0);
      } else if (b_a > b) {
        b /= b_a;
        b = sqrt(b * b + 1.0) * b_a;
      } else if (rtIsNaN(b)) {
      } else {
        b = b_a * 1.4142135623730951;
      }

      ath.re = log(b);
      ath.im = rt_atan2d_snf(pw->data[c_k].im, pw->data[c_k].re);
    }

    pw->data[c_k] = ath;
  }

  emxFree_creal_T(&f);
  a_rdct(pw, b_b);
  i0 = c->size[0] * c->size[1];
  c->size[0] = 1;
  emxEnsureCapacity((emxArray__common *)c, i0, (int32_T)sizeof(real_T));
  i = b_b->size[0];
  i0 = c->size[0] * c->size[1];
  c->size[1] = i;
  emxEnsureCapacity((emxArray__common *)c, i0, (int32_T)sizeof(real_T));
  emxFree_creal_T(&pw);
  ar = b_b->size[0] - 1;
  for (i0 = 0; i0 <= ar; i0++) {
    c->data[i0] = b_b->data[i0];
  }

  emxFree_real_T(&b_b);
  i2 = (int64_T)nc + 1L;
  if (i2 > 2147483647L) {
    i2 = 2147483647L;
  } else {
    if (i2 < -2147483648L) {
      i2 = -2147483648L;
    }
  }

  nc = (int32_T)i2;
  if (32 > nc) {
    b_emxInit_int32_T(&r0, 1);
    i0 = c->size[1];
    i1 = r0->size[0];
    r0->size[0] = i0 - nc;
    emxEnsureCapacity((emxArray__common *)r0, i1, (int32_T)sizeof(int32_T));
    ar = (i0 - nc) - 1;
    for (i0 = 0; i0 <= ar; i0++) {
      r0->data[i0] = (nc + i0) + 1;
    }

    emxInit_int32_T(&idx, 2);
    i0 = idx->size[0] * idx->size[1];
    idx->size[0] = 1;
    emxEnsureCapacity((emxArray__common *)idx, i0, (int32_T)sizeof(int32_T));
    i = r0->size[0];
    i0 = idx->size[0] * idx->size[1];
    idx->size[1] = i;
    emxEnsureCapacity((emxArray__common *)idx, i0, (int32_T)sizeof(int32_T));
    ar = r0->size[0] - 1;
    for (i0 = 0; i0 <= ar; i0++) {
      idx->data[i0] = r0->data[i0];
    }

    emxFree_int32_T(&r0);
    if (idx->size[1] == 1) {
      i = c->size[1] - 1;
      for (ar = idx->data[0]; ar <= i; ar++) {
        c->data[c->size[0] * (ar - 1)] = c->data[c->size[0] * ar];
      }
    } else {
      emxInit_boolean_T(&c_b, 2);
      i0 = c_b->size[0] * c_b->size[1];
      c_b->size[0] = 1;
      emxEnsureCapacity((emxArray__common *)c_b, i0, (int32_T)sizeof(boolean_T));
      i = c->size[1];
      i0 = c_b->size[0] * c_b->size[1];
      c_b->size[1] = i;
      emxEnsureCapacity((emxArray__common *)c_b, i0, (int32_T)sizeof(boolean_T));
      ar = c->size[1] - 1;
      for (i0 = 0; i0 <= ar; i0++) {
        c_b->data[i0] = FALSE;
      }

      for (c_k = 1; c_k <= idx->size[1]; c_k++) {
        c_b->data[idx->data[c_k - 1] - 1] = TRUE;
      }

      i = 0;
      for (c_k = 1; c_k <= c_b->size[1]; c_k++) {
        ia = c_b->data[c_k - 1];
        i += ia;
      }

      i = c->size[1] - i;
      br = c_b->size[1];
      ar = 0;
      i0 = c->size[1];
      for (c_k = 1; c_k <= i0; c_k++) {
        if ((c_k > br) || (!c_b->data[c_k - 1])) {
          c->data[c->size[0] * ar] = c->data[c->size[0] * (c_k - 1)];
          ar++;
        }
      }

      emxFree_boolean_T(&c_b);
    }

    emxFree_int32_T(&idx);
    if (1 > i) {
      i = 0;
    }

    emxInit_real_T(&b_c, 2);
    i0 = b_c->size[0] * b_c->size[1];
    b_c->size[0] = 1;
    b_c->size[1] = i;
    emxEnsureCapacity((emxArray__common *)b_c, i0, (int32_T)sizeof(real_T));
    ar = i - 1;
    for (i0 = 0; i0 <= ar; i0++) {
      b_c->data[b_c->size[0] * i0] = c->data[c->size[0] * i0];
    }

    i0 = c->size[0] * c->size[1];
    c->size[0] = 1;
    c->size[1] = b_c->size[1];
    emxEnsureCapacity((emxArray__common *)c, i0, (int32_T)sizeof(real_T));
    ar = b_c->size[1] - 1;
    for (i0 = 0; i0 <= ar; i0++) {
      c->data[c->size[0] * i0] = b_c->data[b_c->size[0] * i0];
    }

    emxFree_real_T(&b_c);
  } else {
    if (32 < nc) {
      emxInit_real_T(&b_c, 2);
      i = nc - 32;
      i0 = b_c->size[0] * b_c->size[1];
      b_c->size[0] = 1;
      b_c->size[1] = c->size[1] + i;
      emxEnsureCapacity((emxArray__common *)b_c, i0, (int32_T)sizeof(real_T));
      ar = c->size[1] - 1;
      for (i0 = 0; i0 <= ar; i0++) {
        b_c->data[b_c->size[0] * i0] = c->data[c->size[0] * i0];
      }

      ar = i - 1;
      for (i0 = 0; i0 <= ar; i0++) {
        b_c->data[b_c->size[0] * (i0 + c->size[1])] = 0.0;
      }

      i0 = c->size[0] * c->size[1];
      c->size[0] = 1;
      c->size[1] = b_c->size[1];
      emxEnsureCapacity((emxArray__common *)c, i0, (int32_T)sizeof(real_T));
      ar = b_c->size[1] - 1;
      for (i0 = 0; i0 <= ar; i0++) {
        c->data[c->size[0] * i0] = b_c->data[b_c->size[0] * i0];
      }

      emxFree_real_T(&b_c);
    }
  }

  i = c->size[1] - 1;
  for (ar = 1; ar <= i; ar++) {
    c->data[c->size[0] * (ar - 1)] = c->data[c->size[0] * ar];
  }

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

  emxInit_real_T(&c_c, 2);
  i0 = c_c->size[0] * c_c->size[1];
  c_c->size[0] = 1;
  c_c->size[1] = i;
  emxEnsureCapacity((emxArray__common *)c_c, i0, (int32_T)sizeof(real_T));
  ar = i - 1;
  for (i0 = 0; i0 <= ar; i0++) {
    c_c->data[c_c->size[0] * i0] = c->data[c->size[0] * i0];
  }

  i0 = c->size[0] * c->size[1];
  c->size[0] = 1;
  c->size[1] = c_c->size[1];
  emxEnsureCapacity((emxArray__common *)c, i0, (int32_T)sizeof(real_T));
  ar = c_c->size[1] - 1;
  for (i0 = 0; i0 <= ar; i0++) {
    c->data[c->size[0] * i0] = c_c->data[c_c->size[0] * i0];
  }

  emxFree_real_T(&c_c);
}
Esempio n. 10
0
/*
 * Fs -  Sampling frequency
 * Arguments    : double Fs
 *                emxArray_real_T *data
 *                emxArray_real_T *f
 *                emxArray_real_T *YY
 * Return Type  : void
 */
void spectral(double Fs, emxArray_real_T *data, emxArray_real_T *f,
              emxArray_real_T *YY)
{
  emxArray_boolean_T *b;
  int nxin;
  int k0;
  int nrowx;
  int nxout;
  int k;
  emxArray_real_T *b_data;
  int eint;
  double fdbl;
  double delta1;
  emxArray_creal_T *Y;
  double NFFT;
  emxArray_creal_T *x;
  emxInit_boolean_T(&b, 1);
  nxin = b->size[0];
  b->size[0] = data->size[0];
  emxEnsureCapacity((emxArray__common *)b, nxin, (int)sizeof(boolean_T));
  k0 = data->size[0];
  for (nxin = 0; nxin < k0; nxin++) {
    b->data[nxin] = rtIsNaN(data->data[nxin]);
  }

  nxin = data->size[0];
  nrowx = data->size[0];
  nxout = 0;
  for (k = 1; k <= b->size[0]; k++) {
    nxout += b->data[k - 1];
  }

  nxout = data->size[0] - nxout;
  k0 = -1;
  for (k = 1; k <= nxin; k++) {
    if ((k > b->size[0]) || (!b->data[k - 1])) {
      k0++;
      data->data[k0] = data->data[k - 1];
    }
  }

  emxFree_boolean_T(&b);
  if (nrowx != 1) {
    if (1 > nxout) {
      k0 = 0;
    } else {
      k0 = nxout;
    }

    emxInit_real_T(&b_data, 1);
    nxin = b_data->size[0];
    b_data->size[0] = k0;
    emxEnsureCapacity((emxArray__common *)b_data, nxin, (int)sizeof(double));
    for (nxin = 0; nxin < k0; nxin++) {
      b_data->data[nxin] = data->data[nxin];
    }

    nxin = data->size[0];
    data->size[0] = b_data->size[0];
    emxEnsureCapacity((emxArray__common *)data, nxin, (int)sizeof(double));
    k0 = b_data->size[0];
    for (nxin = 0; nxin < k0; nxin++) {
      data->data[nxin] = b_data->data[nxin];
    }

    emxFree_real_T(&b_data);
  } else {
    nxin = data->size[0];
    if (1 > nxout) {
      data->size[0] = 0;
    } else {
      data->size[0] = nxout;
    }

    emxEnsureCapacity((emxArray__common *)data, nxin, (int)sizeof(double));
  }

  fdbl = frexp(data->size[0], &eint);
  delta1 = eint;
  if (fdbl == 0.5) {
    delta1 = (double)eint - 1.0;
  }

  emxInit_creal_T(&Y, 1);
  NFFT = rt_powd_snf(2.0, delta1);

  /*  Next power of 2 from length of y */
  fft(data, NFFT, Y);
  nxout = data->size[0];
  nxin = Y->size[0];
  emxEnsureCapacity((emxArray__common *)Y, nxin, (int)sizeof(creal_T));
  k0 = Y->size[0];
  for (nxin = 0; nxin < k0; nxin++) {
    fdbl = Y->data[nxin].re;
    delta1 = Y->data[nxin].im;
    if (delta1 == 0.0) {
      Y->data[nxin].re = fdbl / (double)nxout;
      Y->data[nxin].im = 0.0;
    } else if (fdbl == 0.0) {
      Y->data[nxin].re = 0.0;
      Y->data[nxin].im = delta1 / (double)nxout;
    } else {
      Y->data[nxin].re = fdbl / (double)nxout;
      Y->data[nxin].im = delta1 / (double)nxout;
    }
  }

  fdbl = Fs / 2.0;
  nxin = f->size[0] * f->size[1];
  f->size[0] = 1;
  f->size[1] = (int)floor(NFFT / 2.0 + 1.0);
  emxEnsureCapacity((emxArray__common *)f, nxin, (int)sizeof(double));
  f->data[f->size[1] - 1] = 1.0;
  if (f->size[1] >= 2) {
    f->data[0] = 0.0;
    if (f->size[1] >= 3) {
      delta1 = 1.0 / ((double)f->size[1] - 1.0);
      nxin = f->size[1];
      for (k = 0; k <= nxin - 3; k++) {
        f->data[1 + k] = (1.0 + (double)k) * delta1;
      }
    }
  }

  nxin = f->size[0] * f->size[1];
  f->size[0] = 1;
  emxEnsureCapacity((emxArray__common *)f, nxin, (int)sizeof(double));
  nxout = f->size[0];
  k0 = f->size[1];
  k0 *= nxout;
  for (nxin = 0; nxin < k0; nxin++) {
    f->data[nxin] *= fdbl;
  }

  emxInit_creal_T(&x, 1);
  fdbl = NFFT / 2.0 + 1.0;
  k0 = (int)(NFFT / 2.0 + 1.0);
  nxin = x->size[0];
  x->size[0] = k0;
  emxEnsureCapacity((emxArray__common *)x, nxin, (int)sizeof(creal_T));
  for (nxin = 0; nxin < k0; nxin++) {
    x->data[nxin] = Y->data[nxin];
  }

  emxFree_creal_T(&Y);
  nxin = YY->size[0];
  YY->size[0] = (int)fdbl;
  emxEnsureCapacity((emxArray__common *)YY, nxin, (int)sizeof(double));
  for (k = 0; k + 1 <= (int)fdbl; k++) {
    YY->data[k] = rt_hypotd_snf(x->data[k].re, x->data[k].im);
  }

  emxFree_creal_T(&x);
  nxin = YY->size[0];
  emxEnsureCapacity((emxArray__common *)YY, nxin, (int)sizeof(double));
  k0 = YY->size[0];
  for (nxin = 0; nxin < k0; nxin++) {
    YY->data[nxin] *= 2.0;
  }

  /*  figure; */
  /*  plot(f,2*abs(Y(1:NFFT/2+1))); */
  /*  L = length(data);                                                 % Length of signal */
  /*  NFFT = 2^nextpow2(L); */
  /*  f = Fs/2*linspace(0,1,NFFT/2+1); */
  /*  figure(1) */
  /*  Y = fft(data,NFFT)/L; */
  /*  % Plot single-sided amplitude spectrum. */
  /*  plot(f,2*abs(Y(1:NFFT/2+1)))                                        % 船首向信号谱分析 */
  /*  set(gca,'xlim',[0.005 0.5],'ylimmode','auto');  */
  /*  title('艏向快速傅里叶变换'); */
  /*  xlabel('频率/Hz'); */
  /*  ylabel('功率'); */
  /*  box off */
}