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

Improve center_frequency accuracy, fix edge case #575

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions pywt/_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,15 @@ def central_frequency(wavelet, precision=8):
domain = float(x[-1] - x[0])
assert domain > 0

index = np.argmax(abs(fft(psi)[1:])) + 2
if index > len(psi) / 2:
index = len(psi) - index + 2
# improve center frequency estimation by sampling DTFT(psi) more granularly
pad_factor = 3
psi_pad = np.pad(psi, [0, pad_factor * len(psi)])

return 1.0 / (domain / (index - 1))
index = np.argmax(abs(fft(psi_pad))[1:]) + 1 # omit dc, +1 to compensate
if index > len(psi_pad) / 2: # if negative freq, use index of positive
index = len(psi_pad) - index

return 1.0 / ((pad_factor + 1) * domain / index)


def scale2frequency(wavelet, scale, precision=8):
Expand Down