TorchDSP / torchsig

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

Resample() transform needs a new transition bandwidth estimate #196

Closed MattCarrickPL closed 11 months ago

MattCarrickPL commented 1 year ago

The resampling() transform has problems when computing for resampling rates > 1 due to the transition bandwidth calculation,

        transition_bandwidth=(0.5 - (new_rate * 0.98) / 2) / 4,

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

The transition bandwidth calculation also produces values that are too narrow and thus creates artificially large filter lengths.

MattCarrickPL commented 12 months ago

The transition bandwidth (in above comment) is part of an anti-aliasing filter proceeding the resample_poly() call:

if anti_alias_lpf:
    new_rate = up_rate / down_rate
    taps = low_pass(
        cutoff=new_rate * 0.98 / 2,
        transition_bandwidth=(0.5 - (new_rate * 0.98) / 2) / 4,
    )
    tensor = sp.convolve(tensor, taps, mode="same")

# Resample
resampled = sp.resample_poly(tensor, up_rate, down_rate)

The problem is that the anti-aliasing filter is redundant, due to the anti-aliasing filter implicit within the resample_poly() call. Proposing that the anti-aliasing filter be removed all together. Here's an example showing the marginal effect of the anti-aliasing filter:

image

MattCarrickPL commented 11 months ago

Merged into v0.4.2 via https://github.com/TorchDSP/torchsig/pull/211