bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / special / _basic / diric
function
scipy.special._basic:diric
source: build-install/usr/lib/python3.14/site-packages/scipy/special/_basic.py:93
Signature
def diric(x, n)Summary
Periodic sinc function, also called the Dirichlet kernel.
Extended Summary
The Dirichlet kernel is defined as
diric(x, n) = sin(x * n/2) / (n * sin(x / 2)),where n is a positive integer.
Parameters
x: array_likeInput data
n: intInteger defining the periodicity.
Returns
diric: ndarrayValue of periodic sinc function.
Examples
import numpy as np from scipy import special import matplotlib.pyplot as plt✓
x = np.linspace(-8*np.pi, 8*np.pi, num=201)
✓plt.figure(figsize=(8, 8)); for idx, n in enumerate([2, 3, 4, 9]): plt.subplot(2, 2, idx+1) plt.plot(x, special.diric(x, n)) plt.title('diric, n={}'.format(n))✗
<Axes: > [<matplotlib.lines.Line2D object at 0x7f3f68636660>] Text(0.5, 1.0, 'diric, n=2') <Axes: > [<matplotlib.lines.Line2D object at 0x7f3f68636270>] Text(0.5, 1.0, 'diric, n=3') <Axes: > [<matplotlib.lines.Line2D object at 0x7f3f686346e0>] Text(0.5, 1.0, 'diric, n=4') <Axes: > [<matplotlib.lines.Line2D object at 0x7f3f69163770>] Text(0.5, 1.0, 'diric, n=9')
plt.show()
✓
np.set_printoptions(suppress=True)
✓m = 8 k = 3 x = np.zeros(m) x[:k] = 1✓
np.abs(np.fft.fft(x))
✗array([3. , 2.414, 1. , 0.414, 1. , 0.414, 1. , 2.414])Now find the same values (up to sign) using `diric`. We multiply by `k` to account for the different scaling conventions of `numpy.fft.fft` and `diric`:
theta = np.linspace(0, 2*np.pi, m, endpoint=False)
✓k * special.diric(theta, k)
✗array([ 3. , 2.414, 1. , -0.414, -1. , -0.414, 1. , 2.414])
Aliases
scipy.special.diric