Skip to content

Commit

Permalink
RDS update
Browse files Browse the repository at this point in the history
  • Loading branch information
vladisslav2011 committed Apr 2, 2024
1 parent 83817e1 commit 5a59129
Show file tree
Hide file tree
Showing 12 changed files with 245 additions and 94 deletions.
54 changes: 46 additions & 8 deletions src/applications/gqrx/dcontrols.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3505,7 +3505,7 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_gomega")
.v_type(V_DOUBLE)
.def(0.)
.def(-4.3)
.min(-50.)
.max(1.)
.step(0.1)
Expand Down Expand Up @@ -3543,7 +3543,7 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_gmu")
.v_type(V_DOUBLE)
.def(0.)
.def(-1.4)
.min(-50.)
.max(1.)
.step(0.1)
Expand All @@ -3562,7 +3562,7 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_agc")
.v_type(V_DOUBLE)
.def(0.002)
.def(0.01)
.min(0.0)
.max(10.0)
.step(1e-4)
Expand Down Expand Up @@ -3598,9 +3598,9 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_fxff_bw")
.v_type(V_DOUBLE)
.def(1000.)
.def(1110.)
.min(500.)
.max(1170.)
.max(2000.)
.step(10.0)
.frac_digits(1)
,
Expand All @@ -3616,7 +3616,7 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_fxff_tw")
.v_type(V_DOUBLE)
.def(500.)
.def(300.)
.min(50.)
.max(800.)
.step(10.0)
Expand All @@ -3634,7 +3634,7 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_omega_lim")
.v_type(V_DOUBLE)
.def(2.5e-4)
.def(5.0e-4)
.min(1e-5)
.max(1e-3)
.step(1e-5)
Expand All @@ -3652,12 +3652,50 @@ c_def()
.v3_config_group("receiver")
.config_key("rds_dll_bw")
.v_type(V_DOUBLE)
.def(0.4)
.def(1.8)
.min(0.01)
.max(4.0)
.step(0.01)
.frac_digits(2)
,
c_def()
.idx(C_RDS_CL_BW)
.name("RDS_CL_BW")
.title("CL BW/SNR:")
.title_placement(c_def::grid_placement(PLACE_NEXT,0))
.placement(c_def::grid_placement(PLACE_SAME,PLACE_NEXT))
.hint("Costas loop bandwidth log unit")
.g_type(G_DOUBLESPINBOX)
.dock(D_RDS)
.scope(S_VFO)
.v3_config_group("receiver")
.config_key("rds_cl_bw")
.v_type(V_DOUBLE)
.def(-28.)
.min(-50.)
.max(-10.)
.step(0.1)
.frac_digits(1)
,
c_def()
.idx(C_RDS_PHASE_SNR)
.name("RDS_PHASE_SNR")
.title("snr:")
.title_placement(c_def::grid_placement(PLACE_NONE,0))
.placement(c_def::grid_placement(PLACE_SAME,PLACE_NEXT))
.hint("SNR(phase), db")
.g_type(G_LABEL)
.dock(D_RDS)
.scope(S_VFO)
.v_type(V_DOUBLE)
.def(0.)
.min(0.)
.max(0.)
.step(0.1)
.frac_digits(4)
.writable(false)
.event(true)
,
};

std::array<std::function<void (const int, const c_def::v_union &)>, C_COUNT> conf_base::observers{};
Expand Down
2 changes: 2 additions & 0 deletions src/applications/gqrx/dcontrols.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ enum c_id
C_RDS_FXFF_TW,
C_RDS_OMEGA_LIM,
C_RDS_DLL_BW,
C_RDS_CL_BW,
C_RDS_PHASE_SNR,

