TorchDSP / torchsig

TorchSig is an open-source signal processing machine learning toolkit based on the PyTorch data handling pipeline.
MIT License
170 stars 38 forks source link

AGC needs consistent log-base #188

Closed MattCarrickPL closed 1 year ago

MattCarrickPL commented 1 year ago

The AGC converts into decibels using natural log, but presumably the external parameters are all log10 based. The parameters such as ref_level_db, track_range_db, and others need to be converted from base-10 into base e before application to the AGC.

        level_db = level_db * alpha_smooth + np.log(np.abs(sample)) * (1 - alpha_smooth)

https://github.com/TorchDSP/torchsig/blob/v0.4.2/torchsig/transforms/functional.py#L1213

    output[sample_idx] = tensor[sample_idx] * np.exp(gain_db)

https://github.com/TorchDSP/torchsig/blob/v0.4.2/torchsig/transforms/functional.py#L1227

MattCarrickPL commented 1 year ago

Made a pass over this internally with code mods to perform the conversion, but not clear what value (if any) it provides. Converted the AGC algorithm to log10 rather than natural log, but it then requires the input parameters to also be changed into the appropriate scale.

The issue is that the AGC references a "dB" value which is the natural logarithm of the magnitude, as opposed to the 10log10() of the magnitude squared. The notation is different, but the algorithm as it exists is functionally correct. Would prefer to keep the existing code in place, not sure a code change provides any value.