|
64 | 64 |
|
65 | 65 | #define CN0_EST_LPF_CUTOFF 5 |
66 | 66 |
|
| 67 | +#define INTEG_PERIOD_20_MS 20 |
| 68 | + |
| 69 | +static const u8 integration_periods[] = { |
| 70 | + INTEG_PERIOD_20_MS |
| 71 | +}; |
| 72 | + |
| 73 | +#define INTEG_PERIODS_NUM (sizeof(integration_periods) / \ |
| 74 | + sizeof(integration_periods[0])) |
| 75 | + |
| 76 | +static cn0_est_params_t cn0_est_pre_computed[INTEG_PERIODS_NUM]; |
| 77 | + |
67 | 78 | static struct loop_params { |
68 | 79 | float code_bw, code_zeta, code_k, carr_to_code; |
69 | 80 | float carr_bw, carr_zeta, carr_k, carr_fll_aid_gain; |
@@ -112,6 +123,7 @@ static void tracker_gps_l2cm_update(const tracker_channel_info_t *channel_info, |
112 | 123 |
|
113 | 124 | static bool parse_loop_params(struct setting *s, const char *val); |
114 | 125 | static bool parse_lock_detect_params(struct setting *s, const char *val); |
| 126 | +static void precompute_cn0_est_params(void); |
115 | 127 |
|
116 | 128 | static const tracker_interface_t tracker_interface_gps_l2cm = { |
117 | 129 | .code = CODE_GPS_L2CM, |
@@ -155,6 +167,8 @@ void track_gps_l2cm_register(void) |
155 | 167 | gps_l2cm_trackers[i].data = &gps_l2cm_tracker_data[i]; |
156 | 168 | } |
157 | 169 |
|
| 170 | + precompute_cn0_est_params(); |
| 171 | + |
158 | 172 | tracker_interface_register(&tracker_interface_list_element_gps_l2cm); |
159 | 173 | } |
160 | 174 |
|
@@ -425,9 +439,33 @@ static void tracker_gps_l2cm_update(const tracker_channel_info_t *channel_info, |
425 | 439 | corr_t* cs = data->cs; |
426 | 440 |
|
427 | 441 | /* Update C/N0 estimate */ |
428 | | - common_data->cn0 = cn0_est(&data->cn0_est, |
429 | | - cs[1].I / data->int_ms, |
430 | | - cs[1].Q / data->int_ms); |
| 442 | + { |
| 443 | + cn0_est_params_t params; |
| 444 | + const cn0_est_params_t *pparams = NULL; |
| 445 | + |
| 446 | + /* TODO |
| 447 | + * Store a pointer to the cn0_est_params_t in the gps_l1ca_tracker_data_t |
| 448 | + * structure so we don't have to scan through the whole array each time |
| 449 | + */ |
| 450 | + for(u32 i = 0; i < INTEG_PERIODS_NUM; i++) { |
| 451 | + if(data->int_ms == integration_periods[i]) { |
| 452 | + pparams = &cn0_est_pre_computed[i]; |
| 453 | + break; |
| 454 | + } |
| 455 | + } |
| 456 | + |
| 457 | + if(NULL == pparams) { |
| 458 | + cn0_est_compute_params(¶ms, 1e3f / data->int_ms, CN0_EST_LPF_CUTOFF, |
| 459 | + 1e3f / data->int_ms); |
| 460 | + pparams = ¶ms; |
| 461 | + } |
| 462 | + |
| 463 | + common_data->cn0 = cn0_est(&data->cn0_est, |
| 464 | + pparams, |
| 465 | + (float) cs[1].I/data->int_ms, |
| 466 | + (float) cs[1].Q/data->int_ms); |
| 467 | + } |
| 468 | + |
431 | 469 | if (common_data->cn0 > track_cn0_drop_thres) { |
432 | 470 | common_data->cn0_above_drop_thres_count = common_data->update_count; |
433 | 471 | } |
@@ -570,3 +608,17 @@ static bool parse_lock_detect_params(struct setting *s, const char *val) |
570 | 608 |
|
571 | 609 | return true; |
572 | 610 | } |
| 611 | + |
| 612 | +/* Pre-compute C/N0 estimator and filter parameters. The parameters are |
| 613 | + * computed using equivalent of cn0_est_compute_params() function for |
| 614 | + * integration periods and cut-off frequency defined in this file. |
| 615 | + */ |
| 616 | +static void precompute_cn0_est_params(void) |
| 617 | +{ |
| 618 | + for(u32 i = 0; i < INTEG_PERIODS_NUM; i++) { |
| 619 | + cn0_est_compute_params(&cn0_est_pre_computed[i], |
| 620 | + 1e3f / integration_periods[i], |
| 621 | + CN0_EST_LPF_CUTOFF, |
| 622 | + 1e3f / integration_periods[i]); |
| 623 | + } |
| 624 | +} |
0 commit comments