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