Skip to content

Commit 0dc2a45

Browse files
committed
Fixed wrong coefficient in Taylor series; cleanup
To even edit this file, indents had to be sanitized a bit. Also, commented-out code was removed. Also, 8.f is a constand and not really longer than `d_8`. This is the first in two changes necessary for gnuradio#1817. The other would be adding a unit test that is *slightly* more holistic than just doing a single-tone frequency detection. Note that there's much about this code that could be refactored, starting with Sdot being a FIR-filtered version of the input.
1 parent 1874b87 commit 0dc2a45

File tree

2 files changed

+13
-28
lines changed

2 files changed

+13
-28
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Older Logs can be found in `docs/RELEASE-NOTES-*`.
1414
- CMake: using regex to match compiler against "Clang" now enables correct build on OS X
1515
#### GRC
1616
- Fixed GRC bug which broke WX and Qt (by altering the template code), in multiple (less than awesome) steps
17+
#### gr-analog
18+
- `fmdet_cf`'s derivative coefficients were wrong.
1719
#### gr-blocks
1820
- `float_array_to_int`: int32 limits were wrongly hardcoded.
1921
- Fixed the undefined behaviour happening in `float_to_complex` when accessing the second input_items element in the single-input case

gr-analog/lib/fmdet_cf_impl.cc

+11-28
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
namespace gr {
3232
namespace analog {
3333

34-
#define M_TWOPI (2*M_PI)
35-
3634
fmdet_cf::sptr
3735
fmdet_cf::make(float samplerate, float freq_low,
3836
float freq_high, float scl)
@@ -46,26 +44,13 @@ namespace gr {
4644
: sync_block("fmdet_cf",
4745
io_signature::make(1, 1, sizeof(gr_complex)),
4846
io_signature::make(1, 1, sizeof(float))),
49-
d_S1(0.1), d_S2(0.1),
50-
d_S3(0.1), d_S4(0.1)
47+
d_S1(0.1), d_S2(0.1),
48+
d_S3(0.1), d_S4(0.1)
5149
{
52-
//const float h[] = { 0.003118678733, -0.012139843428, 0.027270898036,
53-
// -0.051318579352, 0.090406910552, -0.162926865366,
54-
// 0.361885392563, 0.000000000000, -0.361885392563,
55-
// 0.162926865366, -0.090406910552, 0.051318579352,
56-
// -0.027270898036, 0.012139843428, -0.003118678733};
57-
58-
//std::vector<float> taps(15);
59-
6050
d_freq = 0;
6151
d_freqhi = freq_high;
6252
d_freqlo = freq_low;
6353
set_scale(scl);
64-
65-
//for(int i = 0; i < 15; i++) {
66-
//taps[i] = h[i];
67-
//}
68-
// d_filter = gr_fir_util::create_gr_fir_ccf(taps);
6954
}
7055

7156
fmdet_cf_impl::~fmdet_cf_impl()
@@ -95,28 +80,26 @@ namespace gr {
9580
{
9681
const gr_complex *iptr = (gr_complex*)input_items[0];
9782
float *optr = (float*)output_items[0];
98-
//const gr_complex *scaleiptr = (gr_complex*)input_items[0];
9983

10084
int size = noutput_items;
10185

10286
gr_complex Sdot, S0;
10387
gr_complex S1=d_S1, S2=d_S2, S3=d_S3, S4=d_S4;
104-
float d_8 = 8.0;
10588

10689
while(size-- > 0) {
107-
S0 = *iptr++;
90+
S0 = *iptr++;
10891

109-
Sdot = d_scl * (-S0+d_8*S1-d_8*S2+S4);
92+
Sdot = d_scl * (-S0 + 8.f*S1 - 8.f*S3 + S4);
11093

111-
d_freq = (S2.real()*Sdot.imag()-S2.imag()*Sdot.real()) /
112-
(S2.real()*S2.real()+S2.imag()*S2.imag());
94+
d_freq = (S2.real()*Sdot.imag() - S2.imag()*Sdot.real()) /
95+
(S2.real()*S2.real() + S2.imag()*S2.imag());
11396

114-
S4 = S3;
115-
S3 = S2;
116-
S2 = S1;
117-
S1 = S0;
97+
S4 = S3;
98+
S3 = S2;
99+
S2 = S1;
100+
S1 = S0;
118101

119-
*optr++ = d_freq-d_bias;
102+
*optr++ = d_freq-d_bias;
120103
}
121104
d_S1 = S1;
122105
d_S2 = S2;

0 commit comments

Comments
 (0)