Skip to content

Commit 1425e48

Browse files
trondeaujmcorgan
authored andcommitted
digital: adds callbacks to corr_est_cc block.
Can set mark_delay and threshold while running.
1 parent 327f070 commit 1425e48

File tree

4 files changed

+87
-14
lines changed

4 files changed

+87
-14
lines changed

gr-digital/grc/digital_corr_est_cc.xml

+9
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,44 @@
44
<key>digital_corr_est_cc</key>
55
<import>from gnuradio import digital</import>
66
<make>digital.corr_est_cc($symbols, $sps, $mark_delay, $threshold)</make>
7+
<callback>set_mark_delay($mark_delay)</callback>
8+
<callback>set_theshold($threshold)</callback>
9+
710
<param>
811
<name>Symbols</name>
912
<key>symbols</key>
1013
<type>complex_vector</type>
1114
</param>
15+
1216
<param>
1317
<name>Samples per Symbol</name>
1418
<key>sps</key>
1519
<type>float</type>
1620
</param>
21+
1722
<param>
1823
<name>Tag marking delay</name>
1924
<key>mark_delay</key>
2025
<type>int</type>
2126
</param>
27+
2228
<param>
2329
<name>Threshold</name>
2430
<key>threshold</key>
2531
<value>0.9</value>
2632
<type>float</type>
2733
</param>
34+
2835
<sink>
2936
<name>in</name>
3037
<type>complex</type>
3138
</sink>
39+
3240
<source>
3341
<name>out</name>
3442
<type>complex</type>
3543
</source>
44+
3645
<source>
3746
<name>corr</name>
3847
<type>complex</type>

gr-digital/include/gnuradio/digital/corr_est_cc.h

+6
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ namespace gr {
104104

105105
virtual std::vector<gr_complex> symbols() const = 0;
106106
virtual void set_symbols(const std::vector<gr_complex> &symbols) = 0;
107+
108+
virtual unsigned int mark_delay() const = 0;
109+
virtual void set_mark_delay(unsigned int mark_delay) = 0;
110+
111+
virtual float threshold() const = 0;
112+
virtual void set_threshold(float threshold) = 0;
107113
};
108114

109115
} // namespace digital

gr-digital/lib/corr_est_cc_impl.cc

+61-12
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,8 @@ namespace gr {
6262
}
6363
std::reverse(d_symbols.begin(), d_symbols.end());
6464

65-
d_mark_delay = mark_delay >= d_symbols.size() ? d_symbols.size() - 1
66-
: mark_delay;
67-
68-
// Compute a correlation threshold.
69-
// Compute the value of the discrete autocorrelation of the matched
70-
// filter with offset 0 (aka the autocorrelation peak).
71-
float corr = 0;
72-
for(size_t i = 0; i < d_symbols.size(); i++)
73-
corr += abs(d_symbols[i]*conj(d_symbols[i]));
74-
d_thresh = threshold*corr*corr;
65+
set_mark_delay(mark_delay);
66+
set_threshold(threshold);
7567

7668
// Correlation filter
7769
d_filter = new kernel::fft_filter_ccc(1, d_symbols);
@@ -157,8 +149,65 @@ namespace gr {
157149
declare_sample_delay(1, 0);
158150
declare_sample_delay(0, d_symbols.size());
159151

160-
d_mark_delay = d_mark_delay >= d_symbols.size() ? d_symbols.size()-1
161-
: d_mark_delay;
152+
_set_mark_delay(d_stashed_mark_delay);
153+
_set_threshold(d_stashed_threshold);
154+
}
155+
156+
unsigned int
157+
corr_est_cc_impl::mark_delay() const
158+
{
159+
return d_mark_delay;
160+
}
161+
162+
void
163+
corr_est_cc_impl::_set_mark_delay(unsigned int mark_delay)
164+
{
165+
d_stashed_mark_delay = mark_delay;
166+
167+
if(mark_delay >= d_symbols.size()) {
168+
d_mark_delay = d_symbols.size()-1;
169+
GR_LOG_WARN(d_logger, boost::format("set_mark_delay: asked for %1% but due "
170+
"to the symbol size constraints, "
171+
"mark delay set to %2%.") \
172+
% mark_delay % d_mark_delay);
173+
}
174+
else {
175+
d_mark_delay = mark_delay;
176+
}
177+
}
178+
179+
void
180+
corr_est_cc_impl::set_mark_delay(unsigned int mark_delay)
181+
{
182+
gr::thread::scoped_lock lock(d_setlock);
183+
_set_mark_delay(mark_delay);
184+
}
185+
186+
float
187+
corr_est_cc_impl::threshold() const
188+
{
189+
return d_thresh;
190+
}
191+
192+
void
193+
corr_est_cc_impl::_set_threshold(float threshold)
194+
{
195+
d_stashed_threshold = threshold;
196+
197+
// Compute a correlation threshold.
198+
// Compute the value of the discrete autocorrelation of the matched
199+
// filter with offset 0 (aka the autocorrelation peak).
200+
float corr = 0;
201+
for(size_t i = 0; i < d_symbols.size(); i++)
202+
corr += abs(d_symbols[i]*conj(d_symbols[i]));
203+
d_thresh = threshold*corr*corr;
204+
}
205+
206+
void
207+
corr_est_cc_impl::set_threshold(float threshold)
208+
{
209+
gr::thread::scoped_lock lock(d_setlock);
210+
_set_threshold(threshold);
162211
}
163212

164213
int

gr-digital/lib/corr_est_cc_impl.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ namespace gr {
3737
pmt::pmt_t d_src_id;
3838
std::vector<gr_complex> d_symbols;
3939
float d_sps;
40-
unsigned int d_mark_delay;
41-
float d_thresh;
40+
unsigned int d_mark_delay, d_stashed_mark_delay;
41+
float d_thresh, d_stashed_threshold;
4242
kernel::fft_filter_ccc *d_filter;
4343

4444
gr_complex *d_corr;
4545
float *d_corr_mag;
4646

47+
void _set_mark_delay(unsigned int mark_delay);
48+
void _set_threshold(float threshold);
49+
4750
public:
4851
corr_est_cc_impl(const std::vector<gr_complex> &symbols,
4952
float sps, unsigned int mark_delay,
@@ -53,6 +56,12 @@ namespace gr {
5356
std::vector<gr_complex> symbols() const;
5457
void set_symbols(const std::vector<gr_complex> &symbols);
5558

59+
unsigned int mark_delay() const;
60+
void set_mark_delay(unsigned int mark_delay);
61+
62+
float threshold() const;
63+
void set_threshold(float threshold);
64+
5665
int work(int noutput_items,
5766
gr_vector_const_void_star &input_items,
5867
gr_vector_void_star &output_items);

0 commit comments

Comments
 (0)