Skip to content

Commit

Permalink
SNR, P and L std, float storage
Browse files Browse the repository at this point in the history
Store the SNR as a float, rather than a uint16_t, avoiding the scaling
and rounding at each access.

The comnav and tersus decoders were not even using the SNR_UNIT for
scaling, perhaps another encoding, but assume scaling is not need when
stored as a float.

Store the P and L std in the float format. Makes better use of the
input format, without lossly compression. Avoids having to do the
encoding and decoding to the compressed format at each use.

Implement the compressed encoding in RINEX input and output. Easier to
make changes in one location here, and avoids this lossy compression
on other paths.

This uses a little extra storage, but if this is an issue then it
might be better to abstract a compressed encoding into accessor
functions than to have this distributed to each use. The P and L std
might be made a compilation option.

ublox: decode_trkmeas is estimating Lstd so have it respect the
-RCVSTDS option.

unicore: was not initialising P and L std.
  • Loading branch information
ourairquality committed Oct 29, 2024
1 parent 5059912 commit 3058d54
Show file tree
Hide file tree
Showing 34 changed files with 195 additions and 213 deletions.
2 changes: 1 addition & 1 deletion app/consapp/rtkrcv/rtkrcv.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ static void probserv(vt_t *vt, int nf)
for (j=0;j<nf;j++) vt_printf(vt,"%13.3f",obs[i].P[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%14.3f",obs[i].L[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%8.1f" ,obs[i].D[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%3.0f" ,obs[i].SNR[j]*SNR_UNIT);
for (j=0;j<nf;j++) vt_printf(vt,"%3.0f" ,obs[i].SNR[j]);
for (j=0;j<nf;j++) vt_printf(vt,"%2d" ,obs[i].LLI[j]);
vt_printf(vt,"\n");
}
Expand Down
2 changes: 1 addition & 1 deletion app/qtapp/rtknavi_qt/mondlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ void MonitorDialog::showObservations()
else ui->tWConsole->item(i, j++)->setText("-");
}
for (k = 0; k < NFREQ + nex; k++) {
if (obs[i].SNR[k]) ui->tWConsole->item(i, j++)->setText(QString::number(obs[i].SNR[k] * SNR_UNIT, 'f', 1));
if (obs[i].SNR[k]) ui->tWConsole->item(i, j++)->setText(QString::number(obs[i].SNR[k], 'f', 1));
else ui->tWConsole->item(i, j++)->setText("-");
}
for (k = 0; k < NFREQ + nex; k++)
Expand Down
4 changes: 2 additions & 2 deletions app/qtapp/rtkplot_qt/plotcmn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ QColor Plot::observationColor(const obsd_t *obs, double az, double el, QVariant
if (obs->L[freq-1] == 0.0 && obs->P[freq-1] == 0.0) {
return Qt::black;
}
color = snrColor(obs->SNR[freq-1] * SNR_UNIT);
color = snrColor(obs->SNR[freq-1]);
} else { // code
for (i = 0; i < NFREQ + NEXOBS; i++) {
if (!strcmp(code2obs(obs->code[i]), qPrintable(obstype.toString()))) break;
Expand All @@ -353,7 +353,7 @@ QColor Plot::observationColor(const obsd_t *obs, double az, double el, QVariant
if (obs->L[i] == 0.0 && obs->P[i] == 0.0) {
return Qt::black;
}
color = snrColor(obs->SNR[i] * SNR_UNIT);
color = snrColor(obs->SNR[i]);
}

// check against elevation mask
Expand Down
2 changes: 1 addition & 1 deletion app/qtapp/rtkplot_qt/plotdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ void Plot::saveSnrMp(const QString &file)
time2str(timeadd(gpst2utc(time), 9 * 3600.0), tstr, 1);
}
data = QString("%1 %2 %3 %4 %5 %6f\n").arg(tstr).arg(sat, 6).arg(azimuth[j] * R2D, 8, 'f', 1)
.arg(elevation[j] * R2D, 8, 'f', 1).arg(observation.data[j].SNR[k] * SNR_UNIT, 9, 'f', 2).arg(!multipath[k] ? 0.0 : multipath[k][j], 10, 'f', 4);
.arg(elevation[j] * R2D, 8, 'f', 1).arg(observation.data[j].SNR[k], 9, 'f', 2).arg(!multipath[k] ? 0.0 : multipath[k][j], 10, 'f', 4);
fp.write(data.toLatin1());
}
}
Expand Down
18 changes: 9 additions & 9 deletions app/qtapp/rtkplot_qt/plotdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ void Plot::drawSky(QPainter &c, int level)
if (obs->P[j] == 0.0 && obs->L[j] == 0.0)
s += "-- ";
else
s += QStringLiteral("%1 ").arg(obs->SNR[j] * SNR_UNIT, 2, 'f', 0, QChar('0'));
s += QStringLiteral("%1 ").arg(obs->SNR[j], 2, 'f', 0, QChar('0'));
}

