Monday, April 15, 2019

Applying outboard AGC and filtering to RTL-SDR dongles to maximize usable dynamic range on HF


An AGC system for RTL-SDR "wideband" receivers
operating in "Direct" (Q-branch) mode.

 A quick description of RTL-SDR dongles:

Figure 1:
An "RTL-SDR.com V3" USB-based receiver - one of the better,
"cheaper" options out there.
This unit has been programmed and marked with its own,
unique (to the system) serial number.
Click on the image for a larger version.
The so-called RTL-SDR dongles are ubiquitous and versatile because they can cover (more or less) from a few hundred kHz to over 1.3 GHz using various on-device signal paths - but all of these signal paths have in common one important limitation - The A/D converter is only 8 bits.

Despite these limitations, they are attractive because they are cheap - from $4 for the "bottom end" and cheapest devices (which are far noisier than they could be) to well over $50 for units with frequency converters and a few other bells and whistles - including band-pass filters.  The devices that we are using are just $20 and are the RTL-SDR dongles sold by "RTL-SDR Blog":  These units have thoughtfully-designed circuit boards that minimize extraneous, spurious responses and include a 1ppm TCXOs for decent frequency stability as well as providing separate signal branches for "direct" and "quadrature" signal paths for frequency ranges below 30 MHz and above around 60 MHz, respectively.

Ideally, the maximum range represented by an 8 bit A/D converter is around 48dB - and this is approximately what can be expected from these devices.  As with most things in the real world, the actual answer to the question of "what is the dynamic range" is more complicated.

In reality, noise produced by the device reduce the number of usable A/D bits and thus the dynamic range - but due to what amounts to oversampling and the contribution of the noise that is always present on HF - which can effectively "dither" the A/D converter, the apparent dynamic range can "seem" to be somewhat greater - perhaps well over 50dB, under some circumstances - but having 50-60 dB or so of usable dynamic range is not nearly enough for reasonable performance on the HF bands under a wide variety of signal conditions.
"But the Dongle already has an AGC!"

One advantage of using a dongle with an upconverter - a device that would, say, converter 0-30 MHz to the range of  125-155 MHz - is that it then places these signals within the range where the R820T chip can operate - and this chip does have RF filtering and a sort of AGC - at least by way of being able to have its gain adjusted by software.

Aside from the frequency drift issues related to this frequency up-conversion mentioned elsewhere, the problem with this is that the R820T chip really isn't that "strong" in terms of  its ability to handle widely disparate signal levels.  While the RTL2832 chip does have an AGC or sorts, the gain of both chips in the signal path must be carefully controlled to maximize performance.  Unfortunately, the precise nature of how these all work together isn't well documented and the general consensus seems to be that at HF, it doesn't work all that well.

While the built-in AGC can work, we decided to avoid combining the somewhat marginal performance of the R820T signal path and the unknown nature of the AGC operation with the already-marginal 8 bits of A/D conversion in favor of an external AGC system operating within the well-defined limits of the dynamics of these devices when they are operated in "direct" mode.


The problem:

In this specific case we are using the "Q" branch of the RTL-SDR dongle for direct reception of HF signals:  For the purposes of this discussion and to avoid the complication of a discussion about aliasing, we'll limit the frequency range to 30 meters (10.15 MHz) and lower - a range that encompasses what are, in the current low end of the sunspot cycle, the two most popular HF bands:  40 and 80/75 meters.

In some circumstances - and with careful adjustment of RF levels - the limited dynamic range of the RTL-SDR dongles is "almost enough" - but because HF conditions widely change, the "optimal" amount of signal getting into the dongle goes all over the map:  During the daytime on 40 meters, noise can be very low and there are very few truly strong signals, but in the evenings or mornings there can be very strong signals from high-power shortwave broadcast stations.  These disparate situations cause some problems:
  • If one adjusts the signal level going into the dongle to optimize being able to hear weak signals during the day (e.g. the background noise of the band driving the A/D converter to 10-15% full scale indication) it is likely that strong nighttime signals - both amateur and broadcast - will (more or less) saturate the A/D converter (e.g. put it into the range of "clipping"), degrading performance considerably.
  • If one adjusts the signal level into the dongle to accommodate the very strong signals (which is only a "best guess" as such signals can vary by 10s of dB) then the input level to the dongle under "quiet" band conditions will be so low that sensitivity will suffer and spurious signals can appear everywhere as too few A/D converter bits are being "tickled" causing images and intermodulation distortion.
As mentioned before, the A/D converter's 8 bits do provide roughly 50dB of overall signal-handling range, but using one of these devices on HF soon makes it clear that one must constantly adjust the input level to assure that that 50dB "window of usefulness" is in the right place.  Using 60 meters as an example again, a "quiet" band in a good location may yield around -107dBm of noise in an SSB bandwidth, but a powerhouse shortwave broadcaster's signal can be into the -35dBm range - nearly 70dB higher than the noise (and there may be more than one of these strong signals!) which represents a range of at least 70dB.  What's worse, taking into account the need to provide 10-15% of A/D deflection just on the background noise on a quiet band for the dongles to work properly (to avoid serious issues with quantization-related distortion) roughly half of the 50dB or so available to us is already "used"!


Applying an AGC (Automatic Gain Control):

Figure 2:
Inside the 4-channel filter and AGC gain block module.
The individual band-pass filters may be seen at the far end of the lid-mounted
PCB ground plane while the actual detection and control circuitry
is on the prototype boards in the foreground near the bottom of the picture.
Click on the image for a larger version.
Any RF-based digital direct-sampling (or analog!) receive system - to maintain optimal performance - must have its input levels constrained, which is to say that one must take into account both the lowest and the highest signal levels.  In some cases it is simply enough to amplify/attenuate the input levels so that the expected signals will always fall in that range - and this may be practical on VHF/UHF or microwave, but it is certainly not the case at HF.

Even if we were to use a higher resolution A/D converter, we would still want to do this to keep all of the input signals within the "sweet spot":  Direct sampling HF transceivers such as the Icom IC-7300 and IC-7610 must apply both "strong" band-pass filtering and input gain control to maximize their overall performance.  In general, the more signal we throw into the A/D converter, the better - as long as we don't overdrive it and cause (excessive) "clipping".

Such is the case with these RTL-SDRs:  For best performance, one must have BOTH "strong" input filtering centered around the frequency range of interest (the narrower the better!) and keep the signal levels in the "sweet spot":  A properly-designed AGC can do this.

