pyffs.ffs

Methods for computing Fast Fourier Series.

ffs(x, T, T_c, N_FS, axis=-1)[source]

Fourier Series coefficients from signal samples of a 1D function.

Parameters:
  • x (ndarray) – (…, N_s, …) function values at sampling points specified by ffs_sample().

  • T (float) – Function period.

  • T_c (float) – Period mid-point.

  • N_FS (int) – Function bandwidth.

  • axis (int) – Dimension of x along which function samples are stored.

Returns:

x_FS – (…, N_s, …) vectors containing entries \(\left[ x_{-N}^{FS}, \ldots, x_{N}^{FS}, 0, \ldots, 0 \right] \in \mathbb{C}^{N_{s}}\).

Return type:

ndarray

Examples

Let \(\phi(t)\) be a shifted Dirichlet kernel of period \(T\) and bandwidth \(N_{FS} = 2 N + 1\):

\[\phi(t) = \sum_{k = -N}^{N} \exp\left( j \frac{2 \pi}{T} k (t - T_{c}) \right) = \frac{\sin\left( N_{FS} \pi [t - T_{c}] / T \right)}{\sin\left( \pi [t - T_{c}] / T \right)}.\]

Its Fourier Series (FS) coefficients \(\phi_{k}^{FS}\) can be analytically evaluated using the shift-modulation theorem:

\[\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}\]

Being bandlimited, we can use ffs() to numerically evaluate \(\{\phi_{k}^{FS}, k = -N, \ldots, N\}\):

>>> T, T_c, N_FS = math.pi, math.e, 15
>>> N_samples = 16  # Any >= N_FS will do, but highly-composite best.

# Sample the kernel and do the transform.
>>> sample_points, _ = ffs_sample(T, N_FS, T_c, N_samples)
>>> diric_samples = dirichlet(sample_points, T, T_c, N_FS)
>>> diric_FS = ffs(diric_samples, T, T_c, N_FS)

# Compare with theoretical result.
>>> np.allclose(diric_FS[:N_FS], dirichlet_fs(N_FS, T, T_c))
True

Notes

Theory: Fast Fourier Series Evaluation for Bandlimited Periodic Signals.

See also

ffs_sample(), iffs()

iffs(x_FS, T, T_c, N_FS, axis=-1)[source]

Signal samples from Fourier Series coefficients of a 1D function.

iffs() is basically the inverse of ffs().

Parameters:
  • x_FS (ndarray) – (…, N_s, …) FS coefficients in the order \(\left[ x_{-N}^{FS}, \ldots, x_{N}^{FS}, 0, \ldots, 0 \right] \in \mathbb{C}^{N_{s}}\).

  • T (float) – Function period.

  • T_c (float) – Period mid-point.

  • N_FS (int) – Function bandwidth.

  • axis (int) – Dimension of x_FS along which FS coefficients are stored.

Returns:

x – (…, N_s, …) vectors containing original function samples given to ffs().

In short: \((\text{iFFS} \circ \text{FFS})\{ x \} = x\).

Return type:

ndarray

Notes

Theory: Fast Fourier Series Evaluation for Bandlimited Periodic Signals.

See also

ffs_sample(), ffs()

ffsn(x, T, T_c, N_FS, axes=None)[source]

Fourier Series coefficients from signal samples of a D-dimension signal.

Parameters:
  • x (ndarray) – (…, N_s1, N_s2, …, N_sD, …) function values at sampling points specified by ffsn_sample().

  • T (list(float)) – Function period along each dimension.

  • T_c (list(float)) – Period mid-point for each dimension.

  • N_FS (list(int)) – Function bandwidth along each dimension.

  • axes (tuple) – Dimensions of x along which function samples are stored.

Returns:

x_FS – (…, N_s1, N_s2, …, N_sD, …) array containing Fourier Series coefficients in ascending order (top-left of matrix).

Return type:

ndarray

Examples

Let \(\phi(x, y)\) be a shifted Dirichlet kernel of periods \((T_x, T_y)\) and bandwidths \(N_{FS, x} = 2 N_x + 1, N_{FS, y} = 2 N_y + 1\):

\[\begin{split}\phi(x, y) &= \sum_{k_x = -N_x}^{N_x} \sum_{k_y = -N_y}^{N_y} \exp\left( j \frac{2 \pi}{T_x} k_x (x - T_{c,x}) \right) \exp\left( j \frac{2 \pi}{T_y} k_y (y - T_{c,y}) \right) \\ &= \frac{\sin\left( N_{FS, x} \pi [x - T_{c,x}] / T_x \right)}{\sin\left( \pi [x - T_{c, x}] / T_x \right)} \frac{\sin\left( N_{FS, y} \pi [y - T_{c,y}] / T_y \right)}{\sin\left( \pi [y - T_{c, y}] / T_y \right)}.\end{split}\]

Its Fourier Series (FS) coefficients \(\phi_{k_x, k_y}^{FS}\) can be analytically evaluated using the shift-modulation theorem:

\[\begin{split}\phi_{k_x, k_y}^{FS} = \begin{cases} \exp\left( -j \frac{2 \pi}{T_x} k_x T_{c,x} \right) \exp\left( -j \frac{2 \pi}{T_y} k_y T_{c,y} \right) & -N_x \le k_x \le N_x, -N_y \le k_y \le N_y, \\ 0 & \text{otherwise}. \end{cases}\end{split}\]

Being bandlimited, we can use ffsn() to numerically evaluate \(\{\phi_{k_x, k_y}^{FS}, k_x = -N_x, \ldots, N_x, k_y = -N_y, \ldots, N_y\}\):

>>> T = [1, 1]
>>> T_c = [0, 0]
>>> N_FS = [3, 3]
>>> N_s = [4, 3]

# Sample the kernel and do the transform.
>>> sample_points, _ = ffsn_sample(T=T, N_FS=N_FS, T_c=T_c, N_s=N_s)
>>> diric_samples = dirichlet_2D(sample_points, T, T_c, N_FS)
>>> diric_FS = ffsn(x=diric_samples, T=T, N_FS=N_FS, T_c=T_c)

# Compare with theoretical result.
>>> diric_FS_exact = np.outer(
... dirichlet_fs(N_FS[0], T[0], T_c[0]), dirichlet_fs(N_FS[1], T[1], T_c[1])
... )
>>> np.allclose(diric_FS[: N_FS[0], : N_FS[1]], diric_FS_exact)
True

Notes

Theory: Fast Fourier Series Evaluation for Bandlimited Periodic Signals.

iffsn(x_FS, T, T_c, N_FS, axes=None)[source]

Signal samples from Fourier Series coefficients of a D-dimension signal.

iffsn() is basically the inverse of ffsn().

Parameters:
  • x_FS (ndarray) – (…, N_s1, N_s2, …, N_sD, …) FS coefficients in ascending order.

  • T (list(float)) – Function period along each dimension.

  • T_c (list(float)) – Period mid-point for each dimension.

  • N_FS (list(int)) – Function bandwidth along each dimension.

  • axes (tuple) – Dimensions of x_FS along which FS coefficients are stored.

Returns:

x – (…, N_s1, N_s2, …, N_sD, …) array containing original function samples given to ffsn().

In short: \((\text{iFFS} \circ \text{FFS})\{ x \} = x\).

Return type:

ndarray

Notes

Theory: Fast Fourier Series Evaluation for Bandlimited Periodic Signals.

See also

ffsn_sample(), ffsn()