// LLI
Expand All @@ -1532,7 +1532,7 @@ void Plot::drawSky(QPainter &c, int level)
if (obs->P[freq - 1] == 0.0 && obs->L[freq - 1] == 0.0)
s += "---- ";
else
s += QStringLiteral("%1 ").arg(obs->SNR[freq - 1] * SNR_UNIT, 4, 'f', 1);
s += QStringLiteral("%1 ").arg(obs->SNR[freq - 1], 4, 'f', 1);

// LLI
if (obs->L[freq-1] == 0.0)
Expand All @@ -1554,7 +1554,7 @@ void Plot::drawSky(QPainter &c, int level)
if (obs->P[j] == 0.0 && obs->L[j] == 0.0)
s += "---- ";
else
s += QStringLiteral("%1 ").arg(obs->SNR[j] * SNR_UNIT, 4, 'f', 1);
s += QStringLiteral("%1 ").arg(obs->SNR[j], 4, 'f', 1);

// LLI
if (obs->L[j] == 0.0)
Expand Down Expand Up @@ -1861,12 +1861,12 @@ void Plot::drawSnr(QPainter &c, int level)
}
if (idx >= NFREQ + NEXOBS) continue;
}
if (obs->SNR[idx] * SNR_UNIT <= 0.0) continue; // skip negative SNR
if (obs->SNR[idx] <= 0.0) continue; // skip negative SNR

// calculate position
x[n] = timePosition(obs->time);
if (panel == 0) { // SNR
y[n] = obs->SNR[idx] * SNR_UNIT;
y[n] = obs->SNR[idx];
col[n] = plotOptDialog->getMarkerColor(0, 4);
} else if (panel == 1) { // multipath
if (!multipath[idx] || multipath[idx][j] == 0.0) continue;
Expand All @@ -1878,7 +1878,7 @@ void Plot::drawSnr(QPainter &c, int level)
if (simulatedObservation)
col[n] = sysColor(obs->sat);
else
col[n] = snrColor(obs->SNR[idx] * SNR_UNIT);
col[n] = snrColor(obs->SNR[idx]);

if (elevation[j] > 0.0 && elevation[j] < plotOptDialog->getElevationMask() * D2R) col[n] = plotOptDialog->getMarkerColor(0, 0);
}
Expand Down Expand Up @@ -2059,10 +2059,10 @@ void Plot::drawSnrE(QPainter &c, int level)
}
if (idx >= NFREQ + NEXOBS) continue;
}
if (obs->SNR[idx] * SNR_UNIT <= 0.0) continue;
if (obs->SNR[idx] <= 0.0) continue;

x[0][n[0]] = x[1][n[1]] = elevation[j] * R2D;
y[0][n[0]] = obs->SNR[idx] * SNR_UNIT;
y[0][n[0]] = obs->SNR[idx];
y[1][n[1]] = !multipath[idx] ? 0.0 : multipath[idx][j];

col[0][n[0]] = col[1][n[1]] = (elevation[j] > 0.0 && elevation[j] < plotOptDialog->getElevationMask() * D2R) ?\
Expand Down Expand Up @@ -2340,7 +2340,7 @@ void Plot::drawResidual(QPainter &c, int level)
y[0][m[0]] = solstat->resp;
y[1][m[1]] = solstat->resc;
y[2][m[2]] = solstat->el * R2D;
y[3][m[3]] = solstat->snr * SNR_UNIT;
y[3][m[3]] = solstat->snr;

if (!(solstat->flag >> 5)) q = 0; // invalid
else if ((solstat->flag & 7) <= 1) q = 2; // float
Expand Down
2 changes: 1 addition & 1 deletion app/winapp/rtknavi/mondlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ void __fastcall TMonitorDialog::ShowObs(void)
else Tbl->Cells[j++][i+1]="-";
}
for (k=0;k<NFREQ+nex;k++) {
if (obs[i].SNR[k]) Tbl->Cells[j++][i+1]=s.sprintf("%.1f",obs[i].SNR[k]*SNR_UNIT);
if (obs[i].SNR[k]) Tbl->Cells[j++][i+1]=s.sprintf("%.1f",obs[i].SNR[k]);
else Tbl->Cells[j++][i+1]=s.sprintf("-");
}
for (k=0;k<NFREQ+nex;k++) {
Expand Down
4 changes: 2 additions & 2 deletions app/winapp/rtkplot/plotcmn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ TColor __fastcall TPlot::ObsColor(const obsd_t *obs, double az, double el)
if (obs->L[freq-1]==0.0&&obs->P[freq-1]==0.0) {
return clBlack;
}
color=SnrColor(obs->SNR[freq-1]*SNR_UNIT);
color=SnrColor(obs->SNR[freq-1]);
}
else {
for (i=0;i<NFREQ+NEXOBS;i++) {
Expand All @@ -354,7 +354,7 @@ TColor __fastcall TPlot::ObsColor(const obsd_t *obs, double az, double el)
if (obs->L[i]==0.0&&obs->P[i]==0.0) {
return clBlack;
}
color=SnrColor(obs->SNR[i]*SNR_UNIT);
color=SnrColor(obs->SNR[i]);
}
if (el<ElMask*D2R||(ElMaskP&&el<ElMaskData[(int)(az*R2D+0.5)])) {
return HideLowSat?clBlack:MColor[0][0];
Expand Down
2 changes: 1 addition & 1 deletion app/winapp/rtkplot/plotdata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ void __fastcall TPlot::SaveSnrMp(AnsiString file)
time2str(timeadd(gpst2utc(time),9*3600.0),tstr,1);
}
fprintf(fp,"%s %6s %8.1f %8.1f %9.2f %10.4f\n",tstr,sat,Az[j]*R2D,
El[j]*R2D,Obs.data[j].SNR[k]*SNR_UNIT,!Mp[k]?0.0:Mp[k][j]);
El[j]*R2D,Obs.data[j].SNR[k],!Mp[k]?0.0:Mp[k][j]);
}
}
fclose(fp);
Expand Down
18 changes: 9 additions & 9 deletions app/winapp/rtkplot/plotdraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,7 @@ void __fastcall TPlot::DrawSky(int level)
ustr+=" ";
for (j=0;j<NFREQ;j++) {
if (obs->P[j]==0.0&&obs->L[j]==0.0) ustr+="-- ";
else ustr+=ss.sprintf("%02.0f ",obs->SNR[j]*SNR_UNIT);
else ustr+=ss.sprintf("%02.0f ",obs->SNR[j]);
}
for (j=0;j<NFREQ;j++) {
if (obs->L[j]==0.0) ustr+="-";
Expand All @@ -1360,7 +1360,7 @@ void __fastcall TPlot::DrawSky(int level)
obs->P[freq-1]==0.0?"-":"C",obs->L[freq-1]==0.0?"-":"L",
obs->D[freq-1]==0.0?"-":"D");
if (obs->P[freq-1]==0.0&&obs->L[freq-1]==0.0) ustr+="---- ";
else ustr+=ss.sprintf("%4.1f ",obs->SNR[freq-1]*SNR_UNIT);
else ustr+=ss.sprintf("%4.1f ",obs->SNR[freq-1]);
if (obs->L[freq-1]==0.0) ustr+=" -";
else ustr+=ss.sprintf("%2d",obs->LLI[freq-1]);
}
Expand All @@ -1373,7 +1373,7 @@ void __fastcall TPlot::DrawSky(int level)
obs->P[j]==0.0?"-":"C",obs->L[j]==0.0?"-":"L",
obs->D[j]==0.0?"-":"D");
if (obs->P[j]==0.0&&obs->L[j]==0.0) ustr+="---- ";
else ustr+=ss.sprintf("%4.1f ",obs->SNR[j]*SNR_UNIT);
else ustr+=ss.sprintf("%4.1f ",obs->SNR[j]);
if (obs->L[j]==0.0) ustr+=" -";
else ustr+=ss.sprintf("%2d",obs->LLI[j]);
}
Expand Down Expand Up @@ -1644,11 +1644,11 @@ void __fastcall TPlot::DrawSnr(int level)
}
if (k>=NFREQ+NEXOBS) continue;
}
if (obs->SNR[k]*SNR_UNIT<=0.0) continue;
if (obs->SNR[k]<=0.0) continue;

x[n]=TimePos(obs->time);
if (i==0) {
y[n]=obs->SNR[k]*SNR_UNIT;
y[n]=obs->SNR[k];
col[n]=MColor[0][4];
}
else if (i==1) {
Expand All @@ -1659,7 +1659,7 @@ void __fastcall TPlot::DrawSnr(int level)
else {
y[n]=El[j]*R2D;
if (SimObs) col[n]=SysColor(obs->sat);
else col[n]=SnrColor(obs->SNR[k]*SNR_UNIT);
else col[n]=SnrColor(obs->SNR[k]);
if (El[j]>0.0&&El[j]<ElMask*D2R) col[n]=MColor[0][0];
}
if (timediff(time,obs->time)==0.0&&np<MAXSAT) {
Expand Down Expand Up @@ -1801,10 +1801,10 @@ void __fastcall TPlot::DrawSnrE(int level)
}
if (k>=NFREQ+NEXOBS) continue;
}
if (obs->SNR[k]*SNR_UNIT<=0.0) continue;
if (obs->SNR[k]<=0.0) continue;

x[0][n[0]]=x[1][n[1]]=El[j]*R2D;
y[0][n[0]]=obs->SNR[k]*SNR_UNIT;
y[0][n[0]]=obs->SNR[k];
y[1][n[1]]=!Mp[k]?0.0:Mp[k][j];

