fht(a, dln, mu, offset=0.0, bias=0.0)
Computes the discrete Hankel transform of a logarithmically spaced periodic sequence using the FFTLog algorithm , .
This function computes a discrete version of the Hankel transform
where J_\mu is the Bessel function of order \mu. The index \mu may be any real number, positive or negative.
The input array a is a periodic sequence of length n, uniformly logarithmically spaced with spacing dln,
a_j = a(r_j) \;, \quad r_j = r_c \exp[(j-j_c) \, \mathtt{dln}]
centred about the point r_c. Note that the central index j_c = (n-1)/2 is half-integral if n is even, so that r_c falls between two input elements. Similarly, the output array A is a periodic sequence of length n, also uniformly logarithmically spaced with spacing dln
A_j = A(k_j) \;, \quad k_j = k_c \exp[(j-j_c) \, \mathtt{dln}]
centred about the point k_c.
The centre points r_c and k_c of the periodic intervals may be chosen arbitrarily, but it would be usual to choose the product k_c r_c = k_j r_{n-1-j} = k_{n-1-j} r_j to be unity. This can be changed using the offset parameter, which controls the logarithmic offset \log(k_c) = \mathtt{offset} - \log(r_c) of the output array. Choosing an optimal value for offset may reduce ringing of the discrete Hankel transform.
If the bias parameter is nonzero, this function computes a discrete version of the biased Hankel transform
where q is the value of bias, and a power law bias a_q(r) = a(r) \, (kr)^{-q} is applied to the input sequence. Biasing the transform can help approximate the continuous transform of a(r) if there is a value q such that a_q(r) is close to a periodic sequence, in which case the resulting A(k) will be close to the continuous transform.
Real periodic input array, uniformly logarithmically spaced. For multidimensional input, the transform is performed over the last axis.
Uniform logarithmic spacing of the input array.
Order of the Hankel transform, any positive or negative real number.
Offset of the uniform logarithmic spacing of the output array.
Exponent of power law bias, any positive or negative real number.
The transformed output array, which is real, periodic, uniformly logarithmically spaced, and of the same shape as the input array.
Compute the fast Hankel transform.
fhtoffset
:None:None:`fht`
ifht
:None:None:`fht`
import numpy as np
from scipy import fft
import matplotlib.pyplot as plt
mu = 0.0 # Order mu of Bessel function
r = np.logspace(-7, 1, 128) # Input evaluation points
dln = np.log(r[1]/r[0]) # Step size
offset = fft.fhtoffset(dln, initial=-6*np.log(10), mu=mu)
k = np.exp(offset)/r[::-1] # Output evaluation points
def f(x, mu):
"""Analytical function: x^(mu+1) exp(-x^2/2)."""
return x**(mu + 1)*np.exp(-x**2/2)
a_r = f(r, mu)
fht = fft.fht(a_r, dln, mu=mu, offset=offset)
a_k = f(k, mu)
rel_err = abs((fht-a_k)/a_k)
figargs = {'sharex': True, 'sharey': True, 'constrained_layout': True}
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4), **figargs)
ax1.set_title(r'$r^{\mu+1}\ \exp(-r^2/2)$')
ax1.loglog(r, a_r, 'k', lw=2)
ax1.set_xlabel('r')
ax2.set_title(r'$k^{\mu+1} \exp(-k^2/2)$')
ax2.loglog(k, a_k, 'k', lw=2, label='Analytical')
ax2.loglog(k, fht, 'C3--', lw=2, label='FFTLog')
ax2.set_xlabel('k')
ax2.legend(loc=3, framealpha=1)
ax2.set_ylim([1e-10, 1e1])
ax2b = ax2.twinx()
ax2b.loglog(k, rel_err, 'C0', label='Rel. Error (-)')
ax2b.set_ylabel('Rel. Error (-)', color='C0')
ax2b.tick_params(axis='y', labelcolor='C0')
ax2b.legend(loc=4, framealpha=1)
ax2b.set_ylim([1e-9, 1e-3])
plt.show()
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them