Commit 3430fd68 authored by Ravi Makhija's avatar Ravi Makhija Committed by Facebook GitHub Bot
Browse files

Fix random Gaussian generation (#2639)

Summary:
This PR is meant to address the bug raised in issue https://github.com/pytorch/audio/issues/2634.

In particular, previously the Box Muller transform was used to generate Gaussian variates for dithering based on `torch.rand` uniform variates, but it was incorrectly implemented (e.g. the same uniform variate was used as input to the transform, rather than two different uniform variates), which led to a different (non-Gaussian) distribution. This PR instead uses `torch.randn` to generate the Gaussian variates.

Pull Request resolved: https://github.com/pytorch/audio/pull/2639

Reviewed By: mthrok

Differential Revision: D39101144

Pulled By: carolineechen

fbshipit-source-id: 691e49679f6598ef0a1675f6f4ee721ef32215fd
parent 08d3bb17
......@@ -177,9 +177,7 @@ def _get_window(
strided_input = _get_strided(waveform, window_size, window_shift, snip_edges)
if dither != 0.0:
# Returns a random number strictly between 0 and 1
x = torch.max(epsilon, torch.rand(strided_input.shape, device=device, dtype=dtype))
rand_gauss = torch.sqrt(-2 * x.log()) * torch.cos(2 * math.pi * x)
rand_gauss = torch.randn(strided_input.shape, device=device, dtype=dtype)
strided_input = strided_input + rand_gauss * dither
if remove_dc_offset:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment