Revision a663f5b4 gnuradio-core/src/lib/general/gr_ofdm_correlator.cc
| b/gnuradio-core/src/lib/general/gr_ofdm_correlator.cc | ||
|---|---|---|
| 30 | 30 |
|
| 31 | 31 |
#define VERBOSE 0 |
| 32 | 32 |
#define M_TWOPI (2*M_PI) |
| 33 |
#define MAX_NUM_SYMBOLS 1000 |
|
| 33 | 34 |
|
| 34 | 35 |
gr_ofdm_correlator_sptr |
| 35 | 36 |
gr_make_ofdm_correlator (unsigned int occupied_carriers, unsigned int fft_length, |
| 36 | 37 |
unsigned int cplen, |
| 37 | 38 |
const std::vector<gr_complex> &known_symbol1, |
| 38 |
const std::vector<gr_complex> &known_symbol2) |
|
| 39 |
const std::vector<gr_complex> &known_symbol2, |
|
| 40 |
unsigned int max_fft_shift_len) |
|
| 39 | 41 |
{
|
| 40 | 42 |
return gr_ofdm_correlator_sptr (new gr_ofdm_correlator (occupied_carriers, fft_length, cplen, |
| 41 |
known_symbol1, known_symbol2)); |
|
| 43 |
known_symbol1, known_symbol2, |
|
| 44 |
max_fft_shift_len)); |
|
| 42 | 45 |
} |
| 43 | 46 |
|
| 44 | 47 |
gr_ofdm_correlator::gr_ofdm_correlator (unsigned occupied_carriers, unsigned int fft_length, |
| 45 | 48 |
unsigned int cplen, |
| 46 | 49 |
const std::vector<gr_complex> &known_symbol1, |
| 47 |
const std::vector<gr_complex> &known_symbol2) |
|
| 50 |
const std::vector<gr_complex> &known_symbol2, |
|
| 51 |
unsigned int max_fft_shift_len) |
|
| 48 | 52 |
: gr_block ("ofdm_correlator",
|
| 49 | 53 |
gr_make_io_signature (1, 1, sizeof(gr_complex)*fft_length), |
| 50 | 54 |
gr_make_io_signature2 (2, 2, sizeof(gr_complex)*occupied_carriers, sizeof(char))), |
| 51 | 55 |
d_occupied_carriers(occupied_carriers), |
| 52 | 56 |
d_fft_length(fft_length), |
| 53 | 57 |
d_cplen(cplen), |
| 54 |
d_freq_shift_len(5),
|
|
| 58 |
d_freq_shift_len(max_fft_shift_len),
|
|
| 55 | 59 |
d_known_symbol1(known_symbol1), |
| 56 | 60 |
d_known_symbol2(known_symbol2), |
| 57 | 61 |
d_coarse_freq(0), |
| ... | ... | |
| 62 | 66 |
|
| 63 | 67 |
std::vector<gr_complex>::iterator i1, i2; |
| 64 | 68 |
|
| 65 |
int i = 0;
|
|
| 69 |
unsigned int i = 0, j = 0;
|
|
| 66 | 70 |
gr_complex one(1.0, 0.0); |
| 67 | 71 |
for(i1 = d_known_symbol1.begin(), i2 = d_known_symbol2.begin(); i1 != d_known_symbol1.end(); i1++, i2++) {
|
| 68 | 72 |
d_diff_corr_factor[i] = one / ((*i1) * conj(*i2)); |
| 69 | 73 |
i++; |
| 70 | 74 |
} |
| 75 |
|
|
| 76 |
d_phase_lut = new gr_complex[(2*d_freq_shift_len+1) * MAX_NUM_SYMBOLS]; |
|
| 77 |
for(i = 0; i <= 2*d_freq_shift_len; i++) {
|
|
| 78 |
for(j = 0; j < MAX_NUM_SYMBOLS; j++) {
|
|
| 79 |
d_phase_lut[j + i*MAX_NUM_SYMBOLS] = gr_expj(-M_TWOPI*d_cplen/d_fft_length*(i-d_freq_shift_len)*j); |
|
| 80 |
} |
|
| 81 |
} |
|
| 71 | 82 |
} |
| 72 | 83 |
|
| 73 | 84 |
gr_ofdm_correlator::~gr_ofdm_correlator(void) |
| 74 | 85 |
{
|
| 86 |
delete [] d_phase_lut; |
|
| 75 | 87 |
} |
| 76 | 88 |
|
| 77 | 89 |
void |
| ... | ... | |
| 87 | 99 |
{
|
| 88 | 100 |
// return gr_complex(cos(-M_TWOPI*freq_delta*d_cplen/d_fft_length*symbol_count), |
| 89 | 101 |
// sin(-M_TWOPI*freq_delta*d_cplen/d_fft_length*symbol_count)); |
| 90 |
return gr_expj(-M_TWOPI*freq_delta*d_cplen/d_fft_length*symbol_count); |
|
| 102 |
//return gr_expj(-M_TWOPI*freq_delta*d_cplen/d_fft_length*symbol_count); |
|
| 103 |
|
|
| 104 |
assert(d_freq_shift_len + freq_delta >= 0); |
|
| 105 |
assert(symbol_count <= MAX_NUM_SYMBOLS); |
|
| 106 |
|
|
| 107 |
return d_phase_lut[MAX_NUM_SYMBOLS * (d_freq_shift_len + freq_delta) + symbol_count]; |
|
| 91 | 108 |
} |
| 92 | 109 |
|
| 93 | 110 |
bool |
| ... | ... | |
| 132 | 149 |
d_snr_est = 10*log10(fabs(h_sqrd.real()/h_sqrd.imag())); |
| 133 | 150 |
} |
| 134 | 151 |
|
| 152 |
#if VERBOSE |
|
| 135 | 153 |
printf("CORR: Found, bin %d\tSNR Est %f dB\tcorr power fraction %f\n",
|
| 136 | 154 |
search_delta, d_snr_est, h_sqrd.real()/power); |
| 155 |
#endif |
|
| 156 |
|
|
| 137 | 157 |
// search_delta,10*log10(h_sqrd.real()/fabs(h_sqrd.imag())),h_sqrd.real()/power); |
| 138 | 158 |
break; |
| 139 | 159 |
} |
| 140 | 160 |
else {
|
| 141 | 161 |
if(search_delta <= 0) |
| 142 |
search_delta = (-search_delta) + 1;
|
|
| 162 |
search_delta = (-search_delta) + 2;
|
|
| 143 | 163 |
else |
| 144 | 164 |
search_delta = -search_delta; |
| 145 | 165 |
} |
| ... | ... | |
| 161 | 181 |
d_hestimate[i] = 0.5F * (d_known_symbol1[i] / previous[i+zeros_on_left+d_coarse_freq] + |
| 162 | 182 |
d_known_symbol2[i] / (coarse_freq_comp(d_coarse_freq,1)* |
| 163 | 183 |
current[i+zeros_on_left+d_coarse_freq])); |
| 164 |
|
|
| 165 |
#if VERBOSE |
|
| 166 |
fprintf(stderr, "%f %f ", d_hestimate[i].real(), d_hestimate[i].imag()); |
|
| 167 |
#endif |
|
| 168 | 184 |
} |
| 169 | 185 |
#if VERBOSE |
| 170 | 186 |
fprintf(stderr, "\n"); |
Also available in: Unified diff