GNU Radio's SATELLITES Package
doppler_correction_impl.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2022-2023 Daniel Estevez <daniel@destevez.net>.
4 *
5 * This file is part of gr-satellites
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 */
9
10#ifndef INCLUDED_SATELLITES_DOPPLER_CORRECTION_IMPL_H
11#define INCLUDED_SATELLITES_DOPPLER_CORRECTION_IMPL_H
12
13#include <gnuradio/math.h>
15#include <cstdint>
16#include <vector>
17
18namespace gr {
19namespace satellites {
20
22{
23private:
24 double d_phase;
25 double d_samp_rate;
26 size_t d_current_index;
27 double d_t0;
28 uint64_t d_sample_t0;
29 std::vector<double> times;
30 std::vector<double> freqs_rad_per_sample;
31 std::vector<tag_t> d_tags;
32
33 // Used by UHD
34 const pmt::pmt_t d_rx_time_key;
35
36 // Used by gr-difi
37 const pmt::pmt_t d_pck_n_key;
38 const pmt::pmt_t d_full_key;
39 const pmt::pmt_t d_frac_key;
40
41 double d_current_time;
42 double d_current_freq;
43
44 // Implementation taken from gr::block::control_loop
45 void phase_wrap()
46 {
47 while (d_phase > (2 * GR_M_PI))
48 d_phase -= 2 * GR_M_PI;
49 while (d_phase < (-2 * GR_M_PI))
50 d_phase += 2 * GR_M_PI;
51 }
52
53 // Called after a time update. Makes the current index go backwards if
54 // needed because of a time update "to the past".
55 void adjust_current_index()
56 {
57 while ((d_current_index > 0) && (times[d_current_index] > d_t0)) {
58 --d_current_index;
59 }
60 }
61
62 void read_doppler_file(std::string& filename);
63
64public:
65 doppler_correction_impl(std::string& filename, double samp_rate, double t0);
67
68 void set_time(double) override;
69
70 double time() override
71 {
72 gr::thread::scoped_lock guard(d_setlock);
73 return d_current_time;
74 }
75
76 double frequency() override
77 {
78 gr::thread::scoped_lock guard(d_setlock);
79 return d_current_freq * d_samp_rate / (2.0 * GR_M_PI);
80 }
81
82 int work(int noutput_items,
83 gr_vector_const_void_star& input_items,
84 gr_vector_void_star& output_items) override;
85};
86
87} // namespace satellites
88} // namespace gr
89
90#endif /* INCLUDED_SATELLITES_DOPPLER_CORRECTION_IMPL_H */
Definition: doppler_correction_impl.h:22
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) override
doppler_correction_impl(std::string &filename, double samp_rate, double t0)
double frequency() override
Returns the current frequency in Hz.
Definition: doppler_correction_impl.h:76
void set_time(double) override
Sets the current time.
double time() override
Returns the current time.
Definition: doppler_correction_impl.h:70
Performs Doppler correction using a frequency vs. time file.
Definition: doppler_correction.h:46
Definition: ax100_decode.h:17