Page 1 of 1

RSP1 & RSP2 under GNURadio

Posted: Sat Feb 16, 2019 9:07 pm
by hb9rxc
Hi List,

I'm using both RSP1 / 2 with GNUradio via Osmocom - SoapySDRPlay module.
This module has 3 "gain" (or better attenuation ?) settings: RF, IF and BB

Could someone explain me the actual values accepted by this parameters and his effects ?

API 2.13 documentation ?

Thank you and enjoy doing some experiment with GNURadio and PothosFlow.

HB9RXC / Pietro

Re: RSP1 & RSP2 under GNURadio

Posted: Sun Feb 17, 2019 9:26 am
by DK7OB
Hm , I think I am running the same setup here but I get IFGR and RFGR with my RSP1A.

Some time ago I did some tests with the non-free sdrplay driver (not the soapy driver) and IIRC I got different gain settings.

What device string are you using? I use "driver=sdrplay,soapy=0"

Re: RSP1 & RSP2 under GNURadio

Posted: Sun Feb 17, 2019 8:07 pm
by hb9rxc
Hello DK7OB,

thank you for answer !

Yes I use osmocom source's module with this initialization: "driver=sdrplay,soapy=1"

Actually now I'm running some simple receiver test, and I found that it's a better way to let AGC on all the time.
I found also a nice document "explaining" how IF e RF GR (gain reduction) do work on RSP hardware.
See download section.

I'm quite new with GnuRadio (and/or PothosFlow) and the learning curve is a bit steep ... but as old engineer and OM, I like to spend some time to acquire some new knowledge abt SDR world !

Regards, Pietro

Re: RSP1 & RSP2 under GNURadio

Posted: Sun Feb 17, 2019 8:36 pm
by fventuri
Pietro,
the 'Documentation' tab in GNU Radio Companion has the following about gain settings and those three parameters:
Gain Mode:
Chooses between the manual (default) and automatic gain mode where appropriate.
To allow manual control of RF/IF/BB gain stages, manual gain mode must be configured.
Currently, only RTL-SDR devices support automatic gain mode.

RF Gain:
Overall RF gain of the device.

IF Gain:
Overall intermediate frequency gain of the device.
This setting is available for RTL-SDR and OsmoSDR devices with E4000 tuners and HackRF in receive and transmit mode. Observations lead to a reasonable gain range from 15 to 30dB.

BB Gain:
Overall baseband gain of the device.
This setting is available for HackRF in receive mode. Observations lead to a reasonable gain range from 15 to 30dB.
The source code for the 'gr-osmocom' module for a SoapySDR source (which is what I assume you are using) has the following (https://github.com/osmocom/gr-osmosdr/b ... ource_c.cc):

Code: Select all

std::vector<std::string> soapy_source_c::get_gain_names( size_t chan )
{
    return _device->listGains(SOAPY_SDR_RX, chan);
}

...

double soapy_source_c::set_if_gain( double gain, size_t chan )
{
    //docs specify RF gain is the first element
    const std::string name = this->get_gain_names(chan).front();
    return this->set_gain(gain, name, chan);
}

double soapy_source_c::set_bb_gain( double gain, size_t chan )
{
    //docs specify baseband gain is the last element
    const std::string name = this->get_gain_names(chan).back();
    return this->set_gain(gain, name, chan);
}
By looking at the implementation of 'listGains()' and 'setGain()' in the SoapySDRplay driver (https://github.com/pothosware/SoapySDRP ... ttings.cpp):

Code: Select all

std::vector<std::string> SoapySDRPlay::listGains(const int direction, const size_t channel) const
{
    //list available gain elements,
    //the functions below have a "name" parameter
    std::vector<std::string> results;

    results.push_back("IFGR");
    results.push_back("RFGR");

    return results;
}

...

void SoapySDRPlay::setGain(const int direction, const size_t channel, const std::string &name, const double value)
{
    std::lock_guard <std::mutex> lock(_general_state_mutex);

   bool doUpdate = false;

   if (name == "IFGR")
   {
      //Depending of the previously used AGC context, the real applied 
      // gain may be either gRdB or current_gRdB, so apply the change if required value is different 
      //from one of them.
      if ((gRdB != (int)value) || (current_gRdB != (int)value))
      {
         gRdB = (int)value;
         current_gRdB = (int)value;
         doUpdate = true;
      }
   }
   else if (name == "RFGR")
   {
      if (lnaState != (int)value) {

          lnaState = (int)value;
          doUpdate = true;
      }
   }
   if ((doUpdate == true) && (streamActive))
   {
      mir_sdr_Reinit(&gRdB, 0.0, 0.0, mir_sdr_BW_Undefined, mir_sdr_IF_Undefined, mir_sdr_LO_Undefined, lnaState, &gRdBsystem, mir_sdr_USE_RSP_SET_GR, &sps, mir_sdr_CHANGE_GR);
   }
}
it seems to me that the parameter 'IF Gain' refers to the 'gRdB' value, while the parameter 'BB Gain' refers to the lnaState, as they are used in the 'mir_sdr_Reinit()' function.

'mir_sdr_Reinit()' is described in the 2.13 API Specification document (https://www.sdrplay.com/docs/SDRplay_SD ... cation.pdf); in that document the two arguments 'gRdB' and 'lnaState' are described as follows:
gRdB:
Input value is the request gain reduction or gain reduction offset in dB (see gain reduction tables referenced in section 5 for ranges and mappings)

...

lnaState:
Specifies the LNA state:
N/A → if setGrMode == mir_sdr_USE_SET_GR
[0:1] → if setGrMode == mir_sdr_USE_SET_GR_ALT_MODE
[0:3] → if setGrMode == mir_sdr_USE_RSP_SET_GR && RSP1
[0:4] → if setGrMode == mir_sdr_USE_RSP_SET_GR && AMport1 && (RSP2 || RSPduo)
[0:5] → if setGrMode == mir_sdr_USE_RSP_SET_GR && Frf >= 420MHz && !RSP1
[0:8] → if setGrMode == mir_sdr_USE_RSP_SET_GR && Frf < 420MHz && !RSP1
I apologize for the long post, but I wanted to show all the steps so that you or anyone in the forum can double check (in case I missed something or I misunderstood the source code above).

Hope this helps,
Franco

Re: RSP1 & RSP2 under GNURadio

Posted: Mon Feb 18, 2019 8:55 am
by DK7OB
So the SoapySDRPlay driver returns RFGAIN and IFGAIN. I am running gqrx, and it is showing the gain settings the driver offers. The gnuradio block always seems to offer RF/IF/BB gain stages which needs to be mapped to the native gain stages of the hardware.

Regarding RFGR in the RSP1A, I am missing in the documentation what this is actually doing on the hardware (enabling LNA, switching attenuators or what?). Also the range is 0 to 7 (0 to 3 on the RSP1), and the real gain reduction in dB for each value depends on the frequency. This is explained in the API doc and is quite accurate at least for the RSP1A.

I am not using AGC because I do not like signals out of band changing the gain settings. Instead I am using a fixed set of manual gain settings depending on frequency which I found working best in my setup. In the low to medium HF range I am running RFGR from 1 to 3 and IFGR at 59 (max gain reduction), only on higher HF bands I use RFGR 0 and IFGR in the 40s which gives maximum sensitivity while keeping a fair large signal handling.