Tuesday, August 25, 2026

Re: AGC2 formula is strange

Hey Thomas, yay! Haven't heard of you in a while! I'll talk to the others about your account, don't know whether we can do something about that. Yes, that formula seems strange. That applies, sadly, to all our three AGCs. Hm. I'm all for completely rewriting / pruning the AGCs, especially since nobody really seems to have any formalized idea of what they are *supposed* to do. I'd deprecate all three of them instantly, but I just haven't got a good replacement. Best, Marcus On 2026-08-25 12:42 PM, Thomas Habets wrote: > Hi. > I tried getting in to chat.gnuradio.org, but my login credentials no longer > work, and they still don't work after resetting my password (maybe my account > name to use for login is not my email?), so asking here instead. > > AGC2, in gr-analog/include/gnuradio/analog/agc2.h, has this code: > > ``` > gr_complex scale(gr_complex input) > { > gr_complex output = input * _gain; > > float tmp = -_reference + > sqrt(output.real() * output.real() + output.imag() > * output.imag()); > float rate = _decay_rate; > if ((tmp) > _gain) { > rate = _attack_rate; > } > _gain -= tmp * rate; > > // Not sure about this; will blow up if _gain < 0 (happens > // when rates are too high), but is this the solution? > if (_gain < 0.0) > _gain = 10e-5; > > if (_max_gain > 0.0 && _gain > _max_gain) { > _gain = _max_gain; > } > return output; > } > ``` > > I'm not talking about the "not sure about this", but about `if ((tmp) > > _gain) {`. > > Should that not be `> 0.0`? `tmp` is already current magnitude minus reference, > so should not attack vs decay rate be decided on whether it's above or below > reference, not above and below `reference + current gain`? > > Maybe there's a good reason, but in my mind this means that my input is such > that the current gain is normally 1000, input is ~1e-3 (noise) to 1e-1 (signal), > reference is 1, then the attack rate will basically never be used? > > Same for the agc2_ff duplication further down the file. > > I'm not sure if this is why my PWM experiments stabilize, just not to around > reference. > > -- > typedef struct me_s { > char name[] = { "Thomas Habets" }; > char email[] = { "thomas@habets.se" }; > char kernel[] = { "Linux" }; > char *pgpKey[] = { "http://www.habets.pp.se/pubkey.txt" }; > char pgp[] = { "9907 8698 8A24 F52F 1C2E 87F6 39A4 9EEA 460A 0169" }; > char coolcmd[] = { "echo '. ./_&. ./_'>_;. ./_" }; > } me_t; >

No comments:

Post a Comment