• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
Tuesday, October 21, 2025
newsaiworld
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
Morning News
No Result
View All Result
Home Artificial Intelligence

Implementing the Fourier Rework Numerically in Python: A Step-by-Step Information

Admin by Admin
October 21, 2025
in Artificial Intelligence
0
Chatgpt image 14 oct. 2025 08 10 18.jpg
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


To get probably the most out of this paper, you need to have a primary understanding of integrals and the Fourier rework and its properties.
If not, we advocate studying Part 1, the place these concepts are reviewed.
In case you are already aware of them, you possibly can go on to Part 2.

In Part 2.1, we implement the Fourier rework utilizing a numerical quadrature technique.
In Part 2.2, we implement it utilizing the Quick Fourier Rework (FFT) algorithm and Shannon’s interpolation method.

this paper got here to us throughout our closing yr at engineering college.

As a part of a course on stochastic course of calibration, our professor wished to check our understanding of the fabric. To take action, we have been requested to pick out a tutorial paper, research it intimately, and reproduce its outcomes

We selected the paper by El Kolei (2013), which proposes a parametric technique for estimating the parameters of a stochastic volatility mannequin, such because the GARCH mannequin. The strategy relies on distinction minimization and deconvolution.

To breed the outcomes, we wanted to implement an optimization technique that concerned computing the Fourier rework f̂ of the perform fθ:

To compute the Fourier rework of fθ, El Kolei (2013) used the left Riemann sum (also called the rectangle quadrature) technique carried out in MATLAB. The paper recommended that utilizing the Quick Fourier Rework (FFT) algorithm may make the computation quicker.

We determined to breed the outcomes utilizing Python and carried out the Fourier rework to check if it really improved computation velocity.. Implementing the left rectangle quadrature technique was easy, and at first, we thought that the scipy.fft and numpy.fft libraries would permit us to compute the Fourier rework of fθ straight utilizing the FFT algorithm.

Nevertheless, we rapidly found that these features do not compute the Fourier rework of a steady perform. As a substitute, they compute the Discrete Fourier Rework (DFT) of a finite sequence.

The determine under reveals what we noticed.

import numpy as np
import matplotlib.pyplot as plt
from scipy.fft import fft, fftfreq, fftshift

# Outline the perform f(t) = exp(-pi * t^2)
def f(t):
    return np.exp(-np.pi * t**2)

# Parameters
N = 1024
T = 1.0 / 64
t = np.linspace(-N/2*T, N/2*T, N, endpoint=False)
y = f(t)

# FFT with scipy
yf_scipy = fftshift(fft(y)) * T
xf = fftshift(fftfreq(N, T))
FT_exact = np.exp(-np.pi * xf**2)

# FFT with numpy
yf_numpy = np.fft.fftshift(np.fft.fft(y)) * T
xf_numpy = np.fft.fftshift(np.fft.fftfreq(N, T))

# Plot with subplot_mosaic
fig, axs = plt.subplot_mosaic([["scipy", "numpy"]], figsize=(7, 5), format="constrained", sharey=True)

# Scipy FFT
axs["scipy"].plot(xf, FT_exact, 'k-', linewidth=1.5, label='Actual FT')
axs["scipy"].plot(xf, np.actual(yf_scipy), 'r--', linewidth=1, label='FFT (scipy)')
axs["scipy"].set_xlim(-6, 6)
axs["scipy"].set_ylim(-1, 1)
axs["scipy"].set_title("Scipy FFT")
axs["scipy"].set_xlabel("Frequency")
axs["scipy"].set_ylabel("Amplitude")
axs["scipy"].legend()
axs["scipy"].grid(False)

# NumPy FFT
axs["numpy"].plot(xf_numpy, FT_exact, 'k-', linewidth=1.5, label='Actual FT')
axs["numpy"].plot(xf_numpy, np.actual(yf_numpy), 'b--', linewidth=1, label='FFT (numpy)')
axs["numpy"].set_xlim(-6, 6)
axs["numpy"].set_title("NumPy FFT")
axs["numpy"].set_xlabel("Frequency")
axs["numpy"].legend()
axs["numpy"].grid(False)