col[0][n[0]]=col[1][n[1]]=
Expand Down Expand Up @@ -2042,7 +2042,7 @@ void __fastcall TPlot::DrawRes(int level)
y[0][m[0]]=p->resp;
y[1][m[1]]=p->resc;
y[2][m[2]]=p->el*R2D;
y[3][m[3]]=p->snr*SNR_UNIT;
y[3][m[3]]=p->snr;
if (!(p->flag>>5)) q=0; // invalid
else if ((p->flag&7)<=1) q=2; // float
else if ((p->flag&7)<=3) q=1; // fixed
Expand Down
8 changes: 4 additions & 4 deletions src/pntpos.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ static double varerr(const prcopt_t *opt, const ssat_t *ssat, const obsd_t *obs,
/* var = R^2*(a^2 + (b^2/sin(el) + c^2*(10^(0.1*(snr_max-snr_rover)))) + (d*rcv_std)^2) */
varr=SQR(opt->err[1])+SQR(opt->err[2])/sin(el);
if (opt->err[6]>0.0) { /* if snr term not zero */
snr_rover=(ssat)?SNR_UNIT*ssat->snr_rover[0]:opt->err[5];
snr_rover=(ssat)?ssat->snr_rover[0]:opt->err[5];
varr+=SQR(opt->err[6])*pow(10,0.1*MAX(opt->err[5]-snr_rover,0));
}
varr*=SQR(opt->eratio[0]);
if (opt->err[7]>0.0) {
varr+=SQR(opt->err[7]*0.01*(1<<(obs->Pstd[0]+5))); /* 0.01*2^(n+5) m */
varr+=SQR(opt->err[7]*obs->Pstd[0]);
}
if (opt->ionoopt==IONOOPT_IFLC) varr*=SQR(3.0); /* iono-free */
return SQR(fact)*varr;
Expand Down Expand Up @@ -98,12 +98,12 @@ static int snrmask(const obsd_t *obs, const double *azel, const prcopt_t *opt)
{
int f2;

if (testsnr(0,0,azel[1],obs->SNR[0]*SNR_UNIT,&opt->snrmask)) {
if (testsnr(0,0,azel[1],obs->SNR[0],&opt->snrmask)) {
return 0;
}
if (opt->ionoopt==IONOOPT_IFLC) {
f2=seliflc(opt->nf,satsys(obs->sat,NULL));
if (testsnr(0,f2,azel[1],obs->SNR[f2]*SNR_UNIT,&opt->snrmask)) return 0;
if (testsnr(0,f2,azel[1],obs->SNR[f2],&opt->snrmask)) return 0;
}
return 1;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,8 @@ static double varerr(int sat, int sys, double el, double snr_rover,
var+=e*e*(pow(10,0.1*MAX(snr_max-snr_rover,0)));
}
if (opt->err[7]>0.0) { /* add rcvr stdevs term */
if (code) var+=SQR(opt->err[7]*0.01*(1<<(obs->Pstd[frq]+5))); /* 0.01*2^(n+5) */
else var+=SQR(opt->err[7]*obs->Lstd[frq]*0.004*0.2); /* 0.004 cycles -> m) */
if (code) var+=SQR(opt->err[7]*obs->Pstd[frq]);
else var+=SQR(opt->err[7]*obs->Lstd[frq]*0.2);
}
/* FIXME: the scaling factor is not 3 for other signals/constellations than GPS L1/L2 */
var*=(opt->ionoopt==IONOOPT_IFLC)?SQR(3.0):1.0;
Expand Down Expand Up @@ -414,7 +414,7 @@ static void corr_meas(const obsd_t *obs, const nav_t *nav, const double *azel,
/* skip if low SNR or missing observations */
freq[i]=sat2freq(obs->sat,obs->code[i],nav);
if (freq[i]==0.0||obs->L[i]==0.0||obs->P[i]==0.0) continue;
if (testsnr(0,0,azel[1],obs->SNR[i]*SNR_UNIT,&opt->snrmask)) continue;
if (testsnr(0,0,azel[1],obs->SNR[i],&opt->snrmask)) continue;

/* antenna phase center and phase windup correction */
L[i]=obs->L[i]*CLIGHT/freq[i]-dants[i]-dantr[i]-phw*CLIGHT/freq[i];
Expand Down Expand Up @@ -1045,7 +1045,7 @@ static int ppp_res(int post, const obsd_t *obs, int n, const double *rs,

/* variance */
var[nv]=varerr(sat,sys,azel[1+i*2],
SNR_UNIT*rtk->ssat[sat-1].snr_rover[frq],
rtk->ssat[sat-1].snr_rover[frq],
j,opt,obs+i);
var[nv] +=vart+SQR(C)*vari+var_rs[i];
if (sys==SYS_GLO&&code==1) var[nv]+=VAR_GLO_IFB;
Expand Down
12 changes: 6 additions & 6 deletions src/rcv/binex.c
Original file line number Diff line number Diff line change
Expand Up @@ -976,16 +976,16 @@ static uint8_t *decode_bnx_7f_05_obs(raw_t *raw, uint8_t *buff, int sat,
}
if (k<0) {
data->P[i]=data->L[i]=0.0;
data->D[i]=0.0f;
data->SNR[i]=data->LLI[i]=0;
data->D[i]=data->SNR[i]=0.0;
data->LLI[i]=0;
data->code[i]=CODE_NONE;
}
else {
freq=code2freq(sys,codes[code[k]],fcn);
data->P[i]=range[k];
data->L[i]=phase[k]*freq/CLIGHT;
data->D[i]=dopp[k];
data->SNR[i]=(uint16_t)(cnr[k]/SNR_UNIT+0.5);
data->SNR[i]=cnr[k];
data->code[i]=codes[code[k]];
data->LLI[i]=slip[k]?1:0;
mask[k]=1;
Expand All @@ -997,16 +997,16 @@ static uint8_t *decode_bnx_7f_05_obs(raw_t *raw, uint8_t *buff, int sat,
}
if (k>=nobs) {
data->P[i]=data->L[i]=0.0;
data->D[i]=0.0f;
data->SNR[i]=data->LLI[i]=0;
data->D[i]=data->SNR[i]=0.0;
data->LLI[i]=0;
data->code[i]=CODE_NONE;
}
else {
freq=code2freq(sys,codes[code[k]],fcn);
data->P[i]=range[k];
data->L[i]=phase[k]*freq/CLIGHT;
data->D[i]=dopp[k];
data->SNR[i]=(uint16_t)(cnr[k]/SNR_UNIT+0.5);
data->SNR[i]=cnr[k];
data->code[i]=codes[code[k]];
data->LLI[i]=slip[k]?1:0;
mask[k]=1;
Expand Down
10 changes: 4 additions & 6 deletions src/rcv/comnav.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ static int obsindex(obs_t *obs, gtime_t time, int sat)
obs->data[i].sat=sat;
for (j=0;j<NFREQ+NEXOBS;j++) {
obs->data[i].L[j]=obs->data[i].P[j]=0.0;
obs->data[i].D[j]=0.0;
obs->data[i].SNR[j]=obs->data[i].LLI[j]=0;
obs->data[i].D[j]=obs->data[i].SNR[j]=0.0;
obs->data[i].LLI[j]=0;
obs->data[i].code[j]=CODE_NONE;
}
obs->n++;
Expand Down Expand Up @@ -299,8 +299,7 @@ static int decode_rangecmpb(raw_t *raw)
raw->obs.data[index].L [pos]=adr;
raw->obs.data[index].P [pos]=psr;
raw->obs.data[index].D [pos]=(float)dop;
raw->obs.data[index].SNR[pos]=
0.0<=snr&&snr<255.0?(unsigned char)(snr*4.0+0.5):0;
raw->obs.data[index].SNR[pos]=0.0<=snr&&snr<255.0?snr:0;
raw->obs.data[index].LLI[pos]=(unsigned char)lli;
raw->obs.data[index].code[pos]=code;
#if 0
Expand Down Expand Up @@ -388,8 +387,7 @@ static int decode_rangeb(raw_t *raw)
raw->obs.data[index].L [pos]=-adr;
raw->obs.data[index].P [pos]=psr;
raw->obs.data[index].D [pos]=(float)dop;
raw->obs.data[index].SNR[pos]=
0.0<=snr&&snr<255.0?(unsigned char)(snr*4.0+0.5):0;
raw->obs.data[index].SNR[pos]=0.0<=snr&&snr<255.0?snr:0;
raw->obs.data[index].LLI[pos]=(unsigned char)lli;
raw->obs.data[index].code[pos]=code;
#if 0
Expand Down
Loading

0 comments on commit 3058d54

Please sign in to comment.