pyffs.interp¶
Methods for interpolating functions using Fourier Series.
-
fs_interp(x_FS, T, a, b, M, axis=-1, real_x=False)[source]¶ Interpolate bandlimited periodic signal.
If x_FS holds the Fourier Series coefficients of a bandlimited periodic function \(x(t): \mathbb{R} \to \mathbb{C}\), then
fs_interp()computes the values of \(x(t)\) at points \(t[k] = (a + \frac{b - a}{M - 1} k) 1_{[0,\ldots,M-1]}[k]\).- Parameters
x_FS (
ndarray) – (…, N_FS, …) FS coefficients in the order \(\left[ x_{-N}^{FS}, \ldots, x_{N}^{FS}\right]\).T (float) – Function period.
a (float) – Interval LHS.
b (float) – Interval RHS.
M (int) – Number of points to interpolate.
axis (int, optional) – Dimension of x_FS along which the FS coefficients are stored.
real_x (bool, optional) – If True, assume that x_FS is conjugate symmetric and use a more efficient algorithm. In this case, the FS coefficients corresponding to negative frequencies are not used.
- Returns
x – (…, M, …) interpolated values \(\left[ x(t[0]), \ldots, x(t[M-1]) \right]\) along the axis indicated by axis. If real_x is
True, the output is real-valued, otherwise it is complex-valued.- Return type
Examples
Let \(\{\phi_{k}^{FS}, k = -N, \ldots, N\}\) be the Fourier Series (FS) coefficients of a shifted Dirichlet kernel of period \(T\):
\[\begin{split}\phi_{k}^{FS} = \begin{cases} \exp\left( -j \frac{2 \pi}{T} k T_{c} \right) & -N \le k \le N, \\ 0 & \text{otherwise}. \end{cases}\end{split}\]# Parameters of the signal. >>> T, T_c, N_FS = math.pi, math.e, 15 >>> N = (N_FS - 1) // 2 # And the kernel's FS coefficients. >>> diric_FS = np.exp(-1j * (2 * np.pi / T) * T_c * np.r_[-N:N+1])
Being bandlimited, we can use
fs_interp()to numerically evaluate \(\phi(t)\) on the interval \(\left[ T_{c} - \frac{T}{2}, T_{c} + \frac{T}{2} \right]\):# Generate interpolated signal >>> a, b = T_c + (T / 2) * np.r_[-1, 1] >>> M = 100 # We want lots of points. >>> diric_sig = fs_interp(diric_FS, T, a, b, M) # Compare with theoretical result. >>> t = a + (b - a) / (M - 1) * np.arange(M) >>> diric_sig_exact = dirichlet(t, T, T_c, N_FS) >>> np.allclose(diric_sig, diric_sig_exact) True
The Dirichlet kernel is real-valued, so we can set real_x to use the accelerated algorithm instead:
# Generate interpolated signal >>> a, b = T_c + (T / 2) * np.r_[-1, 1] >>> M = 100 # We want lots of points. >>> diric_sig = fs_interp(diric_FS, T, a, b, M, real_x=True) # Compare with theoretical result. >>> t = a + (b - a) / (M - 1) * np.arange(M) >>> diric_sig_exact = dirichlet(t, T, T_c, N_FS) >>> np.allclose(diric_sig, diric_sig_exact) True
Notes
Theory: Fast Function Interpolation for Bandlimited Periodic Signals.
See also
-
fs_interpn(x_FS, T, a, b, M, axes=None, real_x=False)[source]¶ Interpolate D-dimensional bandlimited periodic signal.
- Parameters
x_FS (
ndarray) – (…, N_FSx, N_FSy, …) FS coefficients in ascending order.M (list(int)) – Number of points to interpolate for each dimension.
axes (tuple, optional) – Dimensions of x_FS along which the FS coefficients are stored.
real_x (bool, optional) – If True, assume that x_FS is conjugate symmetric in each dimension and use a more efficient algorithm. In this case, the FS coefficients corresponding to negative frequencies are not used. Note that this approach is only available for D < 3, and will raise an error otherwise.
- Returns
x – (…, M_1, M_2, …, M_D, …) interpolated values along the axes indicated by axes. If real_x is
True, the output is real-valued, otherwise it is complex-valued.- Return type
Notes
Theory: Fast Function Interpolation for Bandlimited Periodic Signals.
See also