plt.suptitle("Comparability of FFT Implementations vs. Actual Fourier Rework", fontsize=14)
plt.present()

This expertise impressed us to write down this text, the place we are going to clarify the right way to compute the Fourier rework of a perform in Python utilizing two approaches: the left Riemann sum technique and the Quick Fourier Rework (FFT) algorithm.

Within the literature, many papers talk about the right way to approximate the Fourier rework and the right way to implement it utilizing numerical strategies.

Nevertheless, we didn’t discover a supply as clear and full as Balac (2011). This work presents a quadrature-based strategy to compute the Fourier rework and explains the right way to use the Quick Fourier Rework (FFT) algorithm to carry out the discrete Fourier rework effectively.

The FFT algorithm may be utilized each to compute the Fourier rework of an integrable perform and to calculate the Fourier coefficients of a periodic perform.

1. Definition and Properties of the Fourier Rework

We undertake the framework introduced by Balac (2011) to outline the Fourier rework of a perform f and to introduce its properties.

We think about features that belong to the area of integrable features, denoted L¹(ℝ, 𝕂). This area contains all features f: ℝ → 𝕂, the place 𝕂 represents both the true numbers (ℝ) or the advanced numbers (ℂ).

These features are integrable within the sense of Lebesgue, which means that the integral of their absolute worth is finite.

So, for a perform f to belong to L¹(ℝ, 𝕂), the product f(t) · e–2iπνt should even be integrable for all ν ∈ ℝ.

In that case, the Fourier rework of f, denoted f̂ (or generally 𝓕(f)), is outlined for all ν ∈ ℝ by:

We word that the Fourier rework f̂ of a perform f is a complex-valued, linear perform that depends upon the frequency ν.

If f ∈ L¹(ℝ), is real-valued and even, then f̂ can be real-valued and even. Conversely, if f is real-valued and odd, then f̂ is solely imaginary and odd as nicely.

For some features, the Fourier rework may be computed analytically. For instance, for the perform
f : t ∈ ℝ ↦ 𝟙 [−a⁄2, a⁄2](t),
The Fourier rework is given by:

f̂(ν) = a sinc(a π ν)

the place  is the sinc(t) = sin(t)/t or t ∈ ℝ*, and sinc(0) = 0.

Nevertheless, for a lot of features, the Fourier rework can’t be computed analytically. In such instances, we use numerical strategies to approximate it. We discover these numerical approaches within the following sections of this text.

2. How you can numerically approximate the Fourier Rework?

In his article, Balac (2011) reveals that computing the Fourier rework of a perform entails approximating it by the next integral over the interval [−T⁄2, T⁄2]:

The place T is a sufficiently giant quantity for the integral to converge.. An approximate worth of the integral S̃(ν) may be computed utilizing quadrature strategies.

Within the subsequent part, we are going to approximate this integral utilizing the left rectangle quadrature technique (also called the left Riemann sum).

2.1 Quadrature technique of left Rectangles

To compute the integral S̃(ν) utilizing the left rectangle quadrature technique, we proceed as follows:

  1. Discretization of the Interval
    We divide the interval [−T⁄2, T⁄2] into N uniform subintervals of size ht = T⁄N.
    The discretization factors, similar to the left endpoints of the rectangles, are outlined as:

tok = −T⁄2 + ht, for ok = 0, 1, …, N−1.

  1. Approximation of the Integral
    Utilizing the Chasles relation, we approximate the integral S̃(ν) as follows:

Since tₖ₊₁ − tₖ = hₜ and tₖ = −T⁄2 + ok·hₜ = T(ok⁄N − ½), the expression turns into:

We discuss with this strategy because the left rectangle quadrature technique as a result of it makes use of the left endpoint tₖ of every subinterval to approximate the worth of f(t) inside that interval.

  1. Last Method
    The ultimate expression for approximating the Fourier rework is given by:

2.1.1 Implementation of the left rectangle quadrature technique in Python.

The perform tfquad under implements the left rectangle quadrature technique to compute the Fourier rework of a perform f at a given frequency nu.

import numpy as np

def tfquad(f, nu, n, T):
    """
    Computes the Fourier rework of a perform f at frequency nu
    utilizing left Riemann sum quadrature over the interval [-T/2, T/2].

    Parameters:
    ----------
    f : callable
        The perform to remodel. Should settle for a NumPy array as enter.
    nu : float
        The frequency at which to guage the Fourier rework.
    n : int
        Variety of quadrature factors.
    T : float
        Width of the time window [-T/2, T/2].

    Returns:
    -------
    tfnu : advanced
        Approximated worth of the Fourier rework at frequency nu.
    """
    ok = np.arange(n)
    t_k = (ok / n - 0.5) * T
    weights = np.exp(-2j * np.pi * nu * T * ok / n)
    prefactor = (T / n) * np.exp(1j * np.pi * nu * T)

    return prefactor * np.sum(f(t_k) * weights)

We will additionally use SciPy’s quad perform to outline the Fourier rework of a perform f at a given frequency nu. The perform tf_integral under implements this strategy. It makes use of numerical integration to compute the Fourier rework of f over the interval [-T/2, T/2].

READ ALSO

Constructing Transformer Fashions from Scratch with PyTorch (10-day Mini-Course)

10 Python One-Liners for Calling LLMs from Your Code

from scipy.combine import quad

def tf_integral(f, nu, T):
    """Compute FT of f at frequency nu over [-T/2, T/2] utilizing scipy quad."""
    real_part = quad(lambda t: np.actual(f(t) * np.exp(-2j * np.pi * nu * t)), -T/2, T/2)[0]
    imag_part = quad(lambda t: np.imag(f(t) * np.exp(-2j * np.pi * nu * t)), -T/2, T/2)[0]
    return real_part + 1j * imag_part

After deriving the method for the left rectangle quadrature technique, we are able to now implement it in Python to see the way it performs in observe.

To do that, we think about a easy instance the place the perform fff is outlined as an indicator perform on the interval [−1, 1]:

For this perform, the Fourier rework may be computed analytically, which permits us to evaluate the numerical approximation with the precise end result.

The next Python script implements each the analytical Fourier rework and its numerical approximations utilizing:

  • the left rectangle quadrature technique, and
  • SciPy’s integration perform for reference.
import numpy as np
import matplotlib.pyplot as plt

# ----- Operate Definitions -----

def f(t):
    """Indicator perform on [-1, 1]."""
    return np.the place(np.abs(t) <= 1, 1.0, 0.0)

def exact_fourier_transform(nu):
    """Analytical FT of the indicator perform over [-1, 1]."""
    # f̂(ν) = ∫_{-1}^{1} e^{-2πiνt} dt = 2 * sinc(2ν)
    return 2 * np.sinc(2 * nu)


# ----- Computation -----

T = 2.0
n = 32
nu_vals = np.linspace(-6, 6, 500)
exact_vals = exact_fourier_transform(nu_vals)
tfquad_vals = np.array([tfquad(f, nu, n, T) for nu in nu_vals])

# Compute the approximation utilizing scipy integral
tf_integral_vals = np.array([tf_integral(f, nu, T) for nu in nu_vals])

# ----- Plotting -----
fig, axs = plt.subplot_mosaic([["tfquad", "quad"]], figsize=(7.24, 4.07), dpi=100, format="constrained")

# Plot utilizing tfquad implementation
axs["tfquad"].plot(nu_vals, np.actual(exact_vals), 'b-', linewidth=2, label=r'$hat{f}$ (precise)')
axs["tfquad"].plot(nu_vals, np.actual(tfquad_vals), 'r--', linewidth=1.5, label=r'approximation $hat{S}_n$')
axs["tfquad"].set_title("TF avec tfquad (rectangles)")
axs["tfquad"].set_xlabel(r'$nu$')
axs["tfquad"].grid(False)
axs["tfquad"].set_ylim(-0.5, 2.1)

# Plot utilizing scipy.combine.quad
axs["quad"].plot(nu_vals, np.actual(exact_vals), 'b-', linewidth=2, label=r'$hat{f}$ (quad)')
axs["quad"].plot(nu_vals, np.actual(tf_integral_vals), 'r--', linewidth=1.5, label=r'approximation $hat{S}_n$')
axs["quad"].set_title("TF avec scipy.combine.quad")
axs["quad"].set_xlabel(r'$nu$')
axs["quad"].set_ylabel('Amplitude')
axs["quad"].grid(False)
axs["quad"].set_ylim(-0.5, 2.1)



# --- International legend under the plots ---
# Take handles from one subplot solely (assumes labels are constant)
handles, labels = axs["quad"].get_legend_handles_labels()
fig.legend(handles, labels,
           loc='decrease heart', bbox_to_anchor=(0.5, -0.05),
           ncol=3, frameon=False)

plt.suptitle("Comparability of FFT Implementations vs. Actual Fourier Rework", fontsize=14)

plt.present()

2.1.2 Characterization of approximation utilizing the left rectangle quadrature technique

  • The approximation of the Fourier rework  utilizing the left rectangle quadrature technique displays an oscillatory habits by nature.

    As famous by Balac (2011), the Fourier rework f̂ of a perform f is inherently oscillatory. This habits comes from the advanced exponential time period e⁻²πiνt within the integral definition of the rework.

As an example this habits, the determine under reveals the perform

f : t ∈ ℝ ↦ e-t^2 ∈ ℝ

along with the actual and imaginary components of its Fourier rework

f̂ : ν ∈ ℝ ↦ f̂(ν) ∈ ℂ, evaluated at ν = 5⁄2.

Though f(t) is clean, we are able to observe robust oscillations in f̂(ν), which reveal the affect of the exponential time period e-2πiνt within the Fourier integral.

import numpy as np
import matplotlib.pyplot as plt

nu = 5 / 2
t1 = np.linspace(-8, 8, 1000)
t2 = np.linspace(-4, 4, 1000)

f = lambda t: np.exp(-t**2)
phi = lambda t: f(t) * np.exp(-2j * np.pi * nu * t)

f_vals = f(t1)
phi_vals = phi(t2)

# Plot
fig, axs = plt.subplots(1, 2, figsize=(10, 4))

axs[0].plot(t1, f_vals, 'ok', linewidth=2)
axs[0].set_xlim(-8, 8)
axs[0].set_ylim(0, 1)
axs[0].set_title(r"$f(t) = e^{-t^2}$")
axs[0].grid(True)

axs[1].plot(t2, np.actual(phi_vals), 'b', label=r"$Re(phi)$", linewidth=2)
axs[1].plot(t2, np.imag(phi_vals), 'r', label=r"$Im(phi)$", linewidth=2)
axs[1].set_xlim(-4, 4)
axs[1].set_ylim(-1, 1)
axs[1].set_title(r"$phi(t) = f(t)e^{-2ipinu t}$, $nu=5/2$")
axs[1].legend()
axs[1].grid(True)

plt.tight_layout()
plt.present()
  • The approximation obtained utilizing the left rectangle quadrature technique is periodic in nature.

    We observe that even when the perform f is not periodic, its Fourier rework approximation f̂ seems to be periodic.

    Actually, the perform Ŝₙ, obtained from the quadrature technique, is periodic with a interval given by:

This periodicity of Ŝₙ implies that it’s not attainable to compute the Fourier rework for all frequencies ν ∈ ℝ utilizing the quadrature technique when the parameters T and n are mounted.

Actually, it turns into not possible to compute f̂(ν) precisely when

|ν| ≥ νmax,

the place v = n/T represents the most frequency that may be resolved due to the periodic nature of Ŝₙ.

In consequence, in observe, to compute the Fourier rework for bigger frequencies, one should enhance both the time window (T) or the variety of factors (n).

Moreover, by evaluating the error in approximating f̂(ν) utilizing the left rectangle quadrature technique, we are able to present that the approximation is dependable at frequency ν when the next situation holds:

|ν| ≪ n/T or equivalently, (|ν|T)/n ≪ 1.

In accordance with Epstein (2005), when utilizing the Quick Fourier Rework (FFT) algorithm, it’s attainable to precisely compute the Fourier rework of a perform f for all frequencies ν ∈ ℝ, even when (|ν|T)⁄n is near 1, offered that f is piecewise steady and has compact assist.

2.2 Computing the Fourier Rework at Frequency ν Utilizing the FFT Algorithm

On this part, we denote by Ŝₙ(ν) the approximation of the Fourier rework f̂(ν) of the perform f at some extent ν ∈ [−νmax/2, νmax/2], the place νmax = n/T, that’s,

I now current the Fourier rework algorithm used to approximate f̂(ν).
I can’t go into the small print of the Quick Fourier Rework (FFT) algorithm on this article.
For a simplified clarification, I discuss with Balac (2011), and for a extra technical and complete remedy, to the authentic work by Cooley and Tukey (1965).

You will need to perceive that using the FFT algorithm to approximate the Fourier rework of a perform f relies on the end result established by Epstein (2005). This end result states that when Ŝₙ(ν) is evaluated on the frequencies vj = j/T, for j = 0, 1, …, n − 1, it supplies an excellent approximation of the continual Fourier rework f̂(ν).

Furthermore, Ŝₙ is thought to be periodic. This periodicity assigns a symmetric position to the indices j ∈ {0, 1, …, n − 1} and ok ∈ {−n/2, −n/2 + 1, …, −1}.

Actually, the values of the Fourier rework of f over the interval [−νmax/2, νmax/2] may be derived from the values of Ŝₙ on the factors νj = j/T, for j = 0, 1, …, n − 1, as follows:

the place we used the relation:

This relationship reveals that the Fourier rework Ŝₙ(j/T) may be computed for j = −n⁄2, …, n⁄2 − 1.

Furthermore, when n is an influence of two, the computation turns into considerably quicker (see Balac, 2011). This course of is named the Quick Fourier Rework (FFT).

To summarize, I’ve proven that the Fourier rework of the perform f may be approximated over the interval [−T⁄2, T⁄2] on the frequencies vj = j/T, for j = −n/2, …, n/2 − 1, the place n = 2ᵐ for some integer m ≥ 0, by making use of the Quick Fourier Rework (FFT) algorithm as follows:

  • Step 1: Assemble the finite sequence F of values
    f((2k − n)T/(2n)), for ok = 0, 1, …, n − 1.
  • Step 2: Compute the discrete Fourier rework (DFT) of the sequence F utilizing the FFT algorithm, given by:
  • Step 3: Reindex and symmetrize the values to span j = −n/2, …, −1.
  • Step 4: Multiply every worth within the array by (T/n)(−1)j-1, the place j ∈ {1, …, n}.

This course of yields an array representing the values of the Fourier rework f̂(νⱼ), with νj = j/T for j = −n⁄2, …, n⁄2 − 1.

The Python perform tffft under implements these steps to compute the Fourier rework of a given perform.

import numpy as np
from scipy.fft import fft, fftshift

def tffft(f, T, n):
    """
    Calcule la transformée de Fourier approchée d'une fonction f à assist dans [-T/2, T/2],
    en utilisant l’algorithme FFT.

    Paramètres
    ----------
    f : callable
        Fonction à transformer (doit être vectorisable avec numpy).
    T : float
        Largeur de la fenêtre temporelle (intervalle [-T/2, T/2]).
    n : int
        Nombre de factors de discrétisation (doit être une puissance de 2 pour FFT efficace).

    Retours
    -------
    tf : np.ndarray
        Valeurs approximées de la transformée de Fourier aux fréquences discrètes.
    freq_nu : np.ndarray
        Fréquences discrètes correspondantes (de -n/(2T) à (n/2 - 1)/T).
    """
    h = T / n
    t = -0.5 * T + np.arange(n) * h  # noeuds temporels
    F = f(t)                         # échantillonnage de f
    tf = h * (-1) ** np.arange(n) * fftshift(fft(F))  # TF approximée
    freq_nu = -n / (2 * T) + np.arange(n) / T              # fréquences ν_j = j/T

    return tf, freq_nu, t

The next program illustrates the right way to compute the Fourier rework of the Gaussian perform f(t) = e-10t^2 over the interval [-10, 10], utilizing the Quick Fourier Rework (FFT) algorithm.

# Parameters
a = 10
f = lambda t: np.exp(-a * t**2)
T = 10
n = 2**8  # 256

# Compute the Fourier rework utilizing FFT
tf, nu, t = tffft(f, T, n)

# Plotting
fig, axs = plt.subplots(1, 2, figsize=(7.24, 4.07), dpi=100)

axs[0].plot(t, f(t), '-g', linewidth=3)
axs[0].set_xlabel("time")
axs[0].set_title("Thought of Operate")
axs[0].set_xlim(-6, 6)
axs[0].set_ylim(-0.5, 1.1)
axs[0].grid(True)

axs[1].plot(nu, np.abs(tf), '-b', linewidth=3)
axs[1].set_xlabel("frequency")
axs[1].set_title("Fourier Rework utilizing FFT")
axs[1].set_xlim(-15, 15)
axs[1].set_ylim(-0.5, 1)
axs[1].grid(True)

plt.tight_layout()
plt.present()

The tactic I simply introduced makes it attainable to compute and visualize the Fourier rework of a perform f at discrete factors vj = j/T, for j = −n/2, …, n/2 − 1, the place n is an influence of two.

These factors lie throughout the interval [−n/(2T), n/(2T)].
Nevertheless, this technique doesn’t permit us to guage the Fourier rework at arbitrary frequencies ν that aren’t of the shape vj = j/T.

To compute the Fourier rework of a perform f at a frequency ν that doesn’t match one of many sampled frequencies νⱼ, interpolation strategies can be utilized, akin to linear, polynomial, or spline interpolation.

On this article, we use the strategy proposed by Balac (2011), which depends on Shannon’s interpolation theorem to compute the Fourier rework of f at any frequency ν.

Utilizing Shannon’s Interpolation Theorem to Compute the Fourier Rework of a Operate f at a Level ν

What does Shannon’s theorem inform us?

It states that for a band-limited perform g — that’s, a perform whose Fourier rework ĝ is zero exterior the interval [−B⁄2, B⁄2] — the perform g may be reconstructed from its samples gₖ = g(ok⁄B) for ok ∈ ℤ.

If we let νc be the smallest constructive quantity such that ĝ(ν) is zero exterior the interval [−2πνc, 2πνc], then the Shannon interpolation method applies.
For each t ∈ ℝ, and any constructive actual quantity α ≥ 1/(2νc), we’ve:

the place sinc(x) = sin(x)/x is the sinc perform (cardinal sine).

Balac (2011) reveals that when a perform f has a bounded assist within the interval [−T⁄2, T⁄2], Shannon’s interpolation theorem can be utilized to compute its Fourier rework f̂(ν) for any ν ∈ ℝ.
That is finished through the use of the values of the discrete Fourier rework Ŝₙ(νⱼ) for j = −n/2, …, (n/2 − 1).

By setting α = 1/T, Balac derives the next Shannon interpolation method, legitimate for all ν ∈ ℝ:

The next program illustrates the right way to use Shannon’s interpolation theorem to compute the Fourier rework of a perform f at a given frequency ν.

To compute the Fourier rework at any frequency ν, we are able to use Shannon’s interpolation theorem.

The thought is to estimate the worth of the Fourier rework from its discrete samples obtained by the FFT.

The perform under, shannon, implements this interpolation technique in Python.


def shannon(tf, nu, T):
    """
    Approximates the worth of the Fourier rework of perform f at frequency 'nu'
    utilizing its discrete values computed from the FFT.

    Parameters:
    - tf : numpy array, discrete Fourier rework values (centered with fftshift) at frequencies j/T for j = -n/2, ..., n/2 - 1
    - nu : float, frequency at which to approximate the Fourier rework
    - T  : float, time window width used for the FFT

    Returns:
    - tfnu : approximation of the Fourier rework at frequency 'nu'
    """
    n = len(tf)
    tfnu = 0.0
    for j in vary(n):
        ok = j - n // 2  # correspond à l'indice j dans {-n/2, ..., n/2 - 1}
        tfnu += tf[j] * np.sinc(T * nu - ok)  # np.sinc(x) = sin(pi x)/(pi x) en numpy

    return tfnu

The subsequent perform, fourier_at_nu, combines two steps.
It first computes the discrete Fourier rework of a perform utilizing the FFT (tffft), then applies Shannon interpolation to estimate the Fourier rework at a selected frequency ν.

This makes it attainable to guage the rework at any arbitrary level ν, not simply on the FFT sampling frequencies.

We will now check our implementation utilizing a easy instance.
Right here, we outline a perform f(t) = e-a|t|, whose Fourier rework is thought analytically.

This lets us evaluate the precise Fourier rework with the approximation obtained utilizing our technique.

a = 0.5
f = lambda t: np.exp(-a * np.abs(t))                          # Operate to remodel
fhat_exact = lambda nu: (2 * a) / (a**2 + 4 * np.pi**2 * nu**2)  # Actual Fourier rework

T = 40     # Time window
n = 2**10  # Variety of discretization factors

We consider the Fourier rework at two frequencies: ν = 3/T and ν = π/T.

For every case, we print each the precise worth and the approximation obtained by our fourier_at_nu perform.

This comparability helps confirm the accuracy of Shannon interpolation.

# Compute for nu = 3/T

nu = 3 / T

exact_value = fhat_exact(nu)
approx_value = fourier_at_nu(f, T, n, nu)
print(f"Actual worth at nu={nu}: {exact_value}")
print(f"Approximation at nu={nu}: {np.actual(approx_value)}")

# Compute for nu = pi/T

nu = np.pi / T

exact_value = fhat_exact(nu)
approx_value = fourier_at_nu(f, T, n, nu)
print(f"Actual worth at nu={nu}: {exact_value}")
print(f"Approximation at nu={nu}: {np.actual(approx_value)}")
Actual worth at ν = 3/T: 2.118347413776218  
Approximation at ν = 3/T: (2.1185707502943534)

Actual worth at ν = π/T: 2.0262491352594427  
Approximation at ν = π/T: (2.0264201680784835)

It’s value noting that though the frequency 3⁄T (whose Fourier rework worth seems within the FFT output) is near π⁄T, the corresponding values of the Fourier rework of f at these two frequencies are fairly completely different.

This reveals that Shannon’s interpolation method may be very helpful when the specified Fourier rework values are in a roundabout way included among the many outcomes produced by the FFT algorithm.

Conclusion

On this article, we explored two strategies to approximate the Fourier rework of a perform.

The primary was a numerical quadrature technique (the left rectangle rule), and the second was the Quick Fourier Rework (FFT) algorithm.

We confirmed that, not like the built-in fft features in SciPy or NumPy, the FFT may be tailored to compute the Fourier rework of a steady perform by means of correct formulation.

Our implementation was based mostly on the work of Balac (2013), who demonstrated the right way to reproduce the FFT computation in Python.
We additionally launched Shannon’s interpolation theorem, which permits us to estimate the Fourier rework of any perform on ℝ at arbitrary frequencies.

This interpolation may be changed by extra conventional approaches akin to linear or spline interpolation when applicable.

Lastly, it is very important word that when the Fourier rework is required at a single frequency, it’s typically extra environment friendly to compute it straight utilizing a numerical quadrature technique.

Such strategies are nicely suited to deal with the oscillatory nature of the Fourier integral and may be extra correct than making use of the FFT after which interpolating.

References

Balac, Stéphane. 2011. “La Transformée de Fourier Vue Sous l’angle Du Calcul Numérique.”

Cooley, James W, and John W Tukey. 1965. “An Algorithm for the Machine Calculation of Advanced Fourier Sequence.” Arithmetic of Computation 19 (90): 297–301.

El Kolei, Salima. 2013. “Parametric Estimation of Hidden Stochastic Mannequin by Distinction Minimization and Deconvolution: Utility to the Stochastic Volatility Mannequin.” Metrika 76 (8): 1031–81.

Epstein, Charles L. 2005. “How Properly Does the Finite Fourier Rework Approximate the Fourier Rework?” Communications on Pure and Utilized Arithmetic: A Journal Issued by the Courant Institute of Mathematical Sciences 58 (10): 1421–35.

M. Crouzeix and A.L. Mignot. Analyse numérique des équations différentielles. Assortment mathématiques appliquées
pour la maîtrise. Masson, 1992.

A.M. Quarteroni, J.F. Gerbeau, R. Sacco, and F. Saleri. Méthodes numériques pour le calcul scientifique : Programmes
en MATLAB. Assortment IRIS. Springer Paris, 2000.

A. Iserles and S. Norsett. On quadrature strategies for extremely oscillatory integrals and their implementation. BIT
Numerical Arithmetic, 44 :755–772, 2004.

A. Iserles and S. Norsett. Environment friendly quadrature of extremely oscillatory integrals utilizing derivatives. Proc. R. Soc. A,
461 :1383–1399, 2005.

Picture Credit

All photographs and visualizations on this article have been created by the creator utilizing Python (pandas, matplotlib, seaborn, and plotly) and Excel, until in any other case said.

Disclaimer

I write to study, so errors are the norm, though I strive my finest. Please let me know if you happen to discover any. I’m additionally open to any options for brand new subjects!


Tags: FourierGuideimplementingNumericallyPythonStepbyStepTransform

Related Posts

Caleb jack juxmsnzzcj8 unsplash scaled.jpg
Artificial Intelligence

Constructing Transformer Fashions from Scratch with PyTorch (10-day Mini-Course)

October 21, 2025
Mlm shittu 10 python one liners for calling llms from your code 1024x576.png
Artificial Intelligence

10 Python One-Liners for Calling LLMs from Your Code

October 21, 2025
Image 244.jpg
Artificial Intelligence

Use Frontier Imaginative and prescient LLMs: Qwen3-VL

October 20, 2025
Mlm ipc 7 feature engineering tricks text data 1024x683.png
Artificial Intelligence

7 Characteristic Engineering Tips for Textual content Knowledge

October 20, 2025
Image 215 1024x683.png
Artificial Intelligence

The best way to Construct Guardrails for Efficient Brokers

October 20, 2025
Mlm 3 ways speed model training without gpu 1024x683.png
Artificial Intelligence

3 Methods to Pace Up Mannequin Coaching With out Extra GPUs

October 19, 2025
Next Post
Image 15.jpg

Scaling Recommender Transformers to a Billion Parameters

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

0 3.png

College endowments be a part of crypto rush, boosting meme cash like Meme Index

February 10, 2025
Blog.png

XMN is accessible for buying and selling!

October 10, 2025
Gemini 2.0 Fash Vs Gpt 4o.webp.webp

Gemini 2.0 Flash vs GPT 4o: Which is Higher?

January 19, 2025
1da3lz S3h Cujupuolbtvw.png

Scaling Statistics: Incremental Customary Deviation in SQL with dbt | by Yuval Gorchover | Jan, 2025

January 2, 2025
0khns0 Djocjfzxyr.jpeg

Constructing Data Graphs with LLM Graph Transformer | by Tomaz Bratanic | Nov, 2024

November 5, 2024

EDITOR'S PICK

Chatgpt Image Apr 3 2025 11 19 50 Am.png

Kernel Case Examine: Flash Consideration

April 4, 2025
Financial Services Wall Street 2 1 Shutterstock 2452656115.jpg

Balancing Innovation and Threat: Present and Future Use of LLMs within the Monetary Business

February 7, 2025
Elon Musk Twitter.jpg

Elon Musk slams SEC as ‘damaged’ over ‘artificially’ created $150 million Twitter inventory windfall

January 15, 2025
Dynamics 365 for customer engagement.jpg

Reinvent Buyer Engagement with Dynamics 365: Flip Insights into Motion

October 16, 2025

About Us

Welcome to News AI World, your go-to source for the latest in artificial intelligence news and developments. Our mission is to deliver comprehensive and insightful coverage of the rapidly evolving AI landscape, keeping you informed about breakthroughs, trends, and the transformative impact of AI technologies across industries.

Categories

  • Artificial Intelligence
  • ChatGPT
  • Crypto Coins
  • Data Science
  • Machine Learning

Recent Posts

  • Constructing Transformer Fashions from Scratch with PyTorch (10-day Mini-Course)
  • NBA High Shot kicks off 2025-26 season with star partnerships, participant autographs, and blockchain enhancements
  • Scaling Recommender Transformers to a Billion Parameters
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy

© 2024 Newsaiworld.com. All rights reserved.

No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us

© 2024 Newsaiworld.com. All rights reserved.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?