In short, the signal path and method is as follows:
  • The signal comes from the antenna.
  • Bandpass filtering for the band of frequencies is applied.  The narrower the bandwidth and "sharper" the filtering, the better.
    •  Important:  One should never connect a receiver - particularly one with limited dynamic range - to an antenna without a band-pass filter that is designed to limitf the applied signals to the range of interest. (In other words:  Don't waste your time trying to make an RTL-SDR dongle work on HF without a suitable HF bandpass filter for the frequency range of interest - no matter which RTL-SDR dongle you use, filter out all but the frequency band in which you are interested.)
  • On the output of the filter is an electronic attenuator.
  • The signal level on the output of the filter (which is also being applied to the dongle) is measured.
  • If the signal level exceeds a set threshold, the amount of attenuation is increased to cause it to remain at/near that threshold.
In short, the above system prevents the combination of all signals from getting to the dongle from consistently exceeding a pre-set level.  In this way, one can run a bit of "extra" gain to get the best weak-signal performance, but prevent the system from being hopelessly overloaded when very strong signals appear.

A practical implementation:

To maximize performance of the RTL-SDR dongles used for HF reception at the Northern Utah WebSDR, a "prototype" module consisting of four bandpass filters and four AGC gain blocks was constructed - see Figure 2.

Bandpass filters for 90-80 meters, 60-49 meters, 41-40 meters and 31-30 meters were constructed "Manhattan Style" on pieces of glass-epoxy circuit board material as individual filter modules which were then secured to the main ground plane - a larger piece of PC board material mounted in the lid of a Hammond 1590D aluminum enclosure.  Three dividers - also made of circuit board material - provide shielding between each of the band modules.

Constructed on small pieces of phenolic prototype board are the circuits that detect the RF and derive a control current for the electronic attenuators.  These devices are mounted elevated above the ground plane and attached to the shield walls which provides good RF grounding and a DC return path:  Two smaller "walls" are located at the far ends to provide the two boards at the ends with solid attachment points.

Comment:
You can check out the device depicted in this article yourself - simply go to the Northern Utah WebSDR and listen on the "60 Meter" and "30 Meter" bands on WebSDR #1 and WebSDR #2, respectively, or to the "90/80 Meter" and "41/40 Meter" bands on WebSDR #3.  All four of these bands use RTL-SDR dongles with the described AGC device.
Figure 3:
Schematic of the gain control block.
Click on the image for a larger version.
Circuit description:

Figure 3
shows the gain control block schematically.

The input signal passes through the band-pass filter (shown as a block) with its output connected to a doubly-balanced modulator module, U3.  These devices are nearly identical to standard diode-ring doubly-balanced mixers, except that they are optimized for operation as an attenuator or baseband modulator:  The attenuation through them is inversely proportional to the logarithm of the current applied to the "CTL" (control) port.  In this case I used the Mini-Circuits LRAS-2-75 modules, originally designed for 75 ohm systems, but they work just fine at 50 ohms as well - being chosen because they are some of the lowest-cost components of this type offered by Mini-Circuits Labs.  The "official" specifications of the LRAS-2-75 gives specifications down to just 10 MHz, but it works fine at 3 MHz with just an extra dB or two of insertion loss.

Figure 3 gives a list of other suitable devices - some of which are rated down to lower frequencies than the LRAS-2-75.  Figure 3 also mentions the use of a standard doubly-balanced mixer such as the Mini-Circuits SRA-1:  A standard mixer will also work "acceptably" in this role if that is what is available.  If a standard doubly-balanced mixer is used, make sure that it has a port that provides a direct connect to its internal diodes to which the bias may be applied:  While this is usually the "IF" port, some devices have this particular port otherwise designated.  The presence of the diodes can be easily checked by using the "diode" function of a DVM between the device ground(s) and the control pin, observing a 0.2-0.3 volt drop in both directions/polarities of the meter.

The output of the attenuator (U3) goes two places:  To the RTL-SDR dongle being used for reception, and to the input of U2, an Analog Devices AD8307 logarithmic amplifier.  This device's input impedance is quite high, so a 470 ohm series resistor (R6) is used to lightly "tap" the RF coming out of the U3 while causing minimal circuit loading.  Included across the input pins of U2 is a low-value capacitor - typically in the 33-56pF range (as noted on the diagram) that is connected very close to the device to quash its response at VHF/UHF while minimally affecting HF signals:  Without this capacitor, U2 can easily detect any local FM or VHF/UHF TV broadcast signal - or even local VHF/UHF amateur transmissions - and be somewhat "desensed".  Practically speaking, this may not be a problem - particularly when it is placed inside a shielded container, behind bandpass filtering - but this can be distracting when the circuit is on the workbench being tested.

The output of U2 is a logarithmic response of the total RF energy (after having been passed through the filter) being applied to its input, the voltage increasing by approximately 250 millivolts for every 10dB of increase in signal:  If reasonable construction techniques are applied, signals well below -70dBm can be measured.  Because the maximum signal level (e.g. A/D converter clipping) of the "RTL-SDR Blog" dongle is in the range of -40dBm, no additional RF amplification is necessary in front of U2.

Figure 4:
Two of the gain control modules with U2, the AD8307s being
partially obscured by the ferrite beads.  These
beads are used to decouple any stray RF from the
common 12 volt supply line powering the modules.
Click on the image for a larger version.
U1 must be an op amp capable of operating down to the negative rail in order for this circuit to function and the specified LMC660 is ideally suited.  The DC output of U2 is applied to U1a, one half of a dual op amplifier, wired as a unity-gain follower to set a low impedance point, and this DC signal is then applied, via R5, a 1 Megohm resistor to U1b, which is configured as an integrator by virtue of a 0.1uF capacitor placed in the feedback path with the threshold being set by R4, a 10 turn potentiometer.  If the integrated DC signal from U2 is above the threshold set by R4, the voltage output of U1b decreases, reducing the bias applied to attenuator U3 and increasing its loss, but if the signal is below the threshold, the voltage increases, decreasing the attenuation.  By this action, the combination of U1 and U2's action will prevent the average signal at the bandpass filter's output from exceeding the threshold level set by R4.

Whereas a typical AGC found in a receiver will have a fast "attack" and a slow "decay", we want this AGC to be comparatively slow to respond so that it will (hopefully) not be completely deafened by the occasional static crash.  In reality, allowing the A/D converter to hit full-scale on occasional peaks will have minimal apparent impact on reception.  In the absence of broadband static crashes, the cumulative power within the bandpass filter's range will change comparatively slowly over time and it is this that we wish to track.

In the DC path between the output of U1a and the "CTL" pin of U3 is a series LED which provides both a bit of logarithmic current response intrinsic to semiconductor diodes as well as providing a handy visual indication of the state of the circuit:  If the LED is lit, attenuation is low, but if it is very dim or turned off, more attenuation is being applied.  In testing, the photosensitivity of LEDs was simply a "non issue" and ambient light had no discernible effect on circuit operation - and even if it was at all noticeable, it will be placed in a metal box, anyway.

Resistor R3 provides current limiting to the diode while R2 provides a current sink:  The combination of R1 and C1 (located very close to U3) terminate the "CT" port (at high frequencies) at the nominal impedance of the RF portion - in this case, around 50 ohms.  Also included is U4, a 5 volt regulator:  This supplies power for U2 as well as provides a stable reference voltage for R4, the RF threshold adjustment:  It need not be exquisitely stable with temperature as several dB change of the AGC threshold with varying temperature is of no importance in this application.

Under normal "quiet" conditions the RF level going into U2 will be too low to exceed the threshold, causing the output of U1b to go to maximum voltage, biasing U3 to set minimum attenuation - it is only in the presence of stronger signal(s) that the gain reduction will occur.

Circuit calibration:


To calibrate the circuit, a signal generator is required, the procedure being as follows:
  • Pre-set the wiper of R4 (the 10 turn pot) to ground (zero volts at U1b, pin 5)
  • Set a signal generator it to a frequency within the passband of the filter and an RF level of around -20dBm.
  • Connect the input of the dongle to the signal generator and tune it to the frequency of the generator using software of your choice.  Make sure that the "direct - Q" signal path is selected since we are not using an upconverter.
    • If using SDR-Sharp, tuning in the signal (using AM is best) "hovering" the mouse over it on the waterfall display should give a dBFS reading.
    • If using the "HDSDR" program, the "dBFS" reading will appear on-screen in the receiver control panel.
  • Using the software, monitor the level of the applied RF signal's "dBFS" (dB with respect to full-scale).  Ideally, a full-scale A/D indication would yield a dBFS reading of around -6dBFS, but it seems that the internal scaling of the signals from an RTL-SDR dongle aren't scaled, so the reading may be in the -30 to -50 dBFS range.  Monitor the "dBFS" from the dongle while increasing/decreasing the signal and note the highest value.  The goal here is to determine the reading given by the program.
    • Ideally, one would like to be able to see the "recent-highest" reading of the A/D converter of the dongle, but this may not be available in the programs used with the dongle.
    • If adventurous, one can use the "librtlsdr" tool called "rtl_sdr" and dump the results to a file or a display program to monitor the raw A/D values.
    • If you operate a WebSDR using the PA3FWM software there is a utility that will directly read out the number that we want to look at:  Contact me directly for details.
  • Having determined the maximum-displayed "dBFS" level, connect the signal generator to the input of the bandpass filter and the RTL-SDR dongle to the output (e.g. J2 in Figure 3) with the frequency set to the center of the desired frequency range (usually - but not always - the middle of the filter's passband).  The amplitude of the signal generator is set for level higher than one would reasonably expect to see on the input - say -20dBm.
  • At this point the LED should not be illuminated and U3 will offer maximum attenuation.
  • Slowly increase R4 until the LED just starts to be illuminated.  Watching the "dBFS" reading, adjust R4 for a signal level that is about 6dB below the maximum reading that you'd previously obtained.  Ultimately, you will want to set the peak A/D output to between 1/4 and 1/2 of full scale which represents -12 to -6 dBFS, respectively.
  • If the circuit is working properly, any signal above that corresponding with the threshold should be limited at the set value by automatically setting U3's attenuation, but a total signal power level below the threshold should cause U3 to operate at minimum attenuation as indicated by maximum LED brightness.
    • If you are using a signal generator with a built-in "step" attenuator, changing signal levels may cause momentary "glitches" of high signal that may cause a momentary disruption in the A/D reading and slightly upset the AGC:  Simply wait for a few seconds after making an adjustment for the readings to settle after making a change.

Figure 5:
Two bandpass + attenuator (U3) modules.
The inductors/capacitors of the filter may be seen in the
middle of the individual boards while the attenuator (U3) is the
white object seen in the lower-right corner of each board.  U3 is wired
"dead bug" style in each case.
Click on the image for a larger version.

Observations in use:

So far, these devices seem to be working as intended.  Even with higher overall gain in the signal path than before (e.g. when band conditions are poor and/or there are no strong signals in the filter's passband) the RTL-SDR dongles have not been observed to show obvious signs of overload when extremely strong signals are present - this having been a problem previously.  Initially, the AGC threshold was set for -6dBFS (1/2 A/D scale) using a CW signal from a test generator.  In the weeks that followed, these receivers were monitored during high-signal conditions and it was noted that there had been no obvious problems.  The AGC threshold was later reset for -12dBFS (1/4 A/D scale) and an additional 6dB of RF applied to the receivers with no obvious degradation in performance in the presence of strong signals, but a slight improvement in weak-signal performance when the bands were "closed".

In looking at receiver stats, there are still instances of A/D "clipping" - but this is to be expected:  The AGC circuit integrates the level over time (perhaps a few seconds) and brief excursions well above the threshold level are to be expected, both from static crashes, but also coincident modulation peaks of several strong shortwave broadcast signals.  Because the "occasional" clipping typically has little apparent impact on the receive signals (particularly the narrowband signals on shortwave frequencies) this effect isn't usually noticed.

On some of the bands, a bit more RF signal is needed to optimize performance - that is, to "tickle" more A/D bits when signals are weak.  Previously, doing so would risk gross overload of that receiver when the band "opened" with strong signals, but the AGC block should minimize any such issues.

Not mentioned previously, this AGC system can skew the S-meter readings from the receiver somewhat.  In the presence of strong signals, the AGC will lower the overall system gain causing the readings to vary and appear low.  In theory, one could monitor the voltage being applied to bias the attenuator and relate this to the amount of attenuation and offset the S-meter readings, but this may be overkill in most situations!




The above article was posted (by me) as a technical article at the Northern Utah WebSDR (link).

While the circuitry could be integrated onto a small circuit board, this has not been done as the circuits are quite simple and easy to construct as depicted.

* * *

This page stolen from ka7oei.blogspot.com

[End]