The Inspector (GNU Radio module gr-inspector)
signal_detector_cvf_impl.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2019 Free Software Foundation Inc..
4  *
5  * This is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * This software is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this software; see the file COPYING. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 #ifndef INCLUDED_INSPECTOR_SIGNAL_DETECTOR_CVF_IMPL_H
22 #define INCLUDED_INSPECTOR_SIGNAL_DETECTOR_CVF_IMPL_H
23 
24 #include <gnuradio/fft/fft.h>
25 #include <gnuradio/filter/firdes.h>
26 #include <gnuradio/filter/single_pole_iir.h>
28 #include <fstream>
29 
30 namespace gr {
31 namespace inspector {
32 
34 {
35 private:
36  bool d_auto_threshold;
37  int d_fft_len;
38  unsigned int d_tmpbuflen;
39  float d_threshold, d_sensitivity, d_average, d_quantization, d_min_bw;
40  float *d_pxx, *d_tmp_pxx, *d_pxx_out, *d_tmpbuf;
41  double d_samp_rate;
42  std::ofstream logfile;
43 
44  std::vector<filter::single_pole_iir<float, float, double>> d_avg_filter;
45  filter::firdes::win_type d_window_type;
46  std::vector<float> d_window;
47  std::vector<std::vector<float>> d_signal_edges;
48  fft::fft_complex* d_fft;
49  std::vector<float> d_freq;
50  const char* d_filename;
51 
52  void write_logfile_header();
53  void write_logfile_entry();
54 
55 public:
56  signal_detector_cvf_impl(double samp_rate,
57  int fft_len,
58  int window_type,
59  float threshold,
60  float sensitivity,
61  bool auto_threshold,
62  float average,
63  float quantization,
64  float min_bw,
65  const char* filename);
66 
68 
69  // set window coefficients
70  void build_window();
71  // create frequency vector
72  std::vector<float> build_freq();
73  // auto threshold calculation
74  void build_threshold();
75  // signal grouping logic
76  std::vector<std::vector<unsigned int>> find_signal_edges();
77 
78  pmt::pmt_t pack_message();
79  // check if signals have changed
80  bool compare_signal_edges(std::vector<std::vector<float>>* edges);
81  // PSD estimation
82  void periodogram(float* pxx, const gr_complex* signal);
83 
84  int work(int noutput_items,
85  gr_vector_const_void_star& input_items,
86  gr_vector_void_star& output_items);
87 
88  void set_samp_rate(double d_samp_rate)
89  {
90  signal_detector_cvf_impl::d_samp_rate = d_samp_rate;
91  }
92 
93  void set_fft_len(int fft_len);
94  void set_window_type(int d_window);
95 
96  void set_threshold(float d_threshold)
97  {
98  signal_detector_cvf_impl::d_threshold = d_threshold;
99  }
100 
101  void set_sensitivity(float d_sensitivity)
102  {
103  signal_detector_cvf_impl::d_sensitivity = d_sensitivity;
104  }
105 
106  void set_auto_threshold(bool d_auto_threshold)
107  {
108  signal_detector_cvf_impl::d_auto_threshold = d_auto_threshold;
109  }
110 
111  void set_average(float d_average)
112  {
113  signal_detector_cvf_impl::d_average = d_average;
114  for (unsigned int i = 0; i < d_fft_len; i++) {
115  d_avg_filter[i].set_taps(d_average);
116  }
117  }
118 
119  void set_quantization(float d_quantization)
120  {
121  signal_detector_cvf_impl::d_quantization = d_quantization;
122  }
123 };
124 
125 } // namespace inspector
126 } // namespace gr
127 
128 #endif /* INCLUDED_INSPECTOR_SIGNAL_DETECTOR_CVF_IMPL_H */
signal_detector_cvf_impl(double samp_rate, int fft_len, int window_type, float threshold, float sensitivity, bool auto_threshold, float average, float quantization, float min_bw, const char *filename)
void set_auto_threshold(bool d_auto_threshold)
Definition: signal_detector_cvf_impl.h:106
void set_threshold(float d_threshold)
Definition: signal_detector_cvf_impl.h:96
bool compare_signal_edges(std::vector< std::vector< float >> *edges)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
std::vector< std::vector< unsigned int > > find_signal_edges()
Definition: signal_detector_cvf_impl.h:33
Definition: inspector_form.h:40
void set_sensitivity(float d_sensitivity)
Definition: signal_detector_cvf_impl.h:101
void periodogram(float *pxx, const gr_complex *signal)
void set_samp_rate(double d_samp_rate)
Definition: signal_detector_cvf_impl.h:88
Signal detection block using energy detection.
Definition: signal_detector_cvf.h:60
void set_average(float d_average)
Definition: signal_detector_cvf_impl.h:111
void set_quantization(float d_quantization)
Definition: signal_detector_cvf_impl.h:119