// Helper function to keep code base small void fec_test_codec(fec_scheme _fs, unsigned int _n, void * _opts) { #if !LIBFEC_ENABLED if ( _fs == LIQUID_FEC_CONV_V27 || _fs == LIQUID_FEC_CONV_V29 || _fs == LIQUID_FEC_CONV_V39 || _fs == LIQUID_FEC_CONV_V615 || _fs == LIQUID_FEC_CONV_V27P23 || _fs == LIQUID_FEC_CONV_V27P34 || _fs == LIQUID_FEC_CONV_V27P45 || _fs == LIQUID_FEC_CONV_V27P56 || _fs == LIQUID_FEC_CONV_V27P67 || _fs == LIQUID_FEC_CONV_V27P78 || _fs == LIQUID_FEC_CONV_V29P23 || _fs == LIQUID_FEC_CONV_V29P34 || _fs == LIQUID_FEC_CONV_V29P45 || _fs == LIQUID_FEC_CONV_V29P56 || _fs == LIQUID_FEC_CONV_V29P67 || _fs == LIQUID_FEC_CONV_V29P78 || _fs == LIQUID_FEC_RS_M8) { AUTOTEST_WARN("convolutional, Reed-Solomon codes unavailable (install libfec)\n"); return; } #endif // generate fec object fec q = fec_create(_fs,_opts); // create arrays unsigned int n_enc = fec_get_enc_msg_length(_fs,_n); unsigned char msg[_n]; // original message unsigned char msg_enc[n_enc]; // encoded message unsigned char msg_dec[_n]; // decoded message // initialze message unsigned int i; for (i=0; i<_n; i++) { msg[i] = rand() & 0xff; msg_dec[i] = 0; } // encode message fec_encode(q,_n,msg,msg_enc); // channel: add single error msg_enc[0] ^= 0x01; // decode message fec_decode(q,_n,msg_enc,msg_dec); // validate output CONTEND_SAME_DATA(msg,msg_dec,_n); // clean up objects fec_destroy(q); }
// Helper function to keep code base small void modem_test_demodstats(modulation_scheme _ms) { // generate mod/demod modem mod = modem_create(_ms); modem demod = modem_create(_ms); // run the test unsigned int i, s, M = 1 << modem_get_bps(mod); float complex x; float complex x_hat; // rotated symbol float demodstats; float phi = 0.01f; for (i=0; i<M; i++) { // reset modem objects modem_reset(mod); modem_reset(demod); // modulate symbol modem_modulate(mod, i, &x); // ignore rare condition where modulated symbol is (0,0) // (e.g. APSK-8) if (cabsf(x) < 1e-3f) continue; // add phase offsets x_hat = x * cexpf( phi*_Complex_I); // demod positive phase signal, and ensure demodulator // maps to appropriate symbol modem_demodulate(demod, x_hat, &s); if (s != i) AUTOTEST_WARN("modem_test_demodstats(), output symbol does not match"); demodstats = modem_get_demodulator_phase_error(demod); CONTEND_EXPRESSION(demodstats > 0.0f); } // repeat with negative phase error for (i=0; i<M; i++) { // reset modem objects modem_reset(mod); modem_reset(demod); // modulate symbol modem_modulate(mod, i, &x); // ignore rare condition where modulated symbol is (0,0) // (e.g. APSK-8) if (cabsf(x) < 1e-3f) continue; // add phase offsets x_hat = x * cexpf(-phi*_Complex_I); // demod positive phase signal, and ensure demodulator // maps to appropriate symbol modem_demodulate(demod, x_hat, &s); if (s != i) AUTOTEST_WARN("modem_test_demodstats(), output symbol does not match"); demodstats = modem_get_demodulator_phase_error(demod); CONTEND_EXPRESSION(demodstats < 0.0f); } // clean up allocated objects up modem_destroy(mod); modem_destroy(demod); }