void gmskframesync_debug_enable(gmskframesync _q) { // create debugging objects if necessary #if DEBUG_GMSKFRAMESYNC if (!_q->debug_objects_created) { _q->debug_x = windowcf_create(DEBUG_GMSKFRAMESYNC_BUFFER_LEN); _q->debug_fi = windowf_create(DEBUG_GMSKFRAMESYNC_BUFFER_LEN); _q->debug_mf = windowf_create(DEBUG_GMSKFRAMESYNC_BUFFER_LEN); _q->debug_framesyms = windowf_create(DEBUG_GMSKFRAMESYNC_BUFFER_LEN); } // set debugging flags _q->debug_enabled = 1; _q->debug_objects_created = 1; #else fprintf(stderr,"gmskframesync_debug_enable(): compile-time debugging disabled\n"); #endif }
// create gmskdem object // _k : samples/symbol // _m : filter delay (symbols) // _BT : excess bandwidth factor gmskdem gmskdem_create(unsigned int _k, unsigned int _m, float _BT) { if (_k < 2) { fprintf(stderr,"error: gmskdem_create(), samples/symbol must be at least 2\n"); exit(1); } else if (_m < 1) { fprintf(stderr,"error: gmskdem_create(), symbol delay must be at least 1\n"); exit(1); } else if (_BT <= 0.0f || _BT >= 1.0f) { fprintf(stderr,"error: gmskdem_create(), bandwidth/time product must be in (0,1)\n"); exit(1); } // allocate memory for main object gmskdem q = (gmskdem)malloc(sizeof(struct gmskdem_s)); // set properties q->k = _k; q->m = _m; q->BT = _BT; // allocate memory for filter taps q->h_len = 2*(q->k)*(q->m)+1; q->h = (float*) malloc(q->h_len * sizeof(float)); // compute filter coefficients liquid_firdes_gmskrx(q->k, q->m, q->BT, 0.0f, q->h); #if GMSKDEM_USE_EQUALIZER // receiver matched filter/equalizer q->eq = eqlms_rrrf_create_rnyquist(LIQUID_RNYQUIST_GMSKRX, q->k, q->m, q->BT, 0.0f); eqlms_rrrf_set_bw(q->eq, 0.01f); q->k_inv = 1.0f / (float)(q->k); #else // create filter object q->filter = firfilt_rrrf_create(q->h, q->h_len); #endif // reset modem state gmskdem_reset(q); #if DEBUG_GMSKDEM q->debug_mfout = windowf_create(DEBUG_BUFFER_LEN); #endif // return modem object return q; }
int main (int argc, char ** argv) { w=windowcf_create(SPECTRUM_FFT_LENGTH); wchA = windowcf_create(TRACK_LENGTH); wchB = windowcf_create(TRACK_LENGTH); wchC = windowcf_create(TRACK_LENGTH); wchA_filtered = windowcf_create(TRACK_LENGTH); wchB_filtered = windowcf_create(TRACK_LENGTH); wchC_filtered = windowcf_create(TRACK_LENGTH); wmag_buffer = windowf_create(TRACK_LENGTH); nco = nco_crcf_create(LIQUID_NCO); std::cout << "hydromath daemon is beginning..." << std::endl; std::cout << "NOTE: if this is symhydromath you must pass in a matfile" << std::endl; std::cout << argv[1] << std::endl; shm_init(); shm_getg(hydrophones_results_track, shm_results_track); shm_getg(hydrophones_results_spectrum, shm_results_spectrum); //shm_results_track.tracked_ping_count=0; shm_results_track.tracked_ping_time=0; if (argc > 1) { udp_init(argv[1]); } else { udp_init(""); } //std::thread track_thread(direction_loop); // //std::thread spectrum_thread(spectrum_loop); track_sample_idx = 0; while (loop(&spt) == 0) { shm_getg(hydrophones_settings, shm_settings); for (int i = 0; i < 3*CHANNEL_DEPTH; i+=3) { windowcf_push(w, std::complex<float>(spt.data[i+1],0)); //This uses channel B windowcf_push(wchA, std::complex<float>(spt.data[i],0)); windowcf_push(wchB, std::complex<float>(spt.data[i+1],0)); windowcf_push(wchC, std::complex<float>(spt.data[i+2],0)); } current_sample_count+=CHANNEL_DEPTH; do_spectrum(); do_track(); } printf("loop done %li =ci\n",current_sample_count/CHANNEL_DEPTH); return 0; }
// create ampmodem object // _m : modulation index // _fc : carrier frequency // _type : AM type (e.g. LIQUID_AMPMODEM_DSB) // _suppressed_carrier : carrier suppression flag ampmodem ampmodem_create(float _m, float _fc, liquid_ampmodem_type _type, int _suppressed_carrier) { ampmodem q = (ampmodem) malloc(sizeof(struct ampmodem_s)); q->type = _type; q->m = _m; q->fc = _fc; q->suppressed_carrier = (_suppressed_carrier == 0) ? 0 : 1; // create nco, pll objects q->oscillator = nco_crcf_create(LIQUID_NCO); nco_crcf_set_frequency(q->oscillator, 2*M_PI*q->fc); nco_crcf_pll_set_bandwidth(q->oscillator,0.05f); // suppressed carrier q->ssb_alpha = 0.01f; q->ssb_q_hat = 0.0f; // single side-band q->hilbert = firhilbf_create(9, 60.0f); // double side-band ampmodem_reset(q); // debugging #if DEBUG_AMPMODEM q->debug_x = windowcf_create(DEBUG_AMPMODEM_BUFFER_LEN); q->debug_phase_error = windowf_create(DEBUG_AMPMODEM_BUFFER_LEN); q->debug_freq_error = windowf_create(DEBUG_AMPMODEM_BUFFER_LEN); #endif return q; }
// enable debugging void ofdmframesync_debug_enable(ofdmframesync _q) { // create debugging objects if necessary #if DEBUG_OFDMFRAMESYNC if (_q->debug_objects_created) return; _q->debug_x = windowcf_create(DEBUG_OFDMFRAMESYNC_BUFFER_LEN); _q->debug_rssi = windowf_create(DEBUG_OFDMFRAMESYNC_BUFFER_LEN); _q->debug_framesyms = windowcf_create(DEBUG_OFDMFRAMESYNC_BUFFER_LEN); _q->G_hat = (float complex*) malloc((_q->M)*sizeof(float complex)); _q->px = (float*) malloc((_q->M_pilot)*sizeof(float)); _q->py = (float*) malloc((_q->M_pilot)*sizeof(float)); _q->debug_pilot_0 = windowf_create(DEBUG_OFDMFRAMESYNC_BUFFER_LEN); _q->debug_pilot_1 = windowf_create(DEBUG_OFDMFRAMESYNC_BUFFER_LEN); _q->debug_enabled = 1; _q->debug_objects_created = 1; #else fprintf(stderr,"ofdmframesync_debug_enable(): compile-time debugging disabled\n"); #endif }
void wlanframesync_debug_enable(wlanframesync _q) { // create debugging objects if necessary #if DEBUG_WLANFRAMESYNC // agc, rssi if (_q->agc_rx == NULL) _q->agc_rx = agc_crcf_create(); agc_crcf_set_bandwidth(_q->agc_rx, 1e-2f); agc_crcf_set_gain_limits(_q->agc_rx, 1.0f, 1e7f); if (_q->debug_x == NULL) _q->debug_x = windowcf_create(DEBUG_WLANFRAMESYNC_BUFFER_LEN); if (_q->debug_rssi == NULL) _q->debug_rssi = windowf_create(DEBUG_WLANFRAMESYNC_BUFFER_LEN); if (_q->debug_framesyms == NULL) _q->debug_framesyms = windowcf_create(DEBUG_WLANFRAMESYNC_BUFFER_LEN); _q->debug_enabled = 1; #else fprintf(stderr,"wlanframesync_debug_enable(): compile-time debugging disabled\n"); #endif }
// create synchronizer object from external coefficients // _k : samples per symbol // _M : number of filters in the bank // _h : matched filter coefficients // _h_len : length of matched filter SYMSYNC() SYMSYNC(_create)(unsigned int _k, unsigned int _M, TC * _h, unsigned int _h_len) { // validate input if (_k < 2) { fprintf(stderr,"error: symsync_%s_create(), input sample rate must be at least 2\n", EXTENSION_FULL); exit(1); } else if (_h_len == 0) { fprintf(stderr,"error: symsync_%s_create(), filter length must be greater than zero\n", EXTENSION_FULL); exit(1); } else if (_M == 0) { fprintf(stderr,"error: symsync_%s_create(), number of filter banks must be greater than zero\n", EXTENSION_FULL); exit(1); } SYMSYNC() q = (SYMSYNC()) malloc(sizeof(struct SYMSYNC(_s))); q->k = _k; q->M = _M; q->tau = 0.0f; q->bf = 0.0f; q->b = 0; // set output rate (nominally 1, full decimation) SYMSYNC(_set_output_rate)(q, 1); // TODO: validate length q->h_len = (_h_len-1)/q->M; // compute derivative filter TC dh[_h_len]; float hdh_max = 0.0f; unsigned int i; for (i=0; i<_h_len; i++) { if (i==0) { dh[i] = _h[i+1] - _h[_h_len-1]; } else if (i==_h_len-1) { dh[i] = _h[0] - _h[i-1]; } else { dh[i] = _h[i+1] - _h[i-1]; } // find maximum of h*dh if ( fabsf(_h[i]*dh[i]) > hdh_max || i==0 ) hdh_max = fabsf(_h[i]*dh[i]); } // apply scaling factor for normalized response // TODO: scale to 1.0 for consistency for (i=0; i<_h_len; i++) dh[i] *= 0.06f / hdh_max; q->mf = FIRPFB(_create)(q->M, _h, _h_len); q->dmf = FIRPFB(_create)(q->M, dh, _h_len); // reset state and initialize loop filter q->A[0] = 1.0f; q->B[0] = 0.0f; q->A[1] = 0.0f; q->B[1] = 0.0f; q->A[2] = 0.0f; q->B[2] = 0.0f; q->pll = iirfiltsos_rrrf_create(q->B, q->A); SYMSYNC(_reset)(q); SYMSYNC(_set_lf_bw)(q, 0.01f); // set output rate nominally at 1 sample/symbol (full decimation) SYMSYNC(_set_output_rate)(q, 1); // unlock loop control SYMSYNC(_unlock)(q); #if DEBUG_SYMSYNC q->debug_del = windowf_create(DEBUG_BUFFER_LEN); q->debug_tau = windowf_create(DEBUG_BUFFER_LEN); q->debug_bsoft = windowf_create(DEBUG_BUFFER_LEN); q->debug_b = windowf_create(DEBUG_BUFFER_LEN); q->debug_q_hat = windowf_create(DEBUG_BUFFER_LEN); #endif // return main object return q; }
ofdmoqamframe64sync ofdmoqamframe64sync_create(unsigned int _m, float _beta, ofdmoqamframe64sync_callback _callback, void * _userdata) { ofdmoqamframe64sync q = (ofdmoqamframe64sync) malloc(sizeof(struct ofdmoqamframe64sync_s)); q->num_subcarriers = 64; // validate input if (_m < 1) { fprintf(stderr,"error: ofdmoqamframe64sync_create(), filter delay must be > 0\n"); exit(1); } else if (_beta < 0.0f) { fprintf(stderr,"error: ofdmoqamframe64sync_create(), filter excess bandwidth must be > 0\n"); exit(1); } q->m = _m; q->beta = _beta; // synchronizer parameters q->rxx_thresh = 0.60f; // auto-correlation threshold q->rxy_thresh = 0.60f; // cross-correlation threshold q->zeta = 64.0f/sqrtf(52.0f); // scaling factor // create analysis filter banks q->ca0 = firpfbch_create(q->num_subcarriers, q->m, q->beta, 0.0f /*dt*/,FIRPFBCH_ROOTNYQUIST,0/*gradient*/); q->ca1 = firpfbch_create(q->num_subcarriers, q->m, q->beta, 0.0f /*dt*/,FIRPFBCH_ROOTNYQUIST,0/*gradient*/); q->X0 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->X1 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->Y0 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->Y1 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); // allocate memory for PLCP arrays q->S0 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->S1 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->S2 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); ofdmoqamframe64_init_S0(q->S0); ofdmoqamframe64_init_S1(q->S1); ofdmoqamframe64_init_S2(q->S2); unsigned int i; for (i=0; i<q->num_subcarriers; i++) { q->S0[i] *= q->zeta; q->S1[i] *= q->zeta; q->S2[i] *= q->zeta; } q->S1a = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->S1b = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); // set pilot sequence q->ms_pilot = msequence_create_default(8); q->x_phase[0] = -21.0f; q->x_phase[1] = -7.0f; q->x_phase[2] = 7.0f; q->x_phase[3] = 21.0f; // create NCO for pilots q->nco_pilot = nco_crcf_create(LIQUID_VCO); q->pll_pilot = pll_create(); pll_set_bandwidth(q->pll_pilot,0.01f); pll_set_damping_factor(q->pll_pilot,4.0f); // create agc | signal detection object q->sigdet = agc_crcf_create(); agc_crcf_set_bandwidth(q->sigdet,0.1f); // create NCO for CFO compensation q->nco_rx = nco_crcf_create(LIQUID_VCO); // create auto-correlator objects q->autocorr_length = OFDMOQAMFRAME64SYNC_AUTOCORR_LEN; q->autocorr_delay = q->num_subcarriers / 4; q->autocorr = autocorr_cccf_create(q->autocorr_length, q->autocorr_delay); // create cross-correlator object q->hxy = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); ofdmoqam cs = ofdmoqam_create(q->num_subcarriers,q->m,q->beta, 0.0f, // dt OFDMOQAM_SYNTHESIZER, 0); // gradient for (i=0; i<2*(q->m); i++) ofdmoqam_execute(cs,q->S1,q->hxy); // time reverse, complex conjugate (same as fftshift for // this particular sequence) memmove(q->X0, q->hxy, 64*sizeof(float complex)); for (i=0; i<64; i++) q->hxy[i] = conjf(q->X0[64-i-1]); // fftshift //fft_shift(q->hxy,64); q->crosscorr = firfilt_cccf_create(q->hxy, q->num_subcarriers); ofdmoqam_destroy(cs); // input buffer q->input_buffer = windowcf_create((q->num_subcarriers)); // gain q->g = 1.0f; q->G0 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->G1 = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->G = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); q->data = (float complex*) malloc((q->num_subcarriers)*sizeof(float complex)); // reset object ofdmoqamframe64sync_reset(q); #if DEBUG_OFDMOQAMFRAME64SYNC q->debug_x = windowcf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); q->debug_rxx= windowcf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); q->debug_rxy= windowcf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); q->debug_framesyms= windowcf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); q->debug_pilotphase= windowf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); q->debug_pilotphase_hat= windowf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); q->debug_rssi= windowf_create(DEBUG_OFDMOQAMFRAME64SYNC_BUFFER_LEN); #endif q->callback = _callback; q->userdata = _userdata; return q; }
// // AUTOTEST: windowf // void autotest_windowf() { float v[] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; float *r; // reader pointer float x; // temporary value holder unsigned int i; float test0[10] = {0,0,0,0,0,0,0,0,0,0}; float test1[10] = {0,0,0,0,0,0,1,1,1,1}; float test2[10] = {0,0,1,1,1,1,9,8,7,6}; float test3[10] = {1,1,9,8,7,6,3,3,3,3}; float test4[10] = {7,6,3,3,3,3,5,5,5,5}; float test5[6] = {3,3,5,5,5,5}; float test6[6] = {5,5,5,5,6,7}; float test7[10] = {0,0,0,0,5,5,5,5,6,7}; float test8[10] = {0,0,0,0,0,0,0,0,0,0}; // create window // 0 0 0 0 0 0 0 0 0 0 windowf w = windowf_create(10); windowf_read(w, &r); CONTEND_SAME_DATA(r,test0,10*sizeof(float)); // push 4 elements // 0 0 0 0 0 0 1 1 1 1 windowf_push(w, 1); windowf_push(w, 1); windowf_push(w, 1); windowf_push(w, 1); windowf_read(w, &r); CONTEND_SAME_DATA(r,test1,10*sizeof(float)); // push 4 more elements // 0 0 1 1 1 1 9 8 7 6 windowf_write(w, v, 4); windowf_read(w, &r); CONTEND_SAME_DATA(r,test2,10*sizeof(float)); // push 4 more elements // 1 1 9 8 7 6 3 3 3 3 windowf_push(w, 3); windowf_push(w, 3); windowf_push(w, 3); windowf_push(w, 3); windowf_read(w, &r); CONTEND_SAME_DATA(r,test3,10*sizeof(float)); // test indexing operation windowf_index(w, 0, &x); CONTEND_EQUALITY(x, 1); windowf_index(w, 1, &x); CONTEND_EQUALITY(x, 1); windowf_index(w, 2, &x); CONTEND_EQUALITY(x, 9); windowf_index(w, 3, &x); CONTEND_EQUALITY(x, 8); windowf_index(w, 4, &x); CONTEND_EQUALITY(x, 7); windowf_index(w, 5, &x); CONTEND_EQUALITY(x, 6); windowf_index(w, 6, &x); CONTEND_EQUALITY(x, 3); windowf_index(w, 7, &x); CONTEND_EQUALITY(x, 3); windowf_index(w, 8, &x); CONTEND_EQUALITY(x, 3); windowf_index(w, 9, &x); CONTEND_EQUALITY(x, 3); // push 4 more elements // 7 6 3 3 3 3 5 5 5 5 windowf_push(w, 5); windowf_push(w, 5); windowf_push(w, 5); windowf_push(w, 5); windowf_read(w, &r); CONTEND_SAME_DATA(r,test4,10*sizeof(float)); if (liquid_autotest_verbose) windowf_debug_print(w); // recreate window (truncate to last 6 elements) // 3 3 5 5 5 5 w = windowf_recreate(w,6); windowf_read(w, &r); CONTEND_SAME_DATA(r,test5,6*sizeof(float)); // push 2 more elements // 5 5 5 5 6 7 windowf_push(w, 6); windowf_push(w, 7); windowf_read(w, &r); CONTEND_SAME_DATA(r,test6,6*sizeof(float)); // recreate window (extend to 10 elements) // 0 0 0 0 5 5 5 5 6 7 w = windowf_recreate(w,10); windowf_read(w,&r); CONTEND_SAME_DATA(r,test7,10*sizeof(float)); // reset // 0 0 0 0 0 0 0 0 0 0 windowf_reset(w); windowf_read(w, &r); CONTEND_SAME_DATA(r,test8,10*sizeof(float)); if (liquid_autotest_verbose) { // manual print printf("manual output:\n"); for (i=0; i<10; i++) printf("%6u : %f\n", i, r[i]); windowf_debug_print(w); } windowf_destroy(w); printf("done.\n"); }