Gain (reduction) settings via the API

Add useful snippets of code or links to entire SDR projects.
Post Reply
AussieSusan
Posts: 30
Joined: Wed Aug 16, 2017 6:50 am

Gain (reduction) settings via the API

Post by AussieSusan » Thu Oct 19, 2017 8:45 am

I have tried to understand the API documentation and the various documents about how to manage the gain settings but I must admit that I'm having problems.
Using SDRUno I can see the signal that I'm trying to capture in my program. The settings I use in SDRUno are:
- IF AGC option is off and the slider set to 59dB
- the GR slider in the main window is at the top and the legend next to it ways 84dB
- in the Rx Control window, the AGC option of 'fast' is selected and the AGC tab in the settings window has the following values: att = 10.1, hold = 496 and rel = 603
- in the same window int he SAM/HP tab, the PLL AGC setting is 604 rel
If it matters, I'm using the B antenna with the bias-t turned on (there is a mast-head LNA in use).
I must admit that I really don't understand what these settings really mean, and I may well have missed some that are relevant.
How do I achieve configuring the RSP2 to approximately the same configuration using the API?
Is there a document (other than the API Spec and the AGC Technical note (which is nearly incomprehensible to me and I consider myself fairly knowledgeable on such things) that can explain how the gain settings work, how they interact and how to achieve various effects - I'm particularly interested in how to catch weak signals (such as the NOAA satellites) and local FM radio stations (which are rather strong).
Susan
Last edited by AussieSusan on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

sdrplay
Posts: 978
Joined: Wed Jan 07, 2015 7:58 am

Re: Gain (reduction) settings via the API

Post by sdrplay » Thu Oct 19, 2017 8:59 am

Hi Susan,

Firstly, there are two types of AGC in SDRuno. There's the gain control for the hardware (in the main window) and there is audio gain control which is what you are seeing in the RX control window. For what you are doing, you are only interested in the hardware gain control.

If you are using a RSP2, the easiest way to do this is to just set the gain control mode and then adjust the RF gain control. By default the AGC is enabled, so if you don't disable it, that may be why you are seeing values you are not expecting. There is an example code on our github repository that you could use as a starting point (https://github.com/SDRplay/examples)

The following line sets the gain control mode for the RSP2...
mir_sdr_SetGrModeT grMode = mir_sdr_USE_RSP_SET_GR;

then you can use grMode in the mir_sdr_StreamInit function call along with the LNA (RF gain control) value - remember that 0 is max gain (i.e. 0 gain reduction) and gain will decrease as you increase the LNA value. There is a table in the API specification that shows how much gain is switched in with each LNA step.

Hope that helps,

Best regards,

SDRplay Support

Reason: No reason

AussieSusan
Posts: 30
Joined: Wed Aug 16, 2017 6:50 am

Re: Gain (reduction) settings via the API

Post by AussieSusan » Fri Oct 20, 2017 10:02 am

Thanks for the quick reply (by my reckoning it is probably something ridiculously early in the morning in the UK).

The code example is actually the one I based my code on but I am still having problems trying to relate the SDRUno controls to the API calls and therefore the values that I need to set.

For example, the RF Gain control varies which parameter for which API - I assume it is the gRdb parameter of the mir_sdr_RSP_SetGr API but is that correct?

The "Gain" value (I must admit I think in terms of gain and not gain reduction) on the main display reflects what? It says 40.9dB but us that the value obtained from the mir_sdr_GetCurrentGain API?

On the main panels "Settings' page and the 'Input' tab, I have the IF AGC checkbox ticked - does that set the 'enable' parameter of the mir_sdr_AgcControl and if so then to what as it does not seem to be an 'on/off' type parameter?

As I said, I can see and hear the signal I am after using SDRUno but all I get is static in my program when tuning in to the satellites. I can hear the local FM stations OK (perhaps a bit distorted - perhaps as I have not set the gain low enough yet) so I know (or at least I'm fairly confidant) the code is working and I'm selecting the correct frequency.

Susan
Last edited by AussieSusan on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

sdrplay
Posts: 978
Joined: Wed Jan 07, 2015 7:58 am

Re: Gain (reduction) settings via the API

Post by sdrplay » Fri Oct 20, 2017 11:09 am

Hello Susan,

I'm not sure what you are stuck on.

There are 2 gain values reported back in the gain callback... gRdB is the IF gain and lnagRdB is the RF gain. The AGC only affects the IF gain. The RF gain is a manual control and you will need to look at the tables in the API to see what the valid range of values is for the frequency you are interested in, as it will vary.

The first parameter in the AgcControl function is an enum that either disables the AGC or sets it into 1 of 3 "on" states.

Whether you use the getCurrentGain function to obtain a gain value or not, remember all of the control functions in the API work in gain reduction. i.e. lnagRdB = 0 means MAX gain level (i.e. no gain reduction), gRdB = 20 means 20dB of gain reduction.

Best regards,

SDRplay Support

Reason: No reason

Post Reply