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

Hamming window simplification #100

Open
vadimkantorov opened this issue Nov 5, 2020 · 0 comments
Open

Hamming window simplification #100

vadimkantorov opened this issue Nov 5, 2020 · 0 comments

Comments

@vadimkantorov
Copy link

vadimkantorov commented Nov 5, 2020

https://github.com/mravanelli/SincNet/blob/master/dnn_models.py#L106-L108 :

#self.window_ = torch.hamming_window(self.kernel_size)
n_lin=torch.linspace(0, (self.kernel_size/2)-1, steps=int((self.kernel_size/2))) # computing only half of the window
self.window_=0.54-0.46*torch.cos(2*math.pi*n_lin/self.kernel_size);

Could it be replaced instead by self.window_ = torch.hamming_window(kernel_size)[:kernel_size // 2]? Or should it be self.window_ = torch.hamming_window(kernel_size, periodic = False)[:kernel_size // 2]?

There is some divergence. Is it only because of numerical reasons? Or maybe some boundary effects of torch.linspace? Here's PyTorch source code for: torch.hamming_window

import math
import torch

kernel_size = 251

window1 = 0.54 - 0.46 * torch.cos(2 * math.pi * torch.linspace(0, kernel_size / 2 - 1, steps=int((kernel_size / 2))) / kernel_size)
window2 = torch.hamming_window(kernel_size)[:kernel_size // 2]

print((window1 - window2).abs().max())
# tensor(0.0034)
@vadimkantorov vadimkantorov changed the title Hamming window usage Hamming window simplification Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant