Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Target peak amplitude of -6 dBFS in automatic gain selection #370

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

argilo
Copy link
Collaborator

@argilo argilo commented Mar 2, 2025

Fixes #238.
Fixes #333.

nrsc5's automatic gain selection currently works by stepping through all possible gain values, and measuring the amount of power present in the frequency ranges occupied by the HD Radio sidebands compared to the amount of power present at frequencies just below and just above the HD Radio sidebands.

This approach has some problems:

  • It often chooses a gain value that nearly saturates the ADC, leaving little headroom in case the signal amplitude increases.
  • The SNR measurement performs badly when adjacent-channel interference is present.
  • The SNR measurement performs badly when the gain is high enough for clipping to occur.

I think it would be better to instead measure the peak amplitude of the incoming signal, and target -6 dBFS (i.e. 6 dB below full scale, where clipping would begin). So far this approach seems to work well, and selects more sensible gain values. When no interfering signals are present, the -6 dBFS signal level is more than sufficient to receive an error-free signal, while leaving a decent amount of headroom. (Bit errors only begin occurring when the signal level is below -24 dBFS.)

I'd appreciate feedback from anyone who can take this for a spin to confirm whether it works better than the old approach.

@argilo
Copy link
Collaborator Author

argilo commented Mar 2, 2025

For anyone testing this, I'd be interested in any case where you're able to achieve a clearly higher MER (or clearly lower BER) by choosing your own gain instead of letting the automatic gain selection choose it.

@pclov3r
Copy link

pclov3r commented Mar 3, 2025

From testing a few stations arounds here appear to be getting the same MER at lower gain values.

Old method was setting around 32 dB gain and new method is setting around 28 dB

@argilo
Copy link
Collaborator Author

argilo commented Mar 3, 2025

From testing a few stations arounds here appear to be getting the same MER at lower gain values.

It sounds like it's working as intended then. The previous algorithm could set the gain dangerously close to saturating the ADC, while the new algorithm always keeps it at least 6 dB below the saturation point.

@argilo argilo merged commit 3f84c63 into master Mar 7, 2025
8 checks passed
@argilo argilo deleted the new-auto-gain branch March 7, 2025 01:11
@markjfine
Copy link

Late to the party but I just got though playing with the latest master that has this included.
As I'm in a marginal signal area using an amplified TV antenna on the roof, this is working real well. Have noticed the gain figures that it settles on hits the manual ones I've used in the past. Not only does this avoid saturation, but it also helps temper adjacent channel splatter. Real good enhancement.

@argilo
Copy link
Collaborator Author

argilo commented Mar 7, 2025

Thanks for testing this @markjfine!

I also had a look over the library of recordings that I made prior to this change, and I see that the majority of them have at least a small amount of clipping, so clearly the old gain selection often set the gain too high.

If necessary, we could increase or decrease the -6 dB threshold in the future, but so far this value seems to work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Trouble with nrsc5 - Linux Implement automatic gain selection for AM
3 participants