/* 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); }
/* * fft_bandpower_calculate * data: the signal of 1 dimension vector * Fs: the frequency provide * band: the band provided, should have upper and lower bound * Arguments : const double data[256] * double Fs * double band[2] * double *totalpower * double *pband * Return Type : void */ void fft_bandpower_calculate(const double data[256], double Fs, double band[2], double *totalpower, double *pband) { creal_T A[256]; double y; double f[129]; int i; creal_T b_A[256]; creal_T c_A[129]; double c_power[129]; boolean_T bv0[129]; boolean_T bv1[129]; double dv0[129]; unsigned char tmp_data[129]; int trueCount; int partialTrueCount; double power_data[129]; int power_size[2]; int tmp_size[2]; double b_tmp_data[129]; /* get of the data */ fft(data, A); y = Fs / 2.0; linspace(f); for (i = 0; i < 129; i++) { f[i] *= y; } for (i = 0; i < 256; i++) { if (A[i].im == 0.0) { b_A[i].re = A[i].re / 256.0; b_A[i].im = 0.0; } else if (A[i].re == 0.0) { b_A[i].re = 0.0; b_A[i].im = A[i].im / 256.0; } else { b_A[i].re = A[i].re / 256.0; b_A[i].im = A[i].im / 256.0; } } memcpy(&c_A[0], &b_A[0], 129U * sizeof(creal_T)); b_abs(c_A, c_power); for (i = 0; i < 129; i++) { c_power[i] *= 2.0; } /* see if band power is in side the frequency range */ if (band[1] > f[128]) { band[1] = f[128]; } if (band[0] < f[0]) { /* if the band lower bound is less than f(1) */ band[0] = f[0]; } for (i = 0; i < 129; i++) { bv0[i] = (f[i] >= band[0]); bv1[i] = (f[i] <= band[1]); } power(c_power, dv0); *totalpower = sum(dv0); trueCount = 0; for (i = 0; i < 129; i++) { if (bv0[i] && bv1[i]) { trueCount++; } } partialTrueCount = 0; for (i = 0; i < 129; i++) { if (bv0[i] && bv1[i]) { tmp_data[partialTrueCount] = (unsigned char)(i + 1); partialTrueCount++; } } power_size[0] = 1; power_size[1] = trueCount; for (i = 0; i < trueCount; i++) { power_data[i] = c_power[tmp_data[i] - 1]; } b_power(power_data, power_size, b_tmp_data, tmp_size); *pband = b_sum(b_tmp_data, tmp_size); }
/* * function [lp]=gaussmixp(y,m,v,w) * y = cat(1, testSamples(1).mfcc{:}); * m = gmm.M; * v = gmm.V; * w = gmm.W; */ void gaussmixp(const real_T y[2004], const real_T m[108], const real_T v[108], const real_T w[9], real_T lp[167]) { real_T b[108]; real_T dv0[108]; real_T b_b[9]; real_T lvm[9]; int32_T ix; real_T mx[167]; real_T kk[1503]; real_T km[1503]; static real_T b_y[18036]; int32_T iy; real_T dv1[18036]; real_T x[1503]; int32_T i; int32_T ixstart; int32_T ixstop; real_T mtmp; int32_T b_ix; boolean_T exitg1; real_T ps[167]; /* GAUSSMIXP calculate probability densities from a Gaussian mixture model */ /* */ /* Inputs: n data values, k mixtures, p parameters, q data vector size */ /* */ /* Y(n,q) = input data */ /* M(k,p) = mixture means for x(p) */ /* V(k,p) or V(p,p,k) variances (diagonal or full) */ /* W(k,1) = weights */ /* A(q,p), B(q) = transformation: y=x*a'+b' (where y and x are row vectors) */ /* if A is omitted, it is assumed to be the first q rows of the */ /* identity matrix. B defaults to zero. */ /* Note that most commonly, q=p and A and B are omitted entirely. */ /* */ /* Outputs */ /* */ /* LP(n,1) = log probability of each data point */ /* RP(n,k) = relative probability of each mixture */ /* KH(n,1) = highest probability mixture */ /* KP(n,1) = relative probability of highest probability mixture */ /* Copyright (C) Mike Brookes 2000-2009 */ /* Version: $Id: gaussmixp.m,v 1.3 2009/04/08 07:51:21 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. */ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */ /* 'gaussmixp:49' [n,q]=size(y); */ /* 'gaussmixp:50' [k,p]=size(m); */ /* 'gaussmixp:51' memsize=voicebox('memsize'); */ voicebox(); /* set memory size to use */ /* 'gaussmixp:53' lp=zeros(n,1); */ memset((void *)&lp[0], 0, 167U * sizeof(real_T)); /* 'gaussmixp:54' wk=ones(k,1); */ /* 'gaussmixp:56' vi=-0.5*v.^(-1); */ power(v, b); /* data-independent scale factor in exponent */ /* 'gaussmixp:57' lvm=log(w)-0.5*sum(log(v),2); */ memcpy((void *)&dv0[0], (void *)&v[0], 108U * sizeof(real_T)); c_log(dv0); sum(dv0, b_b); memcpy((void *)&lvm[0], (void *)&w[0], 9U * sizeof(real_T)); b_log(lvm); for (ix = 0; ix < 9; ix++) { lvm[ix] -= 0.5 * b_b[ix]; } /* log of external scale factor (excluding -0.5*q*log(2pi) term) */ /* 'gaussmixp:58' ii=1:n; */ /* 'gaussmixp:59' wnj=ones(1,n); */ /* 'gaussmixp:60' kk=repmat(ii,k,1); */ for (ix = 0; ix < 167; ix++) { mx[ix] = 1.0 + (real_T)ix; } repmat(mx, kk); /* 'gaussmixp:61' km=repmat(1:k,1,n); */ for (ix = 0; ix < 9; ix++) { b_b[ix] = 1.0 + (real_T)ix; } b_repmat(b_b, km); /* 'gaussmixp:62' py=reshape(sum((y(kk(:),:)-m(km(:),:)).^2.*vi(km(:),:),2),k,n)+lvm(:,wnj); */ for (ix = 0; ix < 12; ix++) { for (iy = 0; iy < 1503; iy++) { b_y[iy + 1503 * ix] = y[((int32_T)kk[iy] + 167 * ix) - 1] - m[((int32_T) km[iy] + 9 * ix) - 1]; } } b_power(b_y, dv1); for (ix = 0; ix < 12; ix++) { for (iy = 0; iy < 1503; iy++) { b_y[iy + 1503 * ix] = dv1[iy + 1503 * ix] * (-0.5 * b[((int32_T)km[iy] + 9 * ix) - 1]); } } b_sum(b_y, x); memcpy((void *)&kk[0], (void *)&x[0], 1503U * sizeof(real_T)); for (ix = 0; ix < 167; ix++) { for (iy = 0; iy < 9; iy++) { km[iy + 9 * ix] = kk[iy + 9 * ix] + lvm[iy]; } } /* 'gaussmixp:63' mx=max(py,[],1); */ ix = -8; iy = -1; for (i = 0; i < 167; i++) { ix += 9; ixstart = ix; ixstop = ix + 8; mtmp = km[ix - 1]; if (rtIsNaN(km[ix - 1])) { b_ix = ix; exitg1 = 0U; while ((exitg1 == 0U) && (b_ix + 1 <= ixstop)) { ixstart = b_ix + 1; if (!rtIsNaN(km[b_ix])) { mtmp = km[b_ix]; exitg1 = 1U; } else { b_ix++; } } } if (ixstart < ixstop) { while (ixstart + 1 <= ixstop) { if (km[ixstart] > mtmp) { mtmp = km[ixstart]; } ixstart++; } } iy++; mx[iy] = mtmp; } /* find normalizing factor for each data point to prevent underflow when using exp() */ /* 'gaussmixp:64' px=exp(py-mx(wk,:)); */ for (ix = 0; ix < 167; ix++) { for (iy = 0; iy < 9; iy++) { kk[iy + 9 * ix] = km[iy + 9 * ix] - mx[ix]; } } b_exp(kk); /* find normalized probability of each mixture for each datapoint */ /* 'gaussmixp:65' ps=sum(px,1); */ c_sum(kk, ps); /* total normalized likelihood of each data point */ /* 'gaussmixp:66' lp(ii)=log(ps)+mx; */ d_log(ps); for (ix = 0; ix < 167; ix++) { /* 'gaussmixp:67' lp=lp-0.5*q*log(2*pi); */ lp[ix] = (ps[ix] + mx[ix]) - 11.027262398456072; } }
void sammon(sammonStackData *SD, const real_T x[1000000], real_T y[2000], real_T *E) { real_T B; int32_T i; real_T dv0[1000]; int32_T b_i; boolean_T exitg1; real_T alpha1; real_T beta1; char_T TRANSB; char_T TRANSA; ptrdiff_t m_t; ptrdiff_t n_t; ptrdiff_t k_t; ptrdiff_t lda_t; ptrdiff_t ldb_t; ptrdiff_t ldc_t; double * alpha1_t; double * Aia0_t; double * Bib0_t; double * beta1_t; double * Cic0_t; real_T g[2000]; real_T y2[2000]; real_T b_y[2000]; real_T c_y[2000]; real_T d_y[2000]; real_T e_y[2000]; real_T b_g[2000]; int32_T j; int32_T b_j; boolean_T exitg2; real_T dv1[1000]; real_T E_new; /* #codgen */ /* */ /* SAMMON - apply Sammon's nonlinear mapping */ /* */ /* Y = SAMMON(X) applies Sammon's nonlinear mapping procedure on */ /* multivariate data X, where each row represents a pattern and each column */ /* represents a feature. On completion, Y contains the corresponding */ /* co-ordinates of each point on the map. By default, a two-dimensional */ /* map is created. Note if X contains any duplicated rows, SAMMON will */ /* fail (ungracefully). */ /* */ /* [Y,E] = SAMMON(X) also returns the value of the cost function in E (i.e. */ /* the stress of the mapping). */ /* */ /* An N-dimensional output map is generated by Y = SAMMON(X,N) . */ /* */ /* A set of optimisation options can also be specified using a third */ /* argument, Y = SAMMON(X,N,OPTS) , where OPTS is a structure with fields: */ /* */ /* MaxIter - maximum number of iterations */ /* TolFun - relative tolerance on objective function */ /* MaxHalves - maximum number of step halvings */ /* Input - {'raw','distance'} if set to 'distance', X is */ /* interpreted as a matrix of pairwise distances. */ /* Display - {'off', 'on', 'iter'} */ /* Initialisation - {'pca', 'random'} */ /* */ /* The default options structure can be retrieved by calling SAMMON with */ /* no parameters. */ /* */ /* References : */ /* */ /* [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data Structure */ /* Analysis", IEEE Transactions on Computers, vol. C-18, no. 5, */ /* pp 401-409, May 1969. */ /* */ /* See also : SAMMON_TEST */ /* */ /* File : sammon.m */ /* */ /* Date : Monday 12th November 2007. */ /* */ /* Author : Gavin C. Cawley and Nicola L. C. Talbot */ /* */ /* Description : Simple vectorised MATLAB implementation of Sammon's non-linear */ /* mapping algorithm [1]. */ /* */ /* References : [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data */ /* Structure Analysis", IEEE Transactions on Computers, */ /* vol. C-18, no. 5, pp 401-409, May 1969. */ /* */ /* History : 10/08/2004 - v1.00 */ /* 11/08/2004 - v1.10 Hessian made positive semidefinite */ /* 13/08/2004 - v1.11 minor optimisation */ /* 12/11/2007 - v1.20 initialisation using the first n principal */ /* components. */ /* */ /* Thanks : Dr Nick Hamilton ([email protected]) for supplying the */ /* code for implementing initialisation using the first n */ /* principal components (introduced in v1.20). */ /* */ /* To do : The current version does not take advantage of the symmetry */ /* of the distance matrix in order to allow for easy */ /* vectorisation. This may not be a good choice for very large */ /* datasets, so perhaps one day I'll get around to doing a MEX */ /* version using the BLAS library etc. for very large datasets. */ /* */ /* Copyright : (c) Dr Gavin C. Cawley, November 2007. */ /* */ /* 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 should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* */ /* use the default options structure */ /* create distance matrix unless given by parameters */ emlrtPushRtStackR2012b(&emlrtRSI, emlrtRootTLSGlobal); euclid(SD, x, x, SD->f2.D); emlrtPopRtStackR2012b(&emlrtRSI, emlrtRootTLSGlobal); /* remaining initialisation */ B = b_sum(SD->f2.D); eye(SD->f2.delta); for (i = 0; i < 1000000; i++) { SD->f2.D[i] += SD->f2.delta[i]; } rdivide(1.0, SD->f2.D, SD->f2.Dinv); emlrtPushRtStackR2012b(&b_emlrtRSI, emlrtRootTLSGlobal); randn(y); emlrtPopRtStackR2012b(&b_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&c_emlrtRSI, emlrtRootTLSGlobal); b_euclid(SD, y, y, SD->f2.d); eye(SD->f2.delta); for (i = 0; i < 1000000; i++) { SD->f2.d[i] += SD->f2.delta[i]; } emlrtPopRtStackR2012b(&c_emlrtRSI, emlrtRootTLSGlobal); rdivide(1.0, SD->f2.d, SD->f2.dinv); for (i = 0; i < 1000000; i++) { SD->f2.b_D[i] = SD->f2.D[i] - SD->f2.d[i]; } power(SD->f2.b_D, SD->f2.delta); for (i = 0; i < 1000000; i++) { SD->f2.d[i] = SD->f2.delta[i] * SD->f2.Dinv[i]; } d_sum(SD->f2.d, dv0); *E = e_sum(dv0); /* get on with it */ b_i = 0; exitg1 = FALSE; while ((exitg1 == FALSE) && (b_i < 500)) { /* compute gradient, Hessian and search direction (note it is actually */ /* 1/4 of the gradient and Hessian, but the step size is just the ratio */ /* of the gradient and the diagonal of the Hessian so it doesn't matter). */ for (i = 0; i < 1000000; i++) { SD->f2.delta[i] = SD->f2.dinv[i] - SD->f2.Dinv[i]; } emlrtPushRtStackR2012b(&d_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); alpha1 = 1.0; beta1 = 0.0; TRANSB = 'N'; TRANSA = 'N'; for (i = 0; i < 2000; i++) { SD->f2.y_old[i] = 1.0; SD->f2.deltaone[i] = 0.0; } emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(2); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); lda_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldb_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldc_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&alpha1); emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&SD->f2.delta[0]); emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); Bib0_t = (double *)(&SD->f2.y_old[0]); emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); beta1_t = (double *)(&beta1); emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); Cic0_t = (double *)(&SD->f2.deltaone[0]); emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t); emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&d_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); alpha1 = 1.0; beta1 = 0.0; TRANSB = 'N'; TRANSA = 'N'; memset(&g[0], 0, 2000U * sizeof(real_T)); emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(2); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); lda_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldb_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldc_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&alpha1); emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&SD->f2.delta[0]); emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); Bib0_t = (double *)(&y[0]); emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); beta1_t = (double *)(&beta1); emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); Cic0_t = (double *)(&g[0]); emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t); emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); for (i = 0; i < 2000; i++) { g[i] -= y[i] * SD->f2.deltaone[i]; } emlrtPopRtStackR2012b(&e_emlrtRSI, emlrtRootTLSGlobal); c_power(SD->f2.dinv, SD->f2.delta); b_power(y, y2); emlrtPushRtStackR2012b(&f_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); alpha1 = 1.0; beta1 = 0.0; TRANSB = 'N'; TRANSA = 'N'; memset(&b_y[0], 0, 2000U * sizeof(real_T)); emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(2); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); lda_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldb_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldc_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&alpha1); emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&SD->f2.delta[0]); emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); Bib0_t = (double *)(&y2[0]); emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); beta1_t = (double *)(&beta1); emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); Cic0_t = (double *)(&b_y[0]); emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t); emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); for (i = 0; i < 2000; i++) { c_y[i] = 2.0 * y[i]; } emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); alpha1 = 1.0; beta1 = 0.0; TRANSB = 'N'; TRANSA = 'N'; memset(&d_y[0], 0, 2000U * sizeof(real_T)); emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(2); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); lda_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldb_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldc_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&alpha1); emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&SD->f2.delta[0]); emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); Bib0_t = (double *)(&y[0]); emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); beta1_t = (double *)(&beta1); emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); Cic0_t = (double *)(&d_y[0]); emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t); emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); alpha1 = 1.0; beta1 = 0.0; TRANSB = 'N'; TRANSA = 'N'; for (i = 0; i < 2000; i++) { SD->f2.y_old[i] = 1.0; e_y[i] = 0.0; } emlrtPushRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); m_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&l_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); n_t = (ptrdiff_t)(2); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&m_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); k_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&n_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); lda_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&o_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldb_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&p_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); ldc_t = (ptrdiff_t)(1000); emlrtPopRtStackR2012b(&x_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&q_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); alpha1_t = (double *)(&alpha1); emlrtPopRtStackR2012b(&r_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); Aia0_t = (double *)(&SD->f2.delta[0]); emlrtPopRtStackR2012b(&s_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); Bib0_t = (double *)(&SD->f2.y_old[0]); emlrtPopRtStackR2012b(&t_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); beta1_t = (double *)(&beta1); emlrtPopRtStackR2012b(&u_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); Cic0_t = (double *)(&e_y[0]); emlrtPopRtStackR2012b(&v_emlrtRSI, emlrtRootTLSGlobal); emlrtPushRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); dgemm(&TRANSA, &TRANSB, &m_t, &n_t, &k_t, alpha1_t, Aia0_t, &lda_t, Bib0_t, &ldb_t, beta1_t, Cic0_t, &ldc_t); emlrtPopRtStackR2012b(&w_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&k_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&j_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&i_emlrtRSI, emlrtRootTLSGlobal); emlrtPopRtStackR2012b(&f_emlrtRSI, emlrtRootTLSGlobal); for (i = 0; i < 2000; i++) { SD->f2.y_old[i] = ((b_y[i] - SD->f2.deltaone[i]) - c_y[i] * d_y[i]) + y2[i] * e_y[i]; b_g[i] = -g[i]; } b_abs(SD->f2.y_old, y2); for (i = 0; i < 2000; i++) { SD->f2.deltaone[i] = y2[i]; SD->f2.y_old[i] = y[i]; } b_rdivide(b_g, SD->f2.deltaone, y2); /* use step-halving procedure to ensure progress is made */ j = 1; b_j = 0; exitg2 = FALSE; while ((exitg2 == FALSE) && (b_j < 20)) { j = b_j + 1; for (i = 0; i < 2000; i++) { y[i] = SD->f2.y_old[i] + y2[i]; } emlrtPushRtStackR2012b(&g_emlrtRSI, emlrtRootTLSGlobal); b_euclid(SD, y, y, SD->f2.d); eye(SD->f2.delta); for (i = 0; i < 1000000; i++) { SD->f2.d[i] += SD->f2.delta[i]; } emlrtPopRtStackR2012b(&g_emlrtRSI, emlrtRootTLSGlobal); rdivide(1.0, SD->f2.d, SD->f2.dinv); for (i = 0; i < 1000000; i++) { SD->f2.b_D[i] = SD->f2.D[i] - SD->f2.d[i]; } power(SD->f2.b_D, SD->f2.delta); for (i = 0; i < 1000000; i++) { SD->f2.d[i] = SD->f2.delta[i] * SD->f2.Dinv[i]; } d_sum(SD->f2.d, dv1); E_new = e_sum(dv1); if (E_new < *E) { exitg2 = TRUE; } else { for (i = 0; i < 2000; i++) { y2[i] *= 0.5; } b_j++; emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal); } } /* bomb out if too many halving steps are required */ if ((j == 20) || (muDoubleScalarAbs((*E - E_new) / *E) < 1.0E-9)) { exitg1 = TRUE; } else { /* evaluate termination criterion */ /* report progress */ *E = E_new; b_i++; emlrtBreakCheckFastR2012b(emlrtBreakCheckR2012bFlagVar, emlrtRootTLSGlobal); } } /* fiddle stress to match the original Sammon paper */ *E *= 0.5 / B; }
void sammon(const emxArray_real_T *x, emxArray_real_T *y) { emxArray_real_T *D; emxArray_real_T *delta; int32_T i0; int32_T b_D; int32_T br; emxArray_real_T *Dinv; emxArray_real_T *d; emxArray_real_T *dinv; emxArray_real_T *c_D; emxArray_real_T *b_delta; emxArray_real_T *b_x; real_T E; int32_T i; emxArray_real_T *deltaone; emxArray_real_T *g; emxArray_real_T *y2; emxArray_real_T *H; emxArray_real_T *s; emxArray_real_T *C; emxArray_real_T *b_C; emxArray_real_T *c_delta; emxArray_real_T *d_D; emxArray_real_T *b_deltaone; boolean_T exitg1; boolean_T guard2 = FALSE; uint32_T unnamed_idx_0; int32_T ic; int32_T ar; int32_T ib; int32_T ia; int32_T i1; boolean_T guard1 = FALSE; int32_T exitg3; boolean_T exitg2; int32_T b_y[2]; real_T E_new; real_T u1; emxInit_real_T(&D, 2); emxInit_real_T(&delta, 2); /* #codgen */ /* */ /* SAMMON - apply Sammon's nonlinear mapping */ /* */ /* Y = SAMMON(X) applies Sammon's nonlinear mapping procedure on */ /* multivariate data X, where each row represents a pattern and each column */ /* represents a feature. On completion, Y contains the corresponding */ /* co-ordinates of each point on the map. By default, a two-dimensional */ /* map is created. Note if X contains any duplicated rows, SAMMON will */ /* fail (ungracefully). */ /* */ /* [Y,E] = SAMMON(X) also returns the value of the cost function in E (i.e. */ /* the stress of the mapping). */ /* */ /* An N-dimensional output map is generated by Y = SAMMON(X,N) . */ /* */ /* A set of optimisation options can also be specified using a third */ /* argument, Y = SAMMON(X,N,OPTS) , where OPTS is a structure with fields: */ /* */ /* MaxIter - maximum number of iterations */ /* TolFun - relative tolerance on objective function */ /* MaxHalves - maximum number of step halvings */ /* Input - {'raw','distance'} if set to 'distance', X is */ /* interpreted as a matrix of pairwise distances. */ /* Display - {'off', 'on', 'iter'} */ /* Initialisation - {'pca', 'random'} */ /* */ /* The default options structure can be retrieved by calling SAMMON with */ /* no parameters. */ /* */ /* References : */ /* */ /* [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data Structure */ /* Analysis", IEEE Transactions on Computers, vol. C-18, no. 5, */ /* pp 401-409, May 1969. */ /* */ /* See also : SAMMON_TEST */ /* */ /* File : sammon.m */ /* */ /* Date : Monday 12th November 2007. */ /* */ /* Author : Gavin C. Cawley and Nicola L. C. Talbot */ /* */ /* Description : Simple vectorised MATLAB implementation of Sammon's non-linear */ /* mapping algorithm [1]. */ /* */ /* References : [1] Sammon, John W. Jr., "A Nonlinear Mapping for Data */ /* Structure Analysis", IEEE Transactions on Computers, */ /* vol. C-18, no. 5, pp 401-409, May 1969. */ /* */ /* History : 10/08/2004 - v1.00 */ /* 11/08/2004 - v1.10 Hessian made positive semidefinite */ /* 13/08/2004 - v1.11 minor optimisation */ /* 12/11/2007 - v1.20 initialisation using the first n principal */ /* components. */ /* */ /* Thanks : Dr Nick Hamilton ([email protected]) for supplying the */ /* code for implementing initialisation using the first n */ /* principal components (introduced in v1.20). */ /* */ /* To do : The current version does not take advantage of the symmetry */ /* of the distance matrix in order to allow for easy */ /* vectorisation. This may not be a good choice for very large */ /* datasets, so perhaps one day I'll get around to doing a MEX */ /* version using the BLAS library etc. for very large datasets. */ /* */ /* Copyright : (c) Dr Gavin C. Cawley, November 2007. */ /* */ /* 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 should have received a copy of the GNU General Public License */ /* along with this program; if not, write to the Free Software */ /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* */ /* use the default options structure */ /* create distance matrix unless given by parameters */ euclid(x, x, D); /* remaining initialisation */ eye(x->size[0], delta); i0 = D->size[0] * D->size[1]; emxEnsureCapacity((emxArray__common *)D, i0, (int32_T)sizeof(real_T)); b_D = D->size[0]; br = D->size[1]; br *= b_D; for (i0 = 0; i0 < br; i0++) { D->data[i0] += delta->data[i0]; } emxInit_real_T(&Dinv, 2); emxInit_real_T(&d, 2); rdivide(D, Dinv); randn(x->size[0], y); b_euclid(y, y, d); eye(x->size[0], delta); i0 = d->size[0] * d->size[1]; emxEnsureCapacity((emxArray__common *)d, i0, (int32_T)sizeof(real_T)); b_D = d->size[0]; br = d->size[1]; br *= b_D; for (i0 = 0; i0 < br; i0++) { d->data[i0] += delta->data[i0]; } emxInit_real_T(&dinv, 2); emxInit_real_T(&c_D, 2); rdivide(d, dinv); i0 = c_D->size[0] * c_D->size[1]; c_D->size[0] = D->size[0]; c_D->size[1] = D->size[1]; emxEnsureCapacity((emxArray__common *)c_D, i0, (int32_T)sizeof(real_T)); br = D->size[0] * D->size[1]; for (i0 = 0; i0 < br; i0++) { c_D->data[i0] = D->data[i0] - d->data[i0]; } emxInit_real_T(&b_delta, 2); power(c_D, delta); i0 = b_delta->size[0] * b_delta->size[1]; b_delta->size[0] = delta->size[0]; b_delta->size[1] = delta->size[1]; emxEnsureCapacity((emxArray__common *)b_delta, i0, (int32_T)sizeof(real_T)); br = delta->size[0] * delta->size[1]; emxFree_real_T(&c_D); for (i0 = 0; i0 < br; i0++) { b_delta->data[i0] = delta->data[i0] * Dinv->data[i0]; } emxInit_real_T(&b_x, 2); c_sum(b_delta, b_x); E = d_sum(b_x); /* get on with it */ i = 0; emxFree_real_T(&b_delta); emxInit_real_T(&deltaone, 2); emxInit_real_T(&g, 2); emxInit_real_T(&y2, 2); emxInit_real_T(&H, 2); b_emxInit_real_T(&s, 1); emxInit_real_T(&C, 2); emxInit_real_T(&b_C, 2); emxInit_real_T(&c_delta, 2); emxInit_real_T(&d_D, 2); b_emxInit_real_T(&b_deltaone, 1); exitg1 = FALSE; while ((exitg1 == FALSE) && (i < 500)) { /* compute gradient, Hessian and search direction (note it is actually */ /* 1/4 of the gradient and Hessian, but the step size is just the ratio */ /* of the gradient and the diagonal of the Hessian so it doesn't matter). */ i0 = delta->size[0] * delta->size[1]; delta->size[0] = dinv->size[0]; delta->size[1] = dinv->size[1]; emxEnsureCapacity((emxArray__common *)delta, i0, (int32_T)sizeof(real_T)); br = dinv->size[0] * dinv->size[1]; for (i0 = 0; i0 < br; i0++) { delta->data[i0] = dinv->data[i0] - Dinv->data[i0]; } guard2 = FALSE; if (delta->size[1] == 1) { guard2 = TRUE; } else { b_D = x->size[0]; if (b_D == 1) { guard2 = TRUE; } else { unnamed_idx_0 = (uint32_T)delta->size[0]; i0 = deltaone->size[0] * deltaone->size[1]; deltaone->size[0] = (int32_T)unnamed_idx_0; deltaone->size[1] = 2; emxEnsureCapacity((emxArray__common *)deltaone, i0, (int32_T)sizeof (real_T)); br = (int32_T)unnamed_idx_0 << 1; for (i0 = 0; i0 < br; i0++) { deltaone->data[i0] = 0.0; } if (delta->size[0] == 0) { } else { b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { i0 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i0; ic++) { deltaone->data[ic] = 0.0; } b_D += delta->size[0]; } br = 0; b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { ar = 0; i0 = br + delta->size[1]; for (ib = br + 1; ib <= i0; ib++) { ia = ar; i1 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i1; ic++) { ia++; deltaone->data[ic] += delta->data[ia - 1]; } ar += delta->size[0]; } br += delta->size[1]; b_D += delta->size[0]; } } } } if (guard2 == TRUE) { i0 = deltaone->size[0] * deltaone->size[1]; deltaone->size[0] = delta->size[0]; deltaone->size[1] = 2; emxEnsureCapacity((emxArray__common *)deltaone, i0, (int32_T)sizeof(real_T)); br = delta->size[0]; for (i0 = 0; i0 < br; i0++) { for (i1 = 0; i1 < 2; i1++) { deltaone->data[i0 + deltaone->size[0] * i1] = 0.0; ar = delta->size[1]; for (b_D = 0; b_D < ar; b_D++) { deltaone->data[i0 + deltaone->size[0] * i1] += delta->data[i0 + delta->size[0] * b_D]; } } } } if ((delta->size[1] == 1) || (y->size[0] == 1)) { i0 = g->size[0] * g->size[1]; g->size[0] = delta->size[0]; g->size[1] = 2; emxEnsureCapacity((emxArray__common *)g, i0, (int32_T)sizeof(real_T)); br = delta->size[0]; for (i0 = 0; i0 < br; i0++) { for (i1 = 0; i1 < 2; i1++) { g->data[i0 + g->size[0] * i1] = 0.0; ar = delta->size[1]; for (b_D = 0; b_D < ar; b_D++) { g->data[i0 + g->size[0] * i1] += delta->data[i0 + delta->size[0] * b_D] * y->data[b_D + y->size[0] * i1]; } } } } else { unnamed_idx_0 = (uint32_T)delta->size[0]; i0 = g->size[0] * g->size[1]; g->size[0] = (int32_T)unnamed_idx_0; g->size[1] = 2; emxEnsureCapacity((emxArray__common *)g, i0, (int32_T)sizeof(real_T)); br = (int32_T)unnamed_idx_0 << 1; for (i0 = 0; i0 < br; i0++) { g->data[i0] = 0.0; } if (delta->size[0] == 0) { } else { b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { i0 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i0; ic++) { g->data[ic] = 0.0; } b_D += delta->size[0]; } br = 0; b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { ar = 0; i0 = br + delta->size[1]; for (ib = br; ib + 1 <= i0; ib++) { if (y->data[ib] != 0.0) { ia = ar; i1 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i1; ic++) { ia++; g->data[ic] += y->data[ib] * delta->data[ia - 1]; } } ar += delta->size[0]; } br += delta->size[1]; b_D += delta->size[0]; } } } i0 = g->size[0] * g->size[1]; g->size[1] = 2; emxEnsureCapacity((emxArray__common *)g, i0, (int32_T)sizeof(real_T)); b_D = g->size[0]; br = g->size[1]; br *= b_D; for (i0 = 0; i0 < br; i0++) { g->data[i0] -= y->data[i0] * deltaone->data[i0]; } c_power(dinv, delta); b_power(y, y2); if ((delta->size[1] == 1) || (y2->size[0] == 1)) { i0 = H->size[0] * H->size[1]; H->size[0] = delta->size[0]; H->size[1] = 2; emxEnsureCapacity((emxArray__common *)H, i0, (int32_T)sizeof(real_T)); br = delta->size[0]; for (i0 = 0; i0 < br; i0++) { for (i1 = 0; i1 < 2; i1++) { H->data[i0 + H->size[0] * i1] = 0.0; ar = delta->size[1]; for (b_D = 0; b_D < ar; b_D++) { H->data[i0 + H->size[0] * i1] += delta->data[i0 + delta->size[0] * b_D] * y2->data[b_D + y2->size[0] * i1]; } } } } else { unnamed_idx_0 = (uint32_T)delta->size[0]; i0 = H->size[0] * H->size[1]; H->size[0] = (int32_T)unnamed_idx_0; H->size[1] = 2; emxEnsureCapacity((emxArray__common *)H, i0, (int32_T)sizeof(real_T)); br = (int32_T)unnamed_idx_0 << 1; for (i0 = 0; i0 < br; i0++) { H->data[i0] = 0.0; } if (delta->size[0] == 0) { } else { b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { i0 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i0; ic++) { H->data[ic] = 0.0; } b_D += delta->size[0]; } br = 0; b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { ar = 0; i0 = br + delta->size[1]; for (ib = br; ib + 1 <= i0; ib++) { if (y2->data[ib] != 0.0) { ia = ar; i1 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i1; ic++) { ia++; H->data[ic] += y2->data[ib] * delta->data[ia - 1]; } } ar += delta->size[0]; } br += delta->size[1]; b_D += delta->size[0]; } } } if ((delta->size[1] == 1) || (y->size[0] == 1)) { i0 = C->size[0] * C->size[1]; C->size[0] = delta->size[0]; C->size[1] = 2; emxEnsureCapacity((emxArray__common *)C, i0, (int32_T)sizeof(real_T)); br = delta->size[0]; for (i0 = 0; i0 < br; i0++) { for (i1 = 0; i1 < 2; i1++) { C->data[i0 + C->size[0] * i1] = 0.0; ar = delta->size[1]; for (b_D = 0; b_D < ar; b_D++) { C->data[i0 + C->size[0] * i1] += delta->data[i0 + delta->size[0] * b_D] * y->data[b_D + y->size[0] * i1]; } } } } else { unnamed_idx_0 = (uint32_T)delta->size[0]; i0 = C->size[0] * C->size[1]; C->size[0] = (int32_T)unnamed_idx_0; C->size[1] = 2; emxEnsureCapacity((emxArray__common *)C, i0, (int32_T)sizeof(real_T)); br = (int32_T)unnamed_idx_0 << 1; for (i0 = 0; i0 < br; i0++) { C->data[i0] = 0.0; } if (delta->size[0] == 0) { } else { b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { i0 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i0; ic++) { C->data[ic] = 0.0; } b_D += delta->size[0]; } br = 0; b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { ar = 0; i0 = br + delta->size[1]; for (ib = br; ib + 1 <= i0; ib++) { if (y->data[ib] != 0.0) { ia = ar; i1 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i1; ic++) { ia++; C->data[ic] += y->data[ib] * delta->data[ia - 1]; } } ar += delta->size[0]; } br += delta->size[1]; b_D += delta->size[0]; } } } guard1 = FALSE; if (delta->size[1] == 1) { guard1 = TRUE; } else { b_D = x->size[0]; if (b_D == 1) { guard1 = TRUE; } else { unnamed_idx_0 = (uint32_T)delta->size[0]; i0 = b_C->size[0] * b_C->size[1]; b_C->size[0] = (int32_T)unnamed_idx_0; b_C->size[1] = 2; emxEnsureCapacity((emxArray__common *)b_C, i0, (int32_T)sizeof(real_T)); br = (int32_T)unnamed_idx_0 << 1; for (i0 = 0; i0 < br; i0++) { b_C->data[i0] = 0.0; } if (delta->size[0] == 0) { } else { b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { i0 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i0; ic++) { b_C->data[ic] = 0.0; } b_D += delta->size[0]; } br = 0; b_D = 0; while ((delta->size[0] > 0) && (b_D <= delta->size[0])) { ar = 0; i0 = br + delta->size[1]; for (ib = br + 1; ib <= i0; ib++) { ia = ar; i1 = b_D + delta->size[0]; for (ic = b_D; ic + 1 <= i1; ic++) { ia++; b_C->data[ic] += delta->data[ia - 1]; } ar += delta->size[0]; } br += delta->size[1]; b_D += delta->size[0]; } } } } if (guard1 == TRUE) { i0 = b_C->size[0] * b_C->size[1]; b_C->size[0] = delta->size[0]; b_C->size[1] = 2; emxEnsureCapacity((emxArray__common *)b_C, i0, (int32_T)sizeof(real_T)); br = delta->size[0]; for (i0 = 0; i0 < br; i0++) { for (i1 = 0; i1 < 2; i1++) { b_C->data[i0 + b_C->size[0] * i1] = 0.0; ar = delta->size[1]; for (b_D = 0; b_D < ar; b_D++) { b_C->data[i0 + b_C->size[0] * i1] += delta->data[i0 + delta->size[0] * b_D]; } } } } i0 = H->size[0] * H->size[1]; H->size[1] = 2; emxEnsureCapacity((emxArray__common *)H, i0, (int32_T)sizeof(real_T)); b_D = H->size[0]; br = H->size[1]; br *= b_D; for (i0 = 0; i0 < br; i0++) { H->data[i0] = ((H->data[i0] - deltaone->data[i0]) - 2.0 * y->data[i0] * C->data[i0]) + y2->data[i0] * b_C->data[i0]; } b_D = H->size[0] << 1; i0 = s->size[0]; s->size[0] = b_D; emxEnsureCapacity((emxArray__common *)s, i0, (int32_T)sizeof(real_T)); br = 0; do { exitg3 = 0; b_D = H->size[0] << 1; if (br <= b_D - 1) { s->data[br] = fabs(H->data[br]); br++; } else { exitg3 = 1; } } while (exitg3 == 0); i0 = s->size[0]; s->size[0] = g->size[0] << 1; emxEnsureCapacity((emxArray__common *)s, i0, (int32_T)sizeof(real_T)); br = g->size[0] << 1; for (i0 = 0; i0 < br; i0++) { s->data[i0] = -g->data[i0] / s->data[i0]; } i0 = deltaone->size[0] * deltaone->size[1]; deltaone->size[0] = y->size[0]; deltaone->size[1] = 2; emxEnsureCapacity((emxArray__common *)deltaone, i0, (int32_T)sizeof(real_T)); br = y->size[0] * y->size[1]; for (i0 = 0; i0 < br; i0++) { deltaone->data[i0] = y->data[i0]; } /* use step-halving procedure to ensure progress is made */ ib = 1; ia = 0; exitg2 = FALSE; while ((exitg2 == FALSE) && (ia < 20)) { ib = ia + 1; b_D = deltaone->size[0] << 1; i0 = b_deltaone->size[0]; b_deltaone->size[0] = b_D; emxEnsureCapacity((emxArray__common *)b_deltaone, i0, (int32_T)sizeof (real_T)); for (i0 = 0; i0 < b_D; i0++) { b_deltaone->data[i0] = deltaone->data[i0] + s->data[i0]; } for (i0 = 0; i0 < 2; i0++) { b_y[i0] = y->size[i0]; } i0 = y->size[0] * y->size[1]; y->size[0] = b_y[0]; y->size[1] = b_y[1]; emxEnsureCapacity((emxArray__common *)y, i0, (int32_T)sizeof(real_T)); br = b_y[1]; for (i0 = 0; i0 < br; i0++) { ar = b_y[0]; for (i1 = 0; i1 < ar; i1++) { y->data[i1 + y->size[0] * i0] = b_deltaone->data[i1 + b_y[0] * i0]; } } b_euclid(y, y, d); b_D = x->size[0]; i0 = delta->size[0] * delta->size[1]; delta->size[0] = b_D; emxEnsureCapacity((emxArray__common *)delta, i0, (int32_T)sizeof(real_T)); b_D = x->size[0]; i0 = delta->size[0] * delta->size[1]; delta->size[1] = b_D; emxEnsureCapacity((emxArray__common *)delta, i0, (int32_T)sizeof(real_T)); br = x->size[0] * x->size[0]; for (i0 = 0; i0 < br; i0++) { delta->data[i0] = 0.0; } E_new = x->size[0]; u1 = x->size[0]; if (E_new <= u1) { } else { E_new = u1; } b_D = (int32_T)E_new; if (b_D > 0) { for (br = 0; br + 1 <= b_D; br++) { delta->data[br + delta->size[0] * br] = 1.0; } } i0 = d->size[0] * d->size[1]; emxEnsureCapacity((emxArray__common *)d, i0, (int32_T)sizeof(real_T)); b_D = d->size[0]; br = d->size[1]; br *= b_D; for (i0 = 0; i0 < br; i0++) { d->data[i0] += delta->data[i0]; } rdivide(d, dinv); i0 = d_D->size[0] * d_D->size[1]; d_D->size[0] = D->size[0]; d_D->size[1] = D->size[1]; emxEnsureCapacity((emxArray__common *)d_D, i0, (int32_T)sizeof(real_T)); br = D->size[0] * D->size[1]; for (i0 = 0; i0 < br; i0++) { d_D->data[i0] = D->data[i0] - d->data[i0]; } power(d_D, delta); i0 = c_delta->size[0] * c_delta->size[1]; c_delta->size[0] = delta->size[0]; c_delta->size[1] = delta->size[1]; emxEnsureCapacity((emxArray__common *)c_delta, i0, (int32_T)sizeof(real_T)); br = delta->size[0] * delta->size[1]; for (i0 = 0; i0 < br; i0++) { c_delta->data[i0] = delta->data[i0] * Dinv->data[i0]; } c_sum(c_delta, b_x); if (b_x->size[1] == 0) { E_new = 0.0; } else { E_new = b_x->data[0]; for (br = 2; br <= b_x->size[1]; br++) { E_new += b_x->data[br - 1]; } } if (E_new < E) { exitg2 = TRUE; } else { i0 = s->size[0]; emxEnsureCapacity((emxArray__common *)s, i0, (int32_T)sizeof(real_T)); br = s->size[0]; for (i0 = 0; i0 < br; i0++) { s->data[i0] *= 0.5; } ia++; } } /* bomb out if too many halving steps are required */ if ((ib == 20) || (fabs((E - E_new) / E) < 1.0E-9)) { exitg1 = TRUE; } else { /* evaluate termination criterion */ /* report progress */ E = E_new; i++; } } emxFree_real_T(&b_deltaone); emxFree_real_T(&d_D); emxFree_real_T(&c_delta); emxFree_real_T(&b_x); emxFree_real_T(&b_C); emxFree_real_T(&C); emxFree_real_T(&s); emxFree_real_T(&H); emxFree_real_T(&y2); emxFree_real_T(&g); emxFree_real_T(&deltaone); emxFree_real_T(&delta); emxFree_real_T(&dinv); emxFree_real_T(&d); emxFree_real_T(&Dinv); emxFree_real_T(&D); /* fiddle stress to match the original Sammon paper */ }
/* Function Definitions */ static void b_euclid(const emxArray_real_T *x, const emxArray_real_T *y, emxArray_real_T *d) { emxArray_real_T *a; emxArray_real_T *b; emxArray_real_T *r2; emxArray_real_T *r3; int32_T i7; int32_T unnamed_idx_1; int32_T br; emxArray_real_T *b_b; int32_T ar; emxArray_real_T *b_y; uint32_T unnamed_idx_0; uint32_T b_unnamed_idx_1; int32_T cr; int32_T ic; int32_T ib; int32_T ia; emxArray_real_T *b_a; emxArray_real_T *r4; b_emxInit_real_T(&a, 1); emxInit_real_T(&b, 2); emxInit_real_T(&r2, 2); b_emxInit_real_T(&r3, 1); /* all done */ b_power(x, r2); b_sum(r2, a); b_power(y, r2); b_sum(r2, r3); i7 = b->size[0] * b->size[1]; b->size[0] = 1; emxEnsureCapacity((emxArray__common *)b, i7, (int32_T)sizeof(real_T)); unnamed_idx_1 = r3->size[0]; i7 = b->size[0] * b->size[1]; b->size[1] = unnamed_idx_1; emxEnsureCapacity((emxArray__common *)b, i7, (int32_T)sizeof(real_T)); br = r3->size[0]; emxFree_real_T(&r2); for (i7 = 0; i7 < br; i7++) { b->data[i7] = r3->data[i7]; } emxFree_real_T(&r3); emxInit_real_T(&b_b, 2); i7 = b_b->size[0] * b_b->size[1]; b_b->size[0] = 2; b_b->size[1] = y->size[0]; emxEnsureCapacity((emxArray__common *)b_b, i7, (int32_T)sizeof(real_T)); br = y->size[0]; for (i7 = 0; i7 < br; i7++) { for (ar = 0; ar < 2; ar++) { b_b->data[ar + b_b->size[0] * i7] = y->data[i7 + y->size[0] * ar]; } } emxInit_real_T(&b_y, 2); unnamed_idx_0 = (uint32_T)x->size[0]; b_unnamed_idx_1 = (uint32_T)b_b->size[1]; i7 = b_y->size[0] * b_y->size[1]; b_y->size[0] = (int32_T)unnamed_idx_0; emxEnsureCapacity((emxArray__common *)b_y, i7, (int32_T)sizeof(real_T)); i7 = b_y->size[0] * b_y->size[1]; b_y->size[1] = (int32_T)b_unnamed_idx_1; emxEnsureCapacity((emxArray__common *)b_y, i7, (int32_T)sizeof(real_T)); br = (int32_T)unnamed_idx_0 * (int32_T)b_unnamed_idx_1; for (i7 = 0; i7 < br; i7++) { b_y->data[i7] = 0.0; } if ((x->size[0] == 0) || (b_b->size[1] == 0)) { } else { unnamed_idx_1 = x->size[0] * (b_b->size[1] - 1); cr = 0; while ((x->size[0] > 0) && (cr <= unnamed_idx_1)) { i7 = cr + x->size[0]; for (ic = cr; ic + 1 <= i7; ic++) { b_y->data[ic] = 0.0; } cr += x->size[0]; } br = 0; cr = 0; while ((x->size[0] > 0) && (cr <= unnamed_idx_1)) { ar = -1; for (ib = br; ib + 1 <= br + 2; ib++) { if (b_b->data[ib] != 0.0) { ia = ar; i7 = cr + x->size[0]; for (ic = cr; ic + 1 <= i7; ic++) { ia++; b_y->data[ic] += b_b->data[ib] * x->data[ia]; } } ar += x->size[0]; } br += 2; cr += x->size[0]; } } emxFree_real_T(&b_b); emxInit_real_T(&b_a, 2); emxInit_real_T(&r4, 2); unnamed_idx_1 = y->size[0]; cr = x->size[0]; i7 = b_a->size[0] * b_a->size[1]; b_a->size[0] = a->size[0]; b_a->size[1] = unnamed_idx_1; emxEnsureCapacity((emxArray__common *)b_a, i7, (int32_T)sizeof(real_T)); br = a->size[0]; for (i7 = 0; i7 < br; i7++) { for (ar = 0; ar < unnamed_idx_1; ar++) { b_a->data[i7 + b_a->size[0] * ar] = a->data[i7]; } } emxFree_real_T(&a); i7 = r4->size[0] * r4->size[1]; r4->size[0] = cr; r4->size[1] = b->size[1]; emxEnsureCapacity((emxArray__common *)r4, i7, (int32_T)sizeof(real_T)); for (i7 = 0; i7 < cr; i7++) { br = b->size[1]; for (ar = 0; ar < br; ar++) { r4->data[i7 + r4->size[0] * ar] = b->data[b->size[0] * ar]; } } emxFree_real_T(&b); i7 = d->size[0] * d->size[1]; d->size[0] = b_a->size[0]; d->size[1] = b_a->size[1]; emxEnsureCapacity((emxArray__common *)d, i7, (int32_T)sizeof(real_T)); br = b_a->size[1]; for (i7 = 0; i7 < br; i7++) { unnamed_idx_1 = b_a->size[0]; for (ar = 0; ar < unnamed_idx_1; ar++) { d->data[ar + d->size[0] * i7] = (b_a->data[ar + b_a->size[0] * i7] + r4->data[ar + r4->size[0] * i7]) - 2.0 * b_y->data[ar + b_y->size[0] * i7]; } } emxFree_real_T(&r4); emxFree_real_T(&b_a); emxFree_real_T(&b_y); b_sqrt(d); }