Skip to content

File timing_est_core.h

File List > doppler > timing_est > timing_est_core.h

Go to the documentation of this file

#ifndef DP_TIMING_EST_CORE_H
#define DP_TIMING_EST_CORE_H

#include "doppler/RateConverter/RateConverter_core.h"
#include "doppler/clib_common.h"
#include "doppler/dp_state.h"
#include "doppler/jm_perf.h"
#include "doppler/nco/nco_core.h"
#include "doppler/resamp/resamp_core.h"
#include "doppler/hbdecim/hbdecim_core.h"
#include "doppler/cic/cic_core.h"
#include "doppler/fir/fir_core.h"
#include "doppler/resample/resample_core.h"
#ifdef __cplusplus
extern "C" {
#endif

#define TIMING_EST_STATE_MAGIC DP_FOURCC ('T', 'M', 'G', 'E')
#define TIMING_EST_STATE_VERSION 2u /* v2: the lead-in left, and a matched
                                      instance's converter */
#define TIMING_EST_MATCHED_SPS 4.0
#define TIMING_EST_MATCHED_PHASES 1024u

typedef struct {
    double tau;     
    double rate;    
    double quality; 
    double power;   
    double symbols; 
    int has_rate;   
    double eye;     
} dp_timing_estimate_t;

typedef struct {
    double   sps;       
    double   clock_sps; 
    uint32_t inc;       
    uint32_t phase;     
    uint64_t count;     
    /* the block in progress */
    double   c_re;      
    double   c_im;      
    double   pwr;       
    uint64_t blk_n;     
    uint64_t blk_first; 
    /* the previous block, for the rate */
    int      have_prev; 
    double   prev_tau;  
    double   prev_mid;  
    /* the matched flavor */
    dp_RateConverter_state_t *mf; 
    uint64_t lead;      
    uint64_t lead_left; 
    double   delay;     
} dp_timing_est_state_t;

dp_timing_est_state_t *dp_timing_est_create(double sps);

dp_timing_est_state_t *dp_timing_est_create_matched(double sps, int pulse, double beta, size_t span);

void dp_timing_est_destroy(dp_timing_est_state_t *state);

void dp_timing_est_reset(dp_timing_est_state_t *state);

JM_FORCEINLINE void
dp_timing_est_accumulate (dp_timing_est_state_t *state, double power)
{
  if (state->blk_n == 0)
    state->blk_first = state->count;
  double th = 6.283185307179586476925 * nco_word_to_norm (state->phase);
  state->c_re += power * cos (th);
  state->c_im -= power * sin (th);
  state->pwr += power;
  state->phase += state->inc;
  state->count++;
  state->blk_n++;
}

dp_timing_estimate_t dp_timing_est_finish(dp_timing_est_state_t *state);

void dp_timing_est_push(dp_timing_est_state_t *state, const float _Complex *in, size_t n_in);

size_t dp_timing_est_state_bytes(const dp_timing_est_state_t *state);

void dp_timing_est_get_state(const dp_timing_est_state_t *state, void *blob);

int dp_timing_est_set_state(dp_timing_est_state_t *state, const void *blob);

dp_timing_estimate_t dp_timing_est_estimate(dp_timing_est_state_t *state, const float _Complex *in, size_t n_in);
#ifdef __cplusplus
}
#endif

#endif /* DP_TIMING_EST_CORE_H */