Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ tool-clean:

update: tool
. .venv/bin/activate && python -m pip install --upgrade pip
@for package in $$(./tools/taplo/taplo get -f pyproject.toml project.optional-dependencies.dev); do \
. .venv/bin/activate && python -m pip install --upgrade $$package; \
@./tools/taplo/taplo get -f pyproject.toml project.optional-dependencies.dev | while read -r package; do \
. .venv/bin/activate && python -m pip install --upgrade "$$package"; \
done

clean: dist-clean doc-clean test-clean tool-clean
Expand Down
27 changes: 0 additions & 27 deletions diffsptk/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -1138,33 +1138,6 @@ def hilbert(x: Tensor, fft_length: int | None = None, dim: int = -1) -> Tensor:
return nn.HilbertTransform._func(x, fft_length=fft_length, dim=dim)


def hilbert2(
x: Tensor,
fft_length: ArrayLike[int] | int | None = None,
dim: ArrayLike[int] = (-2, -1),
) -> Tensor:
"""Compute the analytic signal using the Hilbert transform.

Parameters
----------
x : Tensor [shape=(..., T1, T2, ...)]
The input signal.

fft_length : int, list[int], or None
The number of FFT bins. If None, set to (:math:`T1`, :math:`T2`).

dim : list[int]
The dimensions along which to take the Hilbert transform.

Returns
-------
out : Tensor [shape=(..., T1, T2, ...)]
The analytic signal.

"""
return nn.TwoDimensionalHilbertTransform._func(x, fft_length=fft_length, dim=dim)


def histogram(
x: Tensor,
n_bin: int = 10,
Expand Down
1 change: 0 additions & 1 deletion diffsptk/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
from .griffin import GriffinLim
from .grpdelay import GroupDelay
from .hilbert import HilbertTransform
from .hilbert2 import TwoDimensionalHilbertTransform
from .histogram import Histogram
from .ialaw import ALawExpansion
from .ica import IndependentComponentAnalysis
Expand Down
29 changes: 17 additions & 12 deletions diffsptk/modules/excite.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,16 @@ def _forward(
s = torch.cumsum(q.double(), dim=-1)
bias, _ = torch.cummax(s * ~mask, dim=-1)
phase = (s - bias).to(p.dtype)
if isinstance(init_phase, str):
if init_phase == "zeros":
pass
elif init_phase == "random":
phase += torch.rand_like(p[..., :1])
else:
raise ValueError(f"init_phase {init_phase} is not supported.")
if not isinstance(init_phase, str):
shift = init_phase / TAU
elif init_phase == "zeros":
shift = 0.0
elif init_phase == "random":
shift = torch.rand_like(p[..., :1])
else:
phase += init_phase / TAU
raise ValueError(f"init_phase {init_phase} is not supported.")
if isinstance(shift, torch.Tensor) or shift != 0.0:
phase += shift

# Generate excitation signal using phase.
if polarity == "auto":
Expand All @@ -170,15 +171,19 @@ def _forward(

def get_pulse_pos(p):
r = torch.ceil(p)
r = F.pad(r, (1, 0))
return torch.ge(torch.diff(r), 1)

if isinstance(shift, float):
padded_phase = F.pad(phase, (1, 0), value=shift)
else:
padded_phase = torch.cat([shift, phase], dim=-1)

if unipolar:
pulse_pos = get_pulse_pos(phase)
pulse_pos = get_pulse_pos(padded_phase)
e[pulse_pos] = torch.sqrt(p[pulse_pos])
else:
pulse_pos1 = get_pulse_pos(phase)
pulse_pos2 = get_pulse_pos(0.5 * phase)
pulse_pos1 = get_pulse_pos(padded_phase)
pulse_pos2 = get_pulse_pos(0.5 * padded_phase)
e[pulse_pos1] = torch.sqrt(p[pulse_pos1])
e[pulse_pos1 & ~pulse_pos2] *= -1
elif voiced_region == "sinusoidal":
Expand Down
133 changes: 0 additions & 133 deletions diffsptk/modules/hilbert2.py

This file was deleted.

4 changes: 0 additions & 4 deletions docs/source/modules/hilbert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,3 @@ hilbert
:members:

.. autofunction:: diffsptk.functional.hilbert

.. seealso::

:ref:`hilbert2`
13 changes: 0 additions & 13 deletions docs/source/modules/hilbert2.rst

This file was deleted.

53 changes: 0 additions & 53 deletions tests/test_hilbert2.py

This file was deleted.