/* 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); }
/* parametric tests for Gaussian variables. */ static double ut_gaustests(SEXP xx, SEXP yy, int nobs, int ntests, double *pvalue, double *df, test_e test) { int i = 0; double transform = 0, *xptr = NULL, *yptr = REAL(yy); double xm = 0, ym = 0, xsd = 0, ysd = 0, statistic = 0; /* compute the degrees of freedom for correlation and mutual information. */ if (test == COR) *df = nobs - 2; else if ((test == MI_G) || (test == MI_G_SH)) *df = 1; if (((test == COR) && (*df < 1)) || ((test == ZF) && (nobs - 2 < 2))) { /* if there are not enough degrees of freedom, return independence. */ warning("trying to do an independence test with zero degrees of freedom."); *df = 0; statistic = 0; for (i = 0; i < ntests; i++) pvalue[i] = 1; return statistic; }/*THEN*/ /* cache mean and variance. */ ym = c_mean(yptr, nobs); ysd = c_sse(yptr, ym, nobs); for (i = 0; i < ntests; i++) { GAUSSIAN_SWAP_X(); statistic = c_fast_cor(xptr, yptr, nobs, xm, ym, xsd, ysd); if (test == COR) { transform = cor_t_trans(statistic, *df); pvalue[i] = 2 * pt(fabs(transform), *df, FALSE, FALSE); }/*THEN*/ else if (test == MI_G) { statistic = 2 * nobs * cor_mi_trans(statistic); pvalue[i] = pchisq(statistic, *df, FALSE, FALSE); }/*THEN*/ else if (test == MI_G_SH) { statistic *= 1 - cor_lambda(xptr, yptr, nobs, xm, ym, xsd, ysd, statistic); statistic = 2 * nobs * cor_mi_trans(statistic); pvalue[i] = pchisq(statistic, *df, FALSE, FALSE); }/*THEN*/ else if (test == ZF) { statistic = cor_zf_trans(statistic, (double)nobs - 2); pvalue[i] = 2 * pnorm(fabs(statistic), 0, 1, FALSE, FALSE); }/*THEN*/ }/*FOR*/ return statistic; }/*UT_GAUSTESTS*/
/* conditional linear Gaussian mutual information test. */ static double ut_micg(SEXP xx, SEXP yy, int nobs, int ntests, double *pvalue, double *df) { int i = 0, xtype = 0, ytype = TYPEOF(yy), llx = 0, lly = 0; double xm = 0, xsd = 0, ym = 0, ysd = 0, statistic = 0; void *xptr = NULL, *yptr = NULL; SEXP xdata; if (ytype == INTSXP) { /* cache the number of levels. */ lly = NLEVELS(yy); yptr = INTEGER(yy); }/*THEN*/ else { /* cache mean and variance. */ yptr = REAL(yy); ym = c_mean(yptr, nobs); ysd = c_sse(yptr, ym, nobs); }/*ELSE*/ for (i = 0; i < ntests; i++) { xdata = VECTOR_ELT(xx, i); xtype = TYPEOF(xdata); if ((ytype == INTSXP) && (xtype == INTSXP)) { /* if both nodes are discrete, the test reverts back to a discrete * mutual information test. */ xptr = INTEGER(xdata); llx = NLEVELS(xdata); DISCRETE_SWAP_X(); statistic = 2 * nobs * c_chisqtest(xptr, llx, yptr, lly, nobs, df, MI); pvalue[i] = pchisq(statistic, *df, FALSE, FALSE); }/*THEN*/ else if ((ytype == REALSXP) && (xtype == REALSXP)) { /* if both nodes are continuous, the test reverts back to a Gaussian * mutual information test. */ xptr = REAL(xdata); xm = c_mean(xptr, nobs); xsd = c_sse(xptr, xm, nobs); statistic = c_fast_cor(xptr, yptr, nobs, xm, ym, xsd, ysd); *df = 1; statistic = 2 * nobs * cor_mi_trans(statistic); pvalue[i] = pchisq(statistic, *df, FALSE, FALSE); }/*THEN*/ else { if (xtype == INTSXP) { xptr = INTEGER(xdata); llx = NLEVELS(xdata); ysd = sqrt(ysd / (nobs - 1)); statistic = 2 * nobs * c_micg(yptr, ym, ysd, xptr, llx, nobs); *df = llx - 1; pvalue[i] = pchisq(statistic, *df, FALSE, FALSE); }/*THEN*/ else { xptr = REAL(xdata); xm = c_mean(xptr, nobs); xsd = sqrt(c_sse(xptr, xm, nobs) / (nobs - 1)); statistic = 2 * nobs * c_micg(xptr, xm, xsd, yptr, lly, nobs); *df = lly - 1; pvalue[i] = pchisq(statistic, *df, FALSE, FALSE); }/*ELSE*/ }/*THEN*/ }/*FOR*/ return statistic; }/*UT_MICG*/
/* remove one variable in each highly-correlated pair. */ SEXP dedup (SEXP data, SEXP threshold, SEXP complete, SEXP debug) { int i = 0, j = 0, k = 0, dropped = 0, nc = 0; int debuglevel = isTRUE(debug); double *mean = NULL, *sse = NULL, *xx = NULL, *yy = NULL; double cur_mean[2], cur_sse[2]; double tol = MACHINE_TOL, t = NUM(threshold); long double sum = 0; SEXP result, colnames; gdata dt = { 0 }; /* extract the columns from the data frame. */ dt = gdata_from_SEXP(data, 0); meta_init_flags(&(dt.m), 0, complete, R_NilValue); meta_copy_names(&(dt.m), 0, data); /* set up the vectors for the pairwise complete observations. */ xx = Calloc1D(dt.m.nobs, sizeof(double)); yy = Calloc1D(dt.m.nobs, sizeof(double)); if (debuglevel > 0) Rprintf("* caching means and variances.\n"); mean = Calloc1D(dt.m.ncols, sizeof(double)); sse = Calloc1D(dt.m.ncols, sizeof(double)); /* cache the mean and variance of complete variables. */ for (j = 0; j < dt.m.ncols; j++) { if (!dt.m.flag[j].complete) continue; mean[j] = c_mean(dt.col[j], dt.m.nobs); sse[j] = c_sse(dt.col[j], mean[j], dt.m.nobs); }/*FOR*/ /* main loop. */ for (j = 0; j < dt.m.ncols - 1; j++) { /* skip variables already flagged for removal. */ if (dt.m.flag[j].drop) continue; if (debuglevel > 0) Rprintf("* looking at %s with %d variables still to check.\n", dt.m.names[j], dt.m.ncols - (j + 1)); for (k = j + 1; k < dt.m.ncols; k++) { /* skip variables already flagged for removal. */ if (dt.m.flag[k].drop) continue; if (dt.m.flag[j].complete && dt.m.flag[k].complete) { /* use the cached means and variances. */ cur_mean[0] = mean[j]; cur_mean[1] = mean[k]; cur_sse[0] = sse[j]; cur_sse[1] = sse[k]; /* compute the covariance. */ for (i = 0, sum = 0; i < dt.m.nobs; i++) sum += (dt.col[j][i] - cur_mean[0]) * (dt.col[k][i] - cur_mean[1]); }/*THEN*/ else { for (i = 0, nc = 0; i < dt.m.nobs; i++) { if (ISNAN(dt.col[j][i]) || ISNAN(dt.col[k][i])) continue; xx[nc] = dt.col[j][i]; yy[nc++] = dt.col[k][i]; }/*FOR*/ /* if there are no complete observations, take the variables to be * independent. */ if (nc == 0) continue; cur_mean[0] = c_mean(xx, nc); cur_mean[1] = c_mean(yy, nc); cur_sse[0] = c_sse(xx, cur_mean[0], nc); cur_sse[1] = c_sse(yy, cur_mean[1], nc); /* compute the covariance. */ for (i = 0, sum = 0; i < nc; i++) sum += (xx[i] - cur_mean[0]) * (yy[i] - cur_mean[1]); }/*ELSE*/ /* safety check against "divide by zero" errors. */ if ((cur_sse[0] < tol) || (cur_sse[1] < tol)) sum = 0; else sum /= sqrt(cur_sse[0] * cur_sse[1]); /* test the correlation against the threshold. */ if (fabsl(sum) > t) { if (debuglevel > 0) Rprintf("%s is collinear with %s, dropping %s with COR = %.4Lf\n", dt.m.names[j], dt.m.names[k], dt.m.names[k], sum); /* flag the variable for removal. */ dt.m.flag[k].drop = TRUE; dropped++; }/*THEN*/ }/*FOR*/ }/*FOR*/ /* set up the return value. */ PROTECT(result = allocVector(VECSXP, dt.m.ncols - dropped)); PROTECT(colnames = allocVector(STRSXP, dt.m.ncols - dropped)); for (j = 0, k = 0; j < dt.m.ncols; j++) if (!dt.m.flag[j].drop) { SET_STRING_ELT(colnames, k, mkChar(dt.m.names[j])); SET_VECTOR_ELT(result, k++, VECTOR_ELT(data, j)); }/*THEN*/ setAttrib(result, R_NamesSymbol, colnames); /* make it a data frame. */ minimal_data_frame(result); Free1D(mean); Free1D(sse); Free1D(xx); Free1D(yy); FreeGDT(dt, FALSE); UNPROTECT(2); return result; }/*DEDUP*/
int main(int argc,char *argv[]){ FILE *file; int lines,i; char *pos; int split=':'; char buf[512]; float alpha=0.5; float mean; float sv; int *lset,*sset,*ka; //socket part variable statement struct sockaddr_in serv; int sd; if(argc<2) { printf("usage:./a.out servaddr\n"); return -1; } if((file=fopen(PATH,"r"))==NULL) { printf("open file error\n"); return -1; } lines=getlines(file); int *h=malloc(lines*sizeof(int)); //int *h=malloc(8000*sizeof(int)); int line=0; if(h==NULL) { printf("malloc h error\n"); return -1; } //reset the file point fseek(file,0L,SEEK_SET); //printf("current file offset:%d\n",(int)ftello(file)); while(fgets(buf,sizeof(buf),file)){ pos=strrchr(buf,split); if(pos==NULL) { printf("wrong format\n"); return -1; } buf[strlen(buf)-3]='\0'; pos+=2; h[line++]=atoi(pos); printf("%d\n",h[line-1]); } mean=c_mean(h,lines); sv=c_sig(h,lines,mean); printf("%.2f\n",mean); printf("%.2f\n",sv); qp=mean+alpha*sv; qs=mean-alpha*sv; printf("%.2f\n",qp); printf("%.2f\n",qs); if(seq(h,lines,&lset)<0) { printf("seq error\n"); return -1; } //test lset printf("lset size:%d\n",lset[0]); for(i=1;i<=lset[0];i++) { printf("%d ",lset[i]); } //socket logic to send L,so you had better check forward logic; //sockaddr init bzero(&serv,sizeof(struct sockaddr_in)); serv.sin_family=AF_INET; serv.sin_port=htons(PORT); serv.sin_addr.s_addr=inet_addr(argv[1]); if((sd=socket(AF_INET,SOCK_STREAM,0))<0) { printf("socket error\n"); return -1; } if(connect(sd,(const struct sockaddr *)&serv,sizeof(struct sockaddr))<0) { printf("connect error\n"); return -1; } //send lset,the algorithm select a random subset of lset,we set lset directly here write(sd,lset,(lset[0]+1)*sizeof(int)); int len; printf("wait for sset from bob\n"); read(sd,&len,sizeof(int)); printf("sset from bob comes\n"); printf("sset len:%d\n",len); sset=malloc((len+1)*sizeof(int)); sset[0]=len; if(sset==NULL){ printf("malloc sset error\n"); return -1; } read(sd,sset+1,len*sizeof(int)); //sset test for(i=1;i<=len;i++) { printf("%d ",sset[i]); } printf("\n"); close(sd); //generate key if(key_gen(h,sset,&ka)==-1) { printf("key_gen error\n"); return -1; } for(i=0;i<sset[0];i++){ printf("%d",ka[i]); } printf("\n"); return 0; }
int main() { //initialize testing array float testVector[] = {0.1f,0.2f,0.3f,0.4f,0.5f}; /*COMMENTED OUT LENGTH PARAM AS IT IS INCLUDED IN HEADER FILE*/ //get the size of the array //int length = sizeof(testVector)/sizeof(float); //initiate empty output array of size length float outputArrayC[length]; //initialize the struct at p=r=q 0.1 and x=k=0 kalman_state currentState = {0.1f, 0.1f, 0.0f , 0.1f, 0.0f}; //call function Kalmanfilter_C Kalmanfilter_C(measurements, outputArrayC, ¤tState, length); //initiate empty output array of size length float outputArrayASM[length]; //reinitialize the struct at p=r=q 0.1 and x=k=0 currentState.p = DEF_p; currentState.r = DEF_r; currentState.k = DEF_k; currentState.q = DEF_q; currentState.x = DEF_x; //call subroutine Kalmanfilter_asm Kalmanfilter_asm(measurements, outputArrayASM, ¤tState, length ); //Check for correctness with a error tolerance of 0.000001 float errorTolerance = 0.000001f; float errorPercentage = 0.01; //is_valid(outputArrayC, outputArrayASM, length, errorTolerance, "c vs asm"); //is_valid_relative(outputArrayC, outputArrayASM, length, errorTolerance, errorPercentage,"c vs asm"); int p; //print KalmanFilter output for ( p = 0; p < length; p++ ) { printf("OutputASM: %f & OutputC %f\n", outputArrayASM[p], outputArrayC[p]); } float differenceC[length]; float differenceCMSIS[length]; //Difference arm_sub_f32 (measurements, outputArrayC, differenceCMSIS, length); c_sub(measurements, outputArrayC, differenceC, length); //is_valid(differenceC, differenceCMSIS, length, errorTolerance, "Difference"); //is_valid_relative(differenceC, differenceCMSIS, length, errorTolerance, errorPercentage,"Difference"); //Print difference vector for ( p = 0; p < length; p++ ) { printf("DifferenceC: %f & DifferenceCMSIS %f \n", differenceC[p], differenceCMSIS[p]); } //Mean float meanCMSIS; float meanC; arm_mean_f32 (differenceCMSIS, length , &meanCMSIS); c_mean(differenceC,length, &meanC); //is_valid(&meanC, &meanCMSIS, 1, errorTolerance, "mean"); //is_valid_relative(&meanC, &meanCMSIS, 1, errorTolerance, errorPercentage, "mean"); //Print mean values printf("MeanC: %f & MeanCMSIS %f \n", meanC, meanCMSIS); //STD float stdC; float stdCMSIS; arm_std_f32 (differenceCMSIS, length, &stdCMSIS); c_std(differenceC, length, &stdC); //is_valid(&stdC, &stdCMSIS, 1, errorTolerance, "STD"); //is_valid_relative(&stdC, &stdCMSIS, 1, errorTolerance, errorPercentage,"STD"); //Print std values printf("StandardDevC: %f & StandardDevCMSIS %f \n", stdC, stdCMSIS); //correlation float corC[2*length-1]; float corCMSIS[2*length-1]; arm_correlate_f32 (measurements, length, outputArrayC, length, corCMSIS); c_correlate(measurements, outputArrayC, corC, length); //is_valid(corC, corCMSIS, 2*length-1, errorTolerance, "correlation"); //is_valid_relative(corC, corCMSIS, 2*length-1, errorTolerance, errorPercentage, "correlation"); //convolution float convC[2*length-1]; float convCMSIS[2*length-1]; arm_conv_f32 (measurements, length, outputArrayC, length, convCMSIS); c_conv(measurements, outputArrayC, convC, length); //is_valid(convC, convCMSIS, 2*length-1, errorTolerance, "convolution"); //is_valid_relative(convC, convCMSIS, 2*length-1, errorTolerance, errorPercentage, "convolution"); //Print correlation and convolution values for ( p = 0; p < (2*length-1); p++ ) { printf("ConvC: %f & ConvCMSIS: %f \n", convC[p], convCMSIS[p]); } for ( p = 0; p < (2*length-1); p++ ) { printf("CorrelateC: %f & CorrelatCMSIS: %f \n", corC[p], corCMSIS[p]); } return 0; }