rebuilt Rx level and No estimation for be indep of Rs and Fs

development
David Rowe 2021-10-22 15:07:56 +10:30
parent 7398187ba9
commit 9eb6b4e1b2
1 changed files with 17 additions and 12 deletions

View File

@ -392,18 +392,19 @@ static void rtlsdr_callback(unsigned char *buf, uint32_t len, void *ctx)
}
/* optional SNR info to stderr for logging */
if (log_snr && (rx_status & FREEDV_RX_BITS)) {
float S,N,RxleveldBm, NodBmHz;
float S,N,RxpowerdBm,NodBmHz;
float FsonRsdB = 20*log10((float)modem_samp_rate/Rs);
freedv_get_fsk_S_and_N(freedv, &S, &N);
RxleveldBm = 10*log10(S) + RxGain;
NodBmHz = 10*log10(N) + RxGain - 10*log10((float)Rs);;
RxpowerdBm = 10*log10(S) + RxGain - FsonRsdB;
NodBmHz = 10*log10(N) + RxGain - FsonRsdB - 10*log10((float)Rs);
fprintf(stderr, "%lu ", (unsigned long)time(NULL));
fprintf(stderr, "Rx Frame Rxloc: %6.2f Noloc: %6.2f snrloc: %5.2f ", RxleveldBm, NodBmHz, 10*log10(S/N));
fprintf(stderr, "Rx Frame Rxloc: %6.2f Noloc: %6.2f snrloc: %5.2f ", RxpowerdBm, NodBmHz, 10*log10(S/N));
memcpy(&S, &bytes_out[2], sizeof(float));
memcpy(&N, &bytes_out[6], sizeof(float));
if ((S>0) && (N>0)) {
RxleveldBm = 10*log10(S) + RxGain;
NodBmHz = 10*log10(N) + RxGain - 10*log10((float)Rs);;
fprintf(stderr, "Rxrem: %6.2f Norem: %6.2f snrrem: %5.2f\n", RxleveldBm, NodBmHz, 10*log10(S/N));
RxpowerdBm = 10*log10(S) + RxGain - FsonRsdB;
NodBmHz = 10*log10(N) + RxGain - FsonRsdB - 10*log10((float)Rs);;
fprintf(stderr, "Rxrem: %6.2f Norem: %6.2f snrrem: %5.2f\n", RxpowerdBm, NodBmHz, 10*log10(S/N));
}
else
fprintf(stderr, "Srem: %6.2f Nrem: %6.2f snrrem: %5.2f\n", 0., 0., 0.);
@ -537,16 +538,20 @@ int main(int argc, char **argv)
case 'g':
gain = (int)(atof(optarg) * 10); /* tenths of a dB */
/* note YMMV - these will vary across RTLSDR brands and samples */
/* Initial calibration with Fs=200E3 and Rs=10E3, so lets normalise such
that other ratios can be used */
float cal_Fs_on_Rs = 20.0*log10(200/10);
if (gain/10 == 49)
RxGain = -90.7;
RxGain = -90.7 + cal_Fs_on_Rs;
else if (gain/10 == 45)
RxGain = -85.6;
RxGain = -85.6 + cal_Fs_on_Rs;
else if (gain/10 == 40)
RxGain = -81.1;
RxGain = -81.1 + cal_Fs_on_Rs;
else if (gain/10 == 35)
RxGain = -76.9;
RxGain = -76.9 + cal_Fs_on_Rs;
else if (gain/10 == 30)
RxGain = -71.0;
RxGain = -71.0 + cal_Fs_on_Rs;
else
fprintf(stderr,"rtl_fsk: WARNING RxLevel not calibrated at this -g gain\n");
break;