C_COUNT
};
Expand Down
11 changes: 4 additions & 7 deletions src/dsp/clock_recovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ int clock_recovery_el_cc::general_work(int noutput_items,
assert(d_mu <= 1.0);

float mm_val = 0;
constexpr float corr_alfa=0.001f;

while (oo < noutput_items && ii < ni)
{
Expand Down Expand Up @@ -170,12 +169,10 @@ int clock_recovery_el_cc::general_work(int noutput_items,
}
if(out1)
out1[oo] = d_skip?0:1;
if(d_corr0>=d_corr180)
{
out[oo++] = d_interp.interpolate(&in[ii], d_mu);
}else{
out[oo++] = d_interp.interpolate(&in[ci180], c_mu180);
}
gr_complex outval=(d_corr0>=d_corr180)?d_interp.interpolate(&in[ii], d_mu):d_interp.interpolate(&in[ci180], c_mu180);
out[oo++]=outval;
d_am_i+=(log10f(std::max(std::abs(real(outval)),0.00001f))-d_am_i)*corr_alfa;
d_am_q+=(log10f(std::max(std::abs(imag(outval)),0.00001f))-d_am_q)*corr_alfa;

d_omega = d_omega + d_gain_omega * mm_val;
d_omega =
Expand Down
7 changes: 6 additions & 1 deletion src/dsp/clock_recovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ typedef std::shared_ptr<clock_recovery_el_cc> sptr;
gr_vector_const_void_star& input_items,
gr_vector_void_star& output_items) override;

float mu() const { return (std::abs(d_corr0)>std::abs(d_corr180))?d_corr0:-d_corr180; }
float mu() const { return (std::abs(d_corr0)>std::abs(d_corr180))?d_corr0*10.f:-d_corr180*10.f; }
// float mu() const { return (std::abs(d_corr0)>std::abs(d_corr180))?(d_am_i-d_am_q)*10.f:(d_am_q-d_am_i)*10.f; }
float omega() const { return d_omega; }
float gain_mu() const { return d_gain_mu; }
float gain_omega() const { return d_gain_omega; }
Expand All @@ -56,6 +57,8 @@ typedef std::shared_ptr<clock_recovery_el_cc> sptr;
void set_dllalfa(float v) { d_dllalfa=v; }

private:
static constexpr float corr_alfa{0.001f};

float d_mu; // fractional sample position [0.0, 1.0]
float d_omega; // nominal frequency
float d_gain_omega; // gain for adjusting omega
Expand Down Expand Up @@ -83,6 +86,8 @@ typedef std::shared_ptr<clock_recovery_el_cc> sptr;
float d_corr180{0.0};
float d_dllbw{0.4f};
float d_dllalfa{0.2f};
float d_am_i{0.f};
float d_am_q{0.f};

gr_complex slicer_0deg(gr_complex sample)
{
Expand Down
97 changes: 75 additions & 22 deletions src/dsp/rds/decoder_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ unsigned int decoder_impl::calc_syndrome(unsigned long message,
return (lreg & ((1<<plen)-1)); // select the bottom plen bits of reg
}

int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_chars, uint16_t * loc)
int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_chars, uint16_t * loc, int * good_grp)
{
int ret=0;
if(offs_chars)
Expand All @@ -152,6 +152,8 @@ int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_ch
if(loc)
loc[0]=loc[1]=loc[2]=loc[3]=0;
uint16_t s;
int g1=0;
int g2=0;

s=calc_syndrome(grp[0]>>10,16)^(grp[0]&0x3ff);
const bit_locator & bl=locator[s^offset_word[0]];
Expand All @@ -160,6 +162,10 @@ int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_ch
if(offs_chars)
if(bl.w>0)
offs_chars[0]='x';
if(bl.w==1)
g1++;
if(bl.w==2)
g2++;
ret+=bl.w;
d_block0errs=bl.w;

Expand All @@ -170,6 +176,10 @@ int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_ch
if(offs_chars)
if(bl1.w>thr)
offs_chars[1]='x';
if(bl1.w==1)
g1++;
if(bl1.w==2)
g2++;
ret+=bl1.w;

s=calc_syndrome(grp[2]>>10,16)^(grp[2]&0x3ff);
Expand All @@ -182,6 +192,10 @@ int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_ch
if(offs_chars)
if(bl2.w>thr)
offs_chars[2]='x';
if(bl2.w==1)
g1++;
if(bl2.w==2)
g2++;
ret+=bl2.w;
}else{
if(offs_chars)
Expand All @@ -191,6 +205,10 @@ int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_ch
if(offs_chars)
if(bl4.w>thr)
offs_chars[2]='x';
if(bl4.w==1)
g1++;
if(bl4.w==2)
g2++;
ret+=bl4.w;
}

Expand All @@ -201,7 +219,14 @@ int decoder_impl::process_group(unsigned * grp, int thr, unsigned char * offs_ch
if(offs_chars)
if(bl3.w>thr)
offs_chars[3]='x';
if(bl3.w==1)
g1++;
if(bl3.w==2)
g2++;
ret+=bl3.w;

if(good_grp)
*good_grp=g1*3+g2;
return ret;
}

Expand Down Expand Up @@ -300,19 +325,31 @@ int decoder_impl::work (int noutput_items,
uint16_t pi = (next_grp[0]>>10)^locators[0];
if(d_block0errs<5)
{
constexpr char weights[]={5,2,1,1,1};
constexpr uint8_t weights[]={19,9,5,4,3};
d_pi_a[pi].weight+=weights[d_block0errs];
d_pi_a[pi].count++;
int bit_offset=d_bit_counter-d_pi_a[pi].lastseen;
d_pi_a[pi].lastseen=d_bit_counter;
if((d_pi_a[pi].weight>=10)&&(d_block0errs==0)&&((bit_offset+1)%GROUP_SIZE < 3))
/*
if((d_pi_a[pi].weight>=22)&&(d_block0errs<3)&&((bit_offset+1)%GROUP_SIZE < 3))
d_pi_a[pi].weight+=2;
if((d_pi_a[pi].weight>=22)&&(d_block0errs<5)&&(bit_offset%GROUP_SIZE == 0))
d_pi_a[pi].weight+=4;
if(d_pi_a[pi].weight<13)
if((d_pi_a[pi].weight>=22)&&(d_block0errs<3)&&(bit_offset%GROUP_SIZE == 0))
d_pi_a[pi].weight+=6;
if((d_pi_a[pi].weight>=22)&&(d_block0errs==0)&&(bit_offset%GROUP_SIZE == 0))
d_pi_a[pi].weight+=15;
*/
if((d_pi_a[pi].weight>=22)&&((bit_offset+1)%GROUP_SIZE < 3))
d_pi_a[pi].weight+=weights[d_block0errs]>>2;
if((d_pi_a[pi].weight>=22)&&(bit_offset%GROUP_SIZE == 0))
d_pi_a[pi].weight+=weights[d_block0errs]>>1;
if(d_pi_a[pi].weight<55)
{
if(d_pi_a[pi].weight>d_max_weight)
{
d_max_weight=d_pi_a[pi].weight;
printf("?[%04x] %d %d %d\n",pi,d_pi_a[pi].weight,d_block0errs,d_next_errs);
printf("?[%04x] %d (%d,%d) %d %d\n",pi,((bit_offset+1)%GROUP_SIZE < 3),d_pi_a[pi].weight,d_pi_a[pi].count,d_block0errs,d_next_errs);
d_matches[pi].push_back(grp_array(next_grp));
prev_grp[0]=pi;
prev_grp[1]=d_pi_a[pi].weight;
Expand All @@ -321,7 +358,7 @@ int decoder_impl::work (int noutput_items,
decode_group(prev_grp,d_next_errs);
}
}else{
printf("+[%04x] %d %d %d!!\n",pi,d_pi_a[pi].weight,d_block0errs,d_next_errs);
printf("+[%04x] %d (%d,%d) %d %d!!\n",pi,((bit_offset+1)%GROUP_SIZE < 3),d_pi_a[pi].weight,d_pi_a[pi].count,d_block0errs,d_next_errs);
auto & prv=d_matches[pi];
for(unsigned k=0;k<prv.size();k++)
{
Expand All @@ -343,19 +380,23 @@ int decoder_impl::work (int noutput_items,
offset_chars[0]='A';
decode_group(prev_grp,0);
for(int jj=0;jj<65536;jj++)
{
d_pi_a[jj].weight>>=2;
d_pi_a[jj].count>>=2;
}
if(jj==pi)
{
d_pi_a[jj].weight>>=1;
d_pi_a[jj].count>>=1;
}else{
d_pi_a[jj].weight>>=2;
d_pi_a[jj].count>>=2;
}
d_pi_bitcnt=0;
d_max_weight>>=2;
//d_state=SYNC;
d_max_weight>>=1;
d_state=SYNC;
d_best_pi=pi;
bit_counter=1;
continue;
}
d_pi_bitcnt++;
if(d_pi_bitcnt>BLOCK_SIZE*100)
if(d_pi_bitcnt>BLOCK_SIZE*50)
{
d_pi_bitcnt=0;
for(int jj=0;jj<65536;jj++)
Expand All @@ -372,7 +413,7 @@ int decoder_impl::work (int noutput_items,
if(d_corr)
continue;
}
bit_errors=process_group(good_group, ecc_max, offset_chars, locators);
bit_errors=process_group(good_group, ecc_max, offset_chars, locators, &good_grp);
char sync_point='E';
if(d_state != FORCE_SYNC)
{
Expand All @@ -396,22 +437,34 @@ int decoder_impl::work (int noutput_items,
sync_point='N';
}
}
if((bit_errors > 15)&&(d_state==SYNC))
if(d_state==SYNC)
{
if(d_counter > 512)
if(good_grp>=4)
{
d_state=NO_SYNC;
d_counter = 0;
printf("- NO Sync errors: %d\n",d_curr_errs);
}else
d_counter +=bit_errors;
}
d_counter>>=2;
//d_counter=0;
}
if(good_grp>=3)
{
d_counter>>=1;
}
if(bit_errors > 15)
{
if(d_counter > 512)
{
d_state=NO_SYNC;
d_counter = 0;
printf("- NO Sync errors: %d\n",d_curr_errs);
}
} }
d_counter +=bit_errors;
if(d_state != SYNC)
continue;
}else{
d_state = SYNC;
offset_chars[0]='F';
sync_point='F';
d_counter = 0;
}
// if(bit_errors>5)
// continue;
Expand Down
6 changes: 3 additions & 3 deletions src/dsp/rds/decoder_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class decoder_impl : public decoder
};
struct pi_stats
{
char count;
char weight;
uint8_t count;
uint8_t weight;
unsigned lastseen;
};
struct grp_array
Expand All @@ -66,7 +66,7 @@ class decoder_impl : public decoder
static unsigned int calc_syndrome(unsigned long, unsigned char);
void decode_group(unsigned *, int);
static std::array<bit_locator,1024> build_locator();
int process_group(unsigned * grp, int thr=0, unsigned char * offs_chars=nullptr, uint16_t * loc=nullptr);
int process_group(unsigned * grp, int thr=0, unsigned char * offs_chars=nullptr, uint16_t * loc=nullptr, int * good_grp=nullptr);

int bit_counter;
unsigned long lastseen_offset_counter, reg;
Expand Down
Loading

0 comments on commit 5a59129

Please sign in to comment.