2021-11-10
from numpy import pi, sin
a = 2
def L(x):
if x == 0: return 1
elif -a <= x < a:
return a*sin(pi*x)*sin(pi*x/a) / (pi**2 * x**2)
else: return 0
from numpy import pi, sin, floor
a = 2
def L(x):
if x == 0: return 1
elif -a <= x < a:
return a*sin(pi*x)*sin(pi*x/a) / (pi**2 * x**2)
else: return 0
# ys: y-coordinates
# x: any value between 0 and len(ys) - 1
def lanczos_query(ys, x):
n = ys.shape[0]
if x < 0 or x > n-1:
raise ValueError('value x must be between 0 and n-1')
y = 0.0
for i in range(int(floor(x)-a+1), int(floor(x)+a+1)):
j = i
if i < 0: j = 0
elif i > n-1: j = n-1
y += ys[j] * L(x - i)
return y
Watch the video: