void julia_v4_1_api(const mxArray * const prhs[3], const mxArray *plhs[2]) { emxArray_creal_T *vz; emxArray_real_T *iter; creal_T c; real_T maxiter; emlrtHeapReferenceStackEnterFcnR2012b(emlrtRootTLSGlobal); emxInit_creal_T(&vz, 2, &c_emlrtRTEI, TRUE); emxInit_real_T(&iter, 2, &c_emlrtRTEI, TRUE); /* Marshall function inputs */ emlrt_marshallIn(emlrtAliasP(prhs[0]), "vz", vz); c = c_emlrt_marshallIn(emlrtAliasP(prhs[1]), "c"); maxiter = e_emlrt_marshallIn(emlrtAliasP(prhs[2]), "maxiter"); /* Invoke the target function */ julia_v4_1(vz, c, maxiter, iter); /* Marshall function outputs */ plhs[0] = emlrt_marshallOut(iter); plhs[1] = b_emlrt_marshallOut(vz); iter->canFreeData = FALSE; emxFree_real_T(&iter); emxFree_creal_T(&vz); emlrtHeapReferenceStackLeaveFcnR2012b(emlrtRootTLSGlobal); }
/* Function Definitions */ static void b_equalizeOFDM(testMACRouterStackData *SD, const emlrtStack *sp, const creal_T recv_data[1280], const real_T tx_longPreamble[53], const real_T tx_pilots[48], const real_T c_tx_pilotLocationsWithoutGuard[4], const real_T tx_dataSubcarrierIndexies_data[48], const int32_T tx_dataSubcarrierIndexies_size[2], c_struct_T *estimate, OFDMDemodulator_1 *hPreambleDemod, OFDMDemodulator_1 *hDataDemod, creal_T R[576], emxArray_creal_T *Rraw) { OFDMDemodulator_1 *obj; const mxArray *y; static const int32_T iv198[2] = { 1, 45 }; const mxArray *m49; char_T cv241[45]; int32_T i; static const char_T cv242[45] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'y', 's', 't', 'e', 'm', ':', 'm', 'e', 't', 'h', 'o', 'd', 'C', 'a', 'l', 'l', 'e', 'd', 'W', 'h', 'e', 'n', 'R', 'e', 'l', 'e', 'a', 's', 'e', 'd', 'C', 'o', 'd', 'e', 'g', 'e', 'n' }; const mxArray *b_y; static const int32_T iv199[2] = { 1, 4 }; char_T cv243[4]; static const char_T cv244[4] = { 's', 't', 'e', 'p' }; const mxArray *c_y; static const int32_T iv200[2] = { 1, 51 }; char_T cv245[51]; static const char_T cv246[51] = { 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'y', 's', 't', 'e', 'm', ':', 'm', 'e', 't', 'h', 'o', 'd', 'C', 'a', 'l', 'l', 'e', 'd', 'W', 'h', 'e', 'n', 'L', 'o', 'c', 'k', 'e', 'd', 'R', 'e', 'l', 'e', 'a', 's', 'e', 'd', 'C', 'o', 'd', 'e', 'g', 'e', 'n' }; const mxArray *d_y; static const int32_T iv201[2] = { 1, 5 }; char_T cv247[5]; static const char_T cv248[5] = { 's', 'e', 't', 'u', 'p' }; int8_T fullGrid[64]; int32_T k; static const int8_T iv202[11] = { 0, 1, 2, 3, 4, 5, 59, 60, 61, 62, 63 }; int8_T ii_data[64]; int32_T ii; boolean_T exitg2; boolean_T guard2 = FALSE; int8_T b_ii_data[64]; creal_T recv[64]; emxArray_creal_T *RLongFirst; const mxArray *e_y; static const int32_T iv203[2] = { 1, 45 }; const mxArray *f_y; static const int32_T iv204[2] = { 1, 4 }; const mxArray *g_y; static const int32_T iv205[2] = { 1, 51 }; const mxArray *h_y; static const int32_T iv206[2] = { 1, 5 }; boolean_T exitg1; boolean_T guard1 = FALSE; creal_T b_recv[64]; emxArray_creal_T *RLongSecond; emxArray_creal_T *b_R; creal_T c_R[106]; real_T b_tx_longPreamble[106]; creal_T RNormal[106]; real_T dv13[106]; real_T dv14[106]; real_T REnergy[53]; creal_T RConj[53]; creal_T b_RConj[53]; const mxArray *i_y; static const int32_T iv207[2] = { 1, 45 }; const mxArray *j_y; static const int32_T iv208[2] = { 1, 4 }; const mxArray *k_y; static const int32_T iv209[2] = { 1, 51 }; const mxArray *l_y; static const int32_T iv210[2] = { 1, 5 }; int8_T b_fullGrid[768]; static const int16_T iv211[48] = { 11, 25, 39, 53, 75, 89, 103, 117, 139, 153, 167, 181, 203, 217, 231, 245, 267, 281, 295, 309, 331, 345, 359, 373, 395, 409, 423, 437, 459, 473, 487, 501, 523, 537, 551, 565, 587, 601, 615, 629, 651, 665, 679, 693, 715, 729, 743, 757 }; boolean_T c_fullGrid[768]; int32_T ii_size[1]; int32_T c_ii_data[768]; real_T d_ii_data[768]; int32_T b_ii_size[1]; creal_T RXPilots[48]; creal_T preambleGainsFull[636]; int32_T ia; int32_T iv212[3]; static const int8_T iv213[3] = { 48, 12, 1 }; int32_T b_Rraw[3]; creal_T PilotNormal[48]; real_T pilotEqGains_re; real_T pilotEqGains_im; real_T a[48]; real_T PilotEnergy[48]; creal_T b_PilotNormal[48]; creal_T pilotEqGains[576]; creal_T preambleGainsFull_data[576]; creal_T b_preambleGainsFull_data[576]; creal_T c_preambleGainsFull_data[576]; real_T preambleGainsFull_data_re; real_T preambleGainsFull_data_im; emlrtStack st; emlrtStack b_st; emlrtStack c_st; emlrtStack d_st; st.prev = sp; st.tls = sp->tls; b_st.prev = &st; b_st.tls = st.tls; c_st.prev = &b_st; c_st.tls = b_st.tls; d_st.prev = &c_st; d_st.tls = c_st.tls; emlrtHeapReferenceStackEnterFcnR2012b(sp); /* equalizeOFDM: Equalize the entire OFDM frame through the use of both */ /* the long preamble from the 802.11a standard and four pilot tones in */ /* the data frames themselves. The gains from the pilots are */ /* interpolated across frequency to fill the data frame and apply gains */ /* to all data subcarriers. */ /* %% Use Long Preamble frame to estimate channel in frequency domain */ /* Separate out received preambles */ emlrtVectorVectorIndexCheckR2012b(1280, 1, 1, 160, &y_emlrtECI, sp); /* Demod */ st.site = &xr_emlrtRSI; obj = hPreambleDemod; if (!obj->isReleased) { } else { y = NULL; m49 = mxCreateCharArray(2, iv198); for (i = 0; i < 45; i++) { cv241[i] = cv242[i]; } emlrtInitCharArrayR2013a(&st, 45, m49, cv241); emlrtAssign(&y, m49); b_y = NULL; m49 = mxCreateCharArray(2, iv199); for (i = 0; i < 4; i++) { cv243[i] = cv244[i]; } emlrtInitCharArrayR2013a(&st, 4, m49, cv243); emlrtAssign(&b_y, m49); b_st.site = &cb_emlrtRSI; c_error(&b_st, message(&b_st, y, b_y, &emlrtMCI), &emlrtMCI); } if (!obj->isInitialized) { b_st.site = &cb_emlrtRSI; if (!obj->isInitialized) { } else { c_y = NULL; m49 = mxCreateCharArray(2, iv200); for (i = 0; i < 51; i++) { cv245[i] = cv246[i]; } emlrtInitCharArrayR2013a(&b_st, 51, m49, cv245); emlrtAssign(&c_y, m49); d_y = NULL; m49 = mxCreateCharArray(2, iv201); for (i = 0; i < 5; i++) { cv247[i] = cv248[i]; } emlrtInitCharArrayR2013a(&b_st, 5, m49, cv247); emlrtAssign(&d_y, m49); c_st.site = &cb_emlrtRSI; c_error(&c_st, message(&c_st, c_y, d_y, &emlrtMCI), &emlrtMCI); } c_st.site = &cb_emlrtRSI; obj->isInitialized = TRUE; d_st.site = &db_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; memset(&fullGrid[0], 1, sizeof(int8_T) << 6); for (k = 0; k < 11; k++) { fullGrid[iv202[k]] = 0; } d_st.site = &fs_emlrtRSI; i = 0; ii = 1; exitg2 = FALSE; while ((exitg2 == FALSE) && (ii < 65)) { guard2 = FALSE; if (fullGrid[ii - 1] == 1) { i++; ii_data[i - 1] = (int8_T)ii; if (i >= 64) { exitg2 = TRUE; } else { guard2 = TRUE; } } else { guard2 = TRUE; } if (guard2 == TRUE) { ii++; } } if (1 > i) { i = 0; } for (k = 0; k < i; k++) { b_ii_data[k] = ii_data[k]; } for (k = 0; k < i; k++) { ii_data[k] = b_ii_data[k]; } d_st.site = &fs_emlrtRSI; k = obj->pDataLinearIndices->size[0]; obj->pDataLinearIndices->size[0] = i; emxEnsureCapacity(&d_st, (emxArray__common *)obj->pDataLinearIndices, k, (int32_T)sizeof(real_T), &pb_emlrtRTEI); for (k = 0; k < i; k++) { obj->pDataLinearIndices->data[k] = ii_data[k]; } c_st.site = &cb_emlrtRSI; } b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; memcpy(&recv[0], &recv_data[192], sizeof(creal_T) << 6); emxInit_creal_T(&st, &RLongFirst, 3, &yb_emlrtRTEI, TRUE); b_st.site = &cb_emlrtRSI; OFDMDemodulator_stepImpl(&b_st, obj, recv, RLongFirst); /* First half of long preamble */ st.site = &yr_emlrtRSI; obj = hPreambleDemod; if (!obj->isReleased) { } else { e_y = NULL; m49 = mxCreateCharArray(2, iv203); for (i = 0; i < 45; i++) { cv241[i] = cv242[i]; } emlrtInitCharArrayR2013a(&st, 45, m49, cv241); emlrtAssign(&e_y, m49); f_y = NULL; m49 = mxCreateCharArray(2, iv204); for (i = 0; i < 4; i++) { cv243[i] = cv244[i]; } emlrtInitCharArrayR2013a(&st, 4, m49, cv243); emlrtAssign(&f_y, m49); b_st.site = &cb_emlrtRSI; c_error(&b_st, message(&b_st, e_y, f_y, &emlrtMCI), &emlrtMCI); } if (!obj->isInitialized) { b_st.site = &cb_emlrtRSI; if (!obj->isInitialized) { } else { g_y = NULL; m49 = mxCreateCharArray(2, iv205); for (i = 0; i < 51; i++) { cv245[i] = cv246[i]; } emlrtInitCharArrayR2013a(&b_st, 51, m49, cv245); emlrtAssign(&g_y, m49); h_y = NULL; m49 = mxCreateCharArray(2, iv206); for (i = 0; i < 5; i++) { cv247[i] = cv248[i]; } emlrtInitCharArrayR2013a(&b_st, 5, m49, cv247); emlrtAssign(&h_y, m49); c_st.site = &cb_emlrtRSI; c_error(&c_st, message(&c_st, g_y, h_y, &emlrtMCI), &emlrtMCI); } c_st.site = &cb_emlrtRSI; obj->isInitialized = TRUE; d_st.site = &db_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; memset(&fullGrid[0], 1, sizeof(int8_T) << 6); for (k = 0; k < 11; k++) { fullGrid[iv202[k]] = 0; } d_st.site = &fs_emlrtRSI; i = 0; ii = 1; exitg1 = FALSE; while ((exitg1 == FALSE) && (ii < 65)) { guard1 = FALSE; if (fullGrid[ii - 1] == 1) { i++; ii_data[i - 1] = (int8_T)ii; if (i >= 64) { exitg1 = TRUE; } else { guard1 = TRUE; } } else { guard1 = TRUE; } if (guard1 == TRUE) { ii++; } } if (1 > i) { i = 0; } for (k = 0; k < i; k++) { b_ii_data[k] = ii_data[k]; } for (k = 0; k < i; k++) { ii_data[k] = b_ii_data[k]; } d_st.site = &fs_emlrtRSI; k = obj->pDataLinearIndices->size[0]; obj->pDataLinearIndices->size[0] = i; emxEnsureCapacity(&d_st, (emxArray__common *)obj->pDataLinearIndices, k, (int32_T)sizeof(real_T), &pb_emlrtRTEI); for (k = 0; k < i; k++) { obj->pDataLinearIndices->data[k] = ii_data[k]; } c_st.site = &cb_emlrtRSI; } b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; memcpy(&b_recv[0], &recv_data[256], sizeof(creal_T) << 6); emxInit_creal_T(&st, &RLongSecond, 3, &ac_emlrtRTEI, TRUE); emxInit_creal_T(&st, &b_R, 3, &pb_emlrtRTEI, TRUE); b_st.site = &cb_emlrtRSI; OFDMDemodulator_stepImpl(&b_st, obj, b_recv, RLongSecond); /* Second half of long preamble */ /* %% Preamble Equalization */ /* Get Equalizer tap gains */ k = RLongFirst->size[0]; ii = RLongSecond->size[0]; emlrtDimSizeEqCheckFastR2012b(k, ii, &x_emlrtECI, sp); st.site = &as_emlrtRSI; k = b_R->size[0] * b_R->size[1] * b_R->size[2]; b_R->size[0] = RLongFirst->size[0]; b_R->size[1] = 2; b_R->size[2] = 1; emxEnsureCapacity(&st, (emxArray__common *)b_R, k, (int32_T)sizeof(creal_T), &pb_emlrtRTEI); i = RLongFirst->size[0]; for (k = 0; k < i; k++) { b_R->data[k] = RLongFirst->data[k]; } emxFree_creal_T(&RLongFirst); i = RLongSecond->size[0]; for (k = 0; k < i; k++) { b_R->data[k + b_R->size[0]] = RLongSecond->data[k]; } emxFree_creal_T(&RLongSecond); /* Calculate Equalizer Taps with preamble symbols */ /* Calculate non-normalized channel gains */ for (k = 0; k < 53; k++) { ii = b_R->size[0]; i = 1 + k; emlrtDynamicBoundsCheckFastR2012b(i, 1, ii, &lb_emlrtBCI, &st); } i = b_R->size[0]; for (k = 0; k < 2; k++) { for (ii = 0; ii < 53; ii++) { c_R[ii + 53 * k] = b_R->data[ii + i * k]; } } emxFree_creal_T(&b_R); for (k = 0; k < 53; k++) { b_tx_longPreamble[k] = tx_longPreamble[k]; b_tx_longPreamble[53 + k] = tx_longPreamble[k]; } b_st.site = &bt_emlrtRSI; b_rdivide(c_R, b_tx_longPreamble, RNormal); /* Known is the original Long Preamble symbols */ /* Scale channel gains */ b_st.site = &ct_emlrtRSI; d_abs(RNormal, dv13); memcpy(&dv14[0], &dv13[0], 106U * sizeof(real_T)); b_st.site = &ct_emlrtRSI; b_power(dv14, dv13); b_st.site = &ct_emlrtRSI; c_mean(dv13, REnergy); b_st.site = &dt_emlrtRSI; d_mean(RNormal, RConj); for (k = 0; k < 53; k++) { RConj[k].im = -RConj[k].im; b_RConj[k] = RConj[k]; } b_st.site = &et_emlrtRSI; c_rdivide(b_RConj, REnergy, RConj); /* Separate data from preambles */ /* recvData = recv(length(tx.preambles)+1:length(tx.preambles)+(hDataDemod.NumSymbols)*(tx.FFTLength+hDataDemod.CyclicPrefixLength)); */ emlrtVectorVectorIndexCheckR2012b(1280, 1, 1, 960, &w_emlrtECI, sp); /* CG */ /* OFDM Demod */ st.site = &bs_emlrtRSI; obj = hDataDemod; if (!obj->isReleased) { } else { i_y = NULL; m49 = mxCreateCharArray(2, iv207); for (i = 0; i < 45; i++) { cv241[i] = cv242[i]; } emlrtInitCharArrayR2013a(&st, 45, m49, cv241); emlrtAssign(&i_y, m49); j_y = NULL; m49 = mxCreateCharArray(2, iv208); for (i = 0; i < 4; i++) { cv243[i] = cv244[i]; } emlrtInitCharArrayR2013a(&st, 4, m49, cv243); emlrtAssign(&j_y, m49); b_st.site = &cb_emlrtRSI; c_error(&b_st, message(&b_st, i_y, j_y, &emlrtMCI), &emlrtMCI); } if (!obj->isInitialized) { b_st.site = &cb_emlrtRSI; if (!obj->isInitialized) { } else { k_y = NULL; m49 = mxCreateCharArray(2, iv209); for (i = 0; i < 51; i++) { cv245[i] = cv246[i]; } emlrtInitCharArrayR2013a(&b_st, 51, m49, cv245); emlrtAssign(&k_y, m49); l_y = NULL; m49 = mxCreateCharArray(2, iv210); for (i = 0; i < 5; i++) { cv247[i] = cv248[i]; } emlrtInitCharArrayR2013a(&b_st, 5, m49, cv247); emlrtAssign(&l_y, m49); c_st.site = &cb_emlrtRSI; c_error(&c_st, message(&c_st, k_y, l_y, &emlrtMCI), &emlrtMCI); } c_st.site = &cb_emlrtRSI; g_SystemProp_matlabCodegenSetAn(obj); c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_SystemCore_validateProperties(); c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; d_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; memset(&b_fullGrid[0], 1, 768U * sizeof(int8_T)); for (k = 0; k < 12; k++) { for (ii = 0; ii < 11; ii++) { b_fullGrid[iv202[ii] + (k << 6)] = 0; } b_fullGrid[32 + (k << 6)] = 0; } d_st.site = &st_emlrtRSI; d_st.site = &st_emlrtRSI; for (k = 0; k < 48; k++) { b_fullGrid[iv211[k]] = 2; } d_st.site = &fs_emlrtRSI; for (k = 0; k < 768; k++) { c_fullGrid[k] = (b_fullGrid[k] == 1); } eml_find(c_fullGrid, c_ii_data, ii_size); b_ii_size[0] = ii_size[0]; i = ii_size[0]; for (k = 0; k < i; k++) { d_ii_data[k] = c_ii_data[k]; } d_st.site = &fs_emlrtRSI; h_SystemProp_matlabCodegenSetAn(&d_st, obj, d_ii_data, b_ii_size); c_st.site = &cb_emlrtRSI; } b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; c_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_st.site = &cb_emlrtRSI; b_OFDMDemodulator_stepImpl(SD, &b_st, obj, *(creal_T (*)[960])&recv_data[320], Rraw, RXPilots); /* Expand equalizer gains to full frame size */ st.site = &cs_emlrtRSI; i = 0; for (ii = 0; ii < 12; ii++) { ia = 0; for (k = 0; k < 53; k++) { preambleGainsFull[i] = RConj[ia]; b_st.site = &ng_emlrtRSI; ia++; b_st.site = &og_emlrtRSI; i++; } } /* Isolate pilot gains from preamble equalizer */ /* Needed to correctly adjust pilot gains */ /* Apply preamble equalizer gains to data and pilots */ /* Correct pilots */ for (i = 0; i < 3; i++) { iv212[i] = iv213[i]; } for (k = 0; k < 3; k++) { b_Rraw[k] = Rraw->size[k]; } emlrtSizeEqCheckNDR2012b(iv212, b_Rraw, &v_emlrtECI, sp); /* Correct data */ /* %% Pilot Equalization */ /* Get pilot-based equalizer gains */ st.site = &ds_emlrtRSI; /* Calculate Equalizer Taps with pilot symbols */ /* Calculate non-normalized channel gains */ b_st.site = &vt_emlrtRSI; c_st.site = &k_emlrtRSI; for (k = 0; k < 12; k++) { for (ii = 0; ii < 4; ii++) { pilotEqGains_re = preambleGainsFull[((int32_T) c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].re * RXPilots[ii + (k << 2)].re - preambleGainsFull[((int32_T) c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].im * RXPilots[ii + (k << 2)].im; pilotEqGains_im = preambleGainsFull[((int32_T) c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].re * RXPilots[ii + (k << 2)].im + preambleGainsFull[((int32_T) c_tx_pilotLocationsWithoutGuard[ii] + 53 * k) - 1].im * RXPilots[ii + (k << 2)].re; if (pilotEqGains_im == 0.0) { PilotNormal[ii + (k << 2)].re = pilotEqGains_re / tx_pilots[ii + (k << 2)]; PilotNormal[ii + (k << 2)].im = 0.0; } else if (pilotEqGains_re == 0.0) { PilotNormal[ii + (k << 2)].re = 0.0; PilotNormal[ii + (k << 2)].im = pilotEqGains_im / tx_pilots[ii + (k << 2)]; } else { PilotNormal[ii + (k << 2)].re = pilotEqGains_re / tx_pilots[ii + (k << 2)]; PilotNormal[ii + (k << 2)].im = pilotEqGains_im / tx_pilots[ii + (k << 2)]; } } } /* Scale channel gains */ b_st.site = &wt_emlrtRSI; for (k = 0; k < 48; k++) { c_st.site = &qc_emlrtRSI; d_st.site = &co_emlrtRSI; a[k] = muDoubleScalarHypot(PilotNormal[k].re, PilotNormal[k].im); } b_st.site = &wt_emlrtRSI; c_st.site = &n_emlrtRSI; d_st.site = &hp_emlrtRSI; for (k = 0; k < 48; k++) { d_st.site = &o_emlrtRSI; PilotEnergy[k] = a[k] * a[k]; } b_st.site = &xt_emlrtRSI; c_st.site = &k_emlrtRSI; /* Interpolate to data carrier size */ for (k = 0; k < 48; k++) { if (-PilotNormal[k].im == 0.0) { b_PilotNormal[k].re = PilotNormal[k].re / PilotEnergy[k]; b_PilotNormal[k].im = 0.0; } else if (PilotNormal[k].re == 0.0) { b_PilotNormal[k].re = 0.0; b_PilotNormal[k].im = -PilotNormal[k].im / PilotEnergy[k]; } else { b_PilotNormal[k].re = PilotNormal[k].re / PilotEnergy[k]; b_PilotNormal[k].im = -PilotNormal[k].im / PilotEnergy[k]; } } b_st.site = &yt_emlrtRSI; resample(SD, &b_st, b_PilotNormal, pilotEqGains); /* Apply Equalizer from Pilots */ for (k = 0; k < 12; k++) { for (ii = 0; ii < 48; ii++) { preambleGainsFull_data[ii + 48 * k] = preambleGainsFull[((int32_T) tx_dataSubcarrierIndexies_data[tx_dataSubcarrierIndexies_size[0] * ii] + 53 * k) - 1]; } } for (k = 0; k < 12; k++) { memcpy(&b_preambleGainsFull_data[48 * k], &preambleGainsFull_data[48 * k], 48U * sizeof(creal_T)); } i = Rraw->size[0]; for (k = 0; k < 12; k++) { for (ii = 0; ii < 48; ii++) { c_preambleGainsFull_data[ii + 48 * k].re = b_preambleGainsFull_data[ii + 48 * k].re * Rraw->data[ii + i * k].re - b_preambleGainsFull_data[ii + 48 * k].im * Rraw->data[ii + i * k].im; c_preambleGainsFull_data[ii + 48 * k].im = b_preambleGainsFull_data[ii + 48 * k].re * Rraw->data[ii + i * k].im + b_preambleGainsFull_data[ii + 48 * k].im * Rraw->data[ii + i * k].re; } } for (k = 0; k < 12; k++) { for (ii = 0; ii < 48; ii++) { pilotEqGains_re = pilotEqGains[ii + 48 * k].re; pilotEqGains_im = pilotEqGains[ii + 48 * k].im; preambleGainsFull_data_re = c_preambleGainsFull_data[ii + 48 * k].re; preambleGainsFull_data_im = c_preambleGainsFull_data[ii + 48 * k].im; R[ii + 48 * k].re = pilotEqGains_re * preambleGainsFull_data_re - pilotEqGains_im * preambleGainsFull_data_im; R[ii + 48 * k].im = pilotEqGains_re * preambleGainsFull_data_im + pilotEqGains_im * preambleGainsFull_data_re; } } /* Save Gains for visualization */ estimate->pilotEqGains.size[0] = 48; estimate->pilotEqGains.size[1] = 12; for (k = 0; k < 576; k++) { estimate->pilotEqGains.data[k] = pilotEqGains[k]; } estimate->preambleEqGains.size[0] = 53; for (k = 0; k < 53; k++) { estimate->preambleEqGains.data[k] = RConj[k]; } emlrtHeapReferenceStackLeaveFcnR2012b(sp); }
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); }
void sqrtm(const emxArray_real_T *A, emxArray_creal_T *X, real_T *arg2) { emxArray_creal_T *T; emxArray_creal_T *y; boolean_T b0; const mxArray *b_y; static const int32_T iv40[2] = { 1, 19 }; const mxArray *m2; char_T cv12[19]; int32_T i; static const char_T cv13[19] = { 'C', 'o', 'd', 'e', 'r', ':', 'M', 'A', 'T', 'L', 'A', 'B', ':', 's', 'q', 'u', 'a', 'r', 'e' }; emxArray_creal_T *Q; emxArray_creal_T *r25; int32_T loop_ub; int16_T iv41[2]; emxArray_creal_T *R; real_T s_re; real_T s_im; int32_T k; real_T R_re; real_T R_im; real_T T_re; real_T T_im; real_T brm; int32_T i1; int32_T b_loop_ub; int32_T i2; emxArray_creal_T *b_T; emxArray_real_T *b_X; emlrtHeapReferenceStackEnterFcnR2012b(emlrtRootTLSGlobal); emxInit_creal_T(&T, 2, &k_emlrtRTEI, TRUE); emxInit_creal_T(&y, 2, &k_emlrtRTEI, TRUE); b0 = (A->size[0] == A->size[1]); if (b0) { } else { emlrtPushRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); emlrt_synchGlobalsToML(); b_y = NULL; m2 = mxCreateCharArray(2, iv40); for (i = 0; i < 19; i++) { cv12[i] = cv13[i]; } emlrtInitCharArrayR2013a(emlrtRootTLSGlobal, 19, m2, cv12); emlrtAssign(&b_y, m2); error(message(b_y, &f_emlrtMCI), &g_emlrtMCI); emlrt_synchGlobalsFromML(); emlrtPopRtStackR2012b(&hb_emlrtRSI, emlrtRootTLSGlobal); } emxInit_creal_T(&Q, 2, &k_emlrtRTEI, TRUE); emxInit_creal_T(&r25, 2, &k_emlrtRTEI, TRUE); emlrtPushRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal); schur(A, Q, r25); i = T->size[0] * T->size[1]; T->size[0] = r25->size[0]; T->size[1] = r25->size[1]; emxEnsureCapacity((emxArray__common *)T, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = r25->size[0] * r25->size[1]; for (i = 0; i < loop_ub; i++) { T->data[i] = r25->data[i]; } emxFree_creal_T(&r25); emlrtPopRtStackR2012b(&ib_emlrtRSI, emlrtRootTLSGlobal); for (i = 0; i < 2; i++) { iv41[i] = (int16_T)T->size[i]; } emxInit_creal_T(&R, 2, &l_emlrtRTEI, TRUE); i = R->size[0] * R->size[1]; R->size[0] = iv41[0]; emxEnsureCapacity((emxArray__common *)R, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); i = R->size[0] * R->size[1]; R->size[1] = iv41[1]; emxEnsureCapacity((emxArray__common *)R, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = iv41[0] * iv41[1]; for (i = 0; i < loop_ub; i++) { R->data[i].re = 0.0; R->data[i].im = 0.0; } emlrtPushRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal); b0 = isUTmatD(T); emlrtPopRtStackR2012b(&jb_emlrtRSI, emlrtRootTLSGlobal); if (b0) { emlrtPushRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&kb_emlrtRSI, emlrtRootTLSGlobal); for (loop_ub = 0; loop_ub + 1 <= A->size[0]; loop_ub++) { R->data[loop_ub + R->size[0] * loop_ub] = T->data[loop_ub + T->size[0] * loop_ub]; c_sqrt(&R->data[loop_ub + R->size[0] * loop_ub]); } } else { emlrtPushRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&lb_emlrtRSI, emlrtRootTLSGlobal); for (loop_ub = 0; loop_ub + 1 <= A->size[0]; loop_ub++) { R->data[loop_ub + R->size[0] * loop_ub] = T->data[loop_ub + T->size[0] * loop_ub]; c_sqrt(&R->data[loop_ub + R->size[0] * loop_ub]); for (i = loop_ub - 1; i + 1 > 0; i--) { s_re = 0.0; s_im = 0.0; emlrtPushRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&mb_emlrtRSI, emlrtRootTLSGlobal); for (k = i + 1; k + 1 <= loop_ub; k++) { R_re = R->data[i + R->size[0] * k].re * R->data[k + R->size[0] * loop_ub].re - R->data[i + R->size[0] * k].im * R->data[k + R->size[0] * loop_ub].im; R_im = R->data[i + R->size[0] * k].re * R->data[k + R->size[0] * loop_ub].im + R->data[i + R->size[0] * k].im * R->data[k + R->size[0] * loop_ub].re; s_re += R_re; s_im += R_im; } T_re = T->data[i + T->size[0] * loop_ub].re - s_re; T_im = T->data[i + T->size[0] * loop_ub].im - s_im; R_re = R->data[i + R->size[0] * i].re + R->data[loop_ub + R->size[0] * loop_ub].re; R_im = R->data[i + R->size[0] * i].im + R->data[loop_ub + R->size[0] * loop_ub].im; if (R_im == 0.0) { if (T_im == 0.0) { R->data[i + R->size[0] * loop_ub].re = T_re / R_re; R->data[i + R->size[0] * loop_ub].im = 0.0; } else if (T_re == 0.0) { R->data[i + R->size[0] * loop_ub].re = 0.0; R->data[i + R->size[0] * loop_ub].im = T_im / R_re; } else { R->data[i + R->size[0] * loop_ub].re = T_re / R_re; R->data[i + R->size[0] * loop_ub].im = T_im / R_re; } } else if (R_re == 0.0) { if (T_re == 0.0) { R->data[i + R->size[0] * loop_ub].re = T_im / R_im; R->data[i + R->size[0] * loop_ub].im = 0.0; } else if (T_im == 0.0) { R->data[i + R->size[0] * loop_ub].re = 0.0; R->data[i + R->size[0] * loop_ub].im = -(T_re / R_im); } else { R->data[i + R->size[0] * loop_ub].re = T_im / R_im; R->data[i + R->size[0] * loop_ub].im = -(T_re / R_im); } } else { brm = muDoubleScalarAbs(R_re); s_re = muDoubleScalarAbs(R_im); if (brm > s_re) { s_re = R_im / R_re; s_im = R_re + s_re * R_im; R->data[i + R->size[0] * loop_ub].re = (T_re + s_re * T_im) / s_im; R->data[i + R->size[0] * loop_ub].im = (T_im - s_re * T_re) / s_im; } else if (s_re == brm) { if (R_re > 0.0) { s_im = 0.5; } else { s_im = -0.5; } if (R_im > 0.0) { s_re = 0.5; } else { s_re = -0.5; } R->data[i + R->size[0] * loop_ub].re = (T_re * s_im + T_im * s_re) / brm; R->data[i + R->size[0] * loop_ub].im = (T_im * s_im - T_re * s_re) / brm; } else { s_re = R_re / R_im; s_im = R_im + s_re * R_re; R->data[i + R->size[0] * loop_ub].re = (s_re * T_re + T_im) / s_im; R->data[i + R->size[0] * loop_ub].im = (s_re * T_im - T_re) / s_im; } } } } } emlrtPushRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&kh_emlrtRSI, emlrtRootTLSGlobal); dynamic_size_checks(Q, R); emlrtPopRtStackR2012b(&kh_emlrtRSI, emlrtRootTLSGlobal); if ((Q->size[1] == 1) || (R->size[0] == 1)) { i = y->size[0] * y->size[1]; y->size[0] = Q->size[0]; y->size[1] = R->size[1]; emxEnsureCapacity((emxArray__common *)y, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = Q->size[0]; for (i = 0; i < loop_ub; i++) { k = R->size[1]; for (i1 = 0; i1 < k; i1++) { y->data[i + y->size[0] * i1].re = 0.0; y->data[i + y->size[0] * i1].im = 0.0; b_loop_ub = Q->size[1]; for (i2 = 0; i2 < b_loop_ub; i2++) { s_re = Q->data[i + Q->size[0] * i2].re * R->data[i2 + R->size[0] * i1] .re - Q->data[i + Q->size[0] * i2].im * R->data[i2 + R->size[0] * i1] .im; s_im = Q->data[i + Q->size[0] * i2].re * R->data[i2 + R->size[0] * i1] .im + Q->data[i + Q->size[0] * i2].im * R->data[i2 + R->size[0] * i1] .re; y->data[i + y->size[0] * i1].re += s_re; y->data[i + y->size[0] * i1].im += s_im; } } } } else { iv41[0] = (int16_T)Q->size[0]; iv41[1] = (int16_T)R->size[1]; emlrtPushRtStackR2012b(&jh_emlrtRSI, emlrtRootTLSGlobal); i = y->size[0] * y->size[1]; y->size[0] = iv41[0]; emxEnsureCapacity((emxArray__common *)y, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); i = y->size[0] * y->size[1]; y->size[1] = iv41[1]; emxEnsureCapacity((emxArray__common *)y, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = iv41[0] * iv41[1]; for (i = 0; i < loop_ub; i++) { y->data[i].re = 0.0; y->data[i].im = 0.0; } eml_xgemm(Q->size[0], R->size[1], Q->size[1], Q, Q->size[0], R, Q->size[1], y, Q->size[0]); emlrtPopRtStackR2012b(&jh_emlrtRSI, emlrtRootTLSGlobal); } emxFree_creal_T(&R); i = T->size[0] * T->size[1]; T->size[0] = Q->size[1]; T->size[1] = Q->size[0]; emxEnsureCapacity((emxArray__common *)T, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = Q->size[0]; for (i = 0; i < loop_ub; i++) { k = Q->size[1]; for (i1 = 0; i1 < k; i1++) { T->data[i1 + T->size[0] * i].re = Q->data[i + Q->size[0] * i1].re; T->data[i1 + T->size[0] * i].im = -Q->data[i + Q->size[0] * i1].im; } } emxFree_creal_T(&Q); emlrtPushRtStackR2012b(&kh_emlrtRSI, emlrtRootTLSGlobal); dynamic_size_checks(y, T); emlrtPopRtStackR2012b(&kh_emlrtRSI, emlrtRootTLSGlobal); if ((y->size[1] == 1) || (T->size[0] == 1)) { i = X->size[0] * X->size[1]; X->size[0] = y->size[0]; X->size[1] = T->size[1]; emxEnsureCapacity((emxArray__common *)X, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = y->size[0]; for (i = 0; i < loop_ub; i++) { k = T->size[1]; for (i1 = 0; i1 < k; i1++) { X->data[i + X->size[0] * i1].re = 0.0; X->data[i + X->size[0] * i1].im = 0.0; b_loop_ub = y->size[1]; for (i2 = 0; i2 < b_loop_ub; i2++) { s_re = y->data[i + y->size[0] * i2].re * T->data[i2 + T->size[0] * i1] .re - y->data[i + y->size[0] * i2].im * T->data[i2 + T->size[0] * i1] .im; s_im = y->data[i + y->size[0] * i2].re * T->data[i2 + T->size[0] * i1] .im + y->data[i + y->size[0] * i2].im * T->data[i2 + T->size[0] * i1] .re; X->data[i + X->size[0] * i1].re += s_re; X->data[i + X->size[0] * i1].im += s_im; } } } } else { iv41[0] = (int16_T)y->size[0]; iv41[1] = (int16_T)T->size[1]; emlrtPushRtStackR2012b(&jh_emlrtRSI, emlrtRootTLSGlobal); i = X->size[0] * X->size[1]; X->size[0] = iv41[0]; emxEnsureCapacity((emxArray__common *)X, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); i = X->size[0] * X->size[1]; X->size[1] = iv41[1]; emxEnsureCapacity((emxArray__common *)X, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = iv41[0] * iv41[1]; for (i = 0; i < loop_ub; i++) { X->data[i].re = 0.0; X->data[i].im = 0.0; } eml_xgemm(y->size[0], T->size[1], y->size[1], y, y->size[0], T, y->size[1], X, y->size[0]); emlrtPopRtStackR2012b(&jh_emlrtRSI, emlrtRootTLSGlobal); } emlrtPopRtStackR2012b(&nb_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&ob_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&kh_emlrtRSI, emlrtRootTLSGlobal); dynamic_size_checks(X, X); emlrtPopRtStackR2012b(&kh_emlrtRSI, emlrtRootTLSGlobal); if ((X->size[1] == 1) || (X->size[0] == 1)) { i = T->size[0] * T->size[1]; T->size[0] = X->size[0]; T->size[1] = X->size[1]; emxEnsureCapacity((emxArray__common *)T, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = X->size[0]; for (i = 0; i < loop_ub; i++) { k = X->size[1]; for (i1 = 0; i1 < k; i1++) { T->data[i + T->size[0] * i1].re = 0.0; T->data[i + T->size[0] * i1].im = 0.0; b_loop_ub = X->size[1]; for (i2 = 0; i2 < b_loop_ub; i2++) { s_re = X->data[i + X->size[0] * i2].re * X->data[i2 + X->size[0] * i1] .re - X->data[i + X->size[0] * i2].im * X->data[i2 + X->size[0] * i1] .im; s_im = X->data[i + X->size[0] * i2].re * X->data[i2 + X->size[0] * i1] .im + X->data[i + X->size[0] * i2].im * X->data[i2 + X->size[0] * i1] .re; T->data[i + T->size[0] * i1].re += s_re; T->data[i + T->size[0] * i1].im += s_im; } } } } else { iv41[0] = (int16_T)X->size[0]; iv41[1] = (int16_T)X->size[1]; emlrtPushRtStackR2012b(&jh_emlrtRSI, emlrtRootTLSGlobal); i = T->size[0] * T->size[1]; T->size[0] = iv41[0]; emxEnsureCapacity((emxArray__common *)T, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); i = T->size[0] * T->size[1]; T->size[1] = iv41[1]; emxEnsureCapacity((emxArray__common *)T, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = iv41[0] * iv41[1]; for (i = 0; i < loop_ub; i++) { T->data[i].re = 0.0; T->data[i].im = 0.0; } eml_xgemm(X->size[0], X->size[1], X->size[1], X, X->size[0], X, X->size[1], T, X->size[0]); emlrtPopRtStackR2012b(&jh_emlrtRSI, emlrtRootTLSGlobal); } emxInit_creal_T(&b_T, 2, &k_emlrtRTEI, TRUE); emlrtPopRtStackR2012b(&ob_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&ob_emlrtRSI, emlrtRootTLSGlobal); i = b_T->size[0] * b_T->size[1]; b_T->size[0] = T->size[0]; b_T->size[1] = T->size[1]; emxEnsureCapacity((emxArray__common *)b_T, i, (int32_T)sizeof(creal_T), &k_emlrtRTEI); loop_ub = T->size[0] * T->size[1]; for (i = 0; i < loop_ub; i++) { b_T->data[i].re = T->data[i].re - A->data[i]; b_T->data[i].im = T->data[i].im; } emxInit_real_T(&b_X, 2, &k_emlrtRTEI, TRUE); s_re = norm(b_T); s_im = b_norm(A); *arg2 = s_re / s_im; emlrtPopRtStackR2012b(&ob_emlrtRSI, emlrtRootTLSGlobal); i = b_X->size[0] * b_X->size[1]; b_X->size[0] = X->size[0]; b_X->size[1] = X->size[1]; emxEnsureCapacity((emxArray__common *)b_X, i, (int32_T)sizeof(real_T), &k_emlrtRTEI); loop_ub = X->size[0] * X->size[1]; emxFree_creal_T(&b_T); for (i = 0; i < loop_ub; i++) { b_X->data[i] = X->data[i].im; } if (c_norm(b_X) <= 10.0 * (real_T)A->size[0] * 2.2204460492503131E-16 * d_norm (X)) { emlrtPushRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&pb_emlrtRSI, emlrtRootTLSGlobal); for (loop_ub = 0; loop_ub + 1 <= A->size[0]; loop_ub++) { emlrtPushRtStackR2012b(&qb_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&qb_emlrtRSI, emlrtRootTLSGlobal); for (i = 0; i + 1 <= A->size[0]; i++) { s_re = X->data[i + X->size[0] * loop_ub].re; X->data[i + X->size[0] * loop_ub].re = s_re; X->data[i + X->size[0] * loop_ub].im = 0.0; } } } emxFree_real_T(&b_X); emxFree_creal_T(&y); emxFree_creal_T(&T); emlrtHeapReferenceStackLeaveFcnR2012b(emlrtRootTLSGlobal); }
/* * 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 */ }