Skip to content

Commit 0bb072f

Browse files
committed
Update cosine
1 parent e9deb0e commit 0bb072f

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

torch/signal/windows/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ def add_docstr(function, docstr):
5252
>>> torch.signal.windows.cosine(10,periodic=False)
5353
tensor([0.1564, 0.4540, 0.7071, 0.8910, 0.9877, 0.9877, 0.8910, 0.7071, 0.4540,
5454
0.1564])
55+
56+
.. note::
57+
The window is normalized with the maximum value equal to 1, however, the 1 doesn't appear if `M` is even
58+
and `periodic` is `False`.
5559
""".format(
5660
**factory_common_args
5761
),

torch/signal/windows/windows.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ def cosine(window_length: int,
8686
if window_length == 1:
8787
return torch.ones((1,), dtype=dtype, layout=layout, device=device, requires_grad=requires_grad)
8888

89-
if periodic:
90-
window_length += 1
91-
9289
start = .5
93-
k = torch.arange(start, start + window_length, dtype=dtype, layout=layout, device=device, requires_grad=requires_grad)
94-
window = torch.sin(torch.pi / window_length * k)
95-
96-
return window[:-1] if periodic else window
90+
k = torch.arange(start,
91+
start+window_length,
92+
dtype=dtype,
93+
layout=layout,
94+
device=device,
95+
requires_grad=requires_grad)
96+
return torch.sin(torch.pi / (window_length + 1 if periodic else window_length) * k)
9797

9898

9999
def gaussian(window_length: int,

0 commit comments

Comments
 (0)