summaryrefslogtreecommitdiff
path: root/gr-dtv/lib/dvbt/dvbt_ofdm_sym_acquisition_impl.h
blob: 669e1e19aefdc7be0e21c20940cae4bf0ecc2f34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* -*- c++ -*- */
/*
 * Copyright 2015 Free Software Foundation, Inc.
 *
 * SPDX-License-Identifier: GPL-3.0-or-later
 *
 */

#ifndef INCLUDED_DTV_DVBT_OFDM_SYM_ACQUISITION_IMPL_H
#define INCLUDED_DTV_DVBT_OFDM_SYM_ACQUISITION_IMPL_H

#include <gnuradio/dtv/dvbt_ofdm_sym_acquisition.h>
#include <volk/volk_alloc.hh>

namespace gr {
namespace dtv {

class dvbt_ofdm_sym_acquisition_impl : public dvbt_ofdm_sym_acquisition
{
private:
    const int d_fft_length;
    const int d_cp_length;
    const float d_rho;

    volk::vector<gr_complex> d_conj;
    volk::vector<float> d_norm;
    volk::vector<gr_complex> d_corr;
    volk::vector<gr_complex> d_gamma;
    volk::vector<float> d_lambda;

    // For peak detector
    float d_threshold_factor_rise;
    float d_avg_alpha;
    float d_avg_min;
    float d_avg_max;
    float d_phase = 0.0;
    double d_phaseinc = 0.0;
    int d_cp_found = 0;
    double d_nextphaseinc = 0;
    int d_nextpos = 0;

    int d_initial_acquisition = 0;

    int d_cp_start = 0;

    volk::vector<gr_complex> d_derot;
    int d_to_consume = 0;
    int d_to_out = 0;
    int d_consumed = 0;
    int d_out = 0;

    int ml_sync(const gr_complex* in,
                int lookup_start,
                int lookup_stop,
                int* cp_pos,
                gr_complex* derot,
                int* to_consume,
                int* to_out);

    int peak_detect_init(float threshold_factor_rise, float alpha);

    int peak_detect_process(const float* datain,
                            const int datain_length,
                            int* peak_pos,
                            int* peak_max);

    void send_sync_start();

    void derotate(const gr_complex* in, gr_complex* out);

public:
    dvbt_ofdm_sym_acquisition_impl(
        int blocks, int fft_length, int occupied_tones, int cp_length, float snr);
    ~dvbt_ofdm_sym_acquisition_impl() override;

    void forecast(int noutput_items, gr_vector_int& ninput_items_required) override;

    int general_work(int noutput_items,
                     gr_vector_int& ninput_items,
                     gr_vector_const_void_star& input_items,
                     gr_vector_void_star& output_items) override;
};

} // namespace dtv
} // namespace gr

#endif /* INCLUDED_DTV_DVBT_OFDM_SYM_ACQUISITION_IMPL_H */