OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to calculate continuous Fourier inverse numerically with numpy?

  • Thread starter Thread starter Peyman
  • Start date Start date
P

Peyman

Guest
I'm trying to implement a function that calculates the inverse Fourier transform of a continuous function F(ω) to obtain f(x).

My input function is continuous (you can assume it is a lambda function) so I have to approximate it discretely using discrete sampling. Here's my current implementation:

Code:
import numpy as np

def fourier_inverse(f, n, omega_max):
    """
    :param f: The function to be transformed
    :param n: Number of samples
    :param omega_max: The max frequency we want to be samples
    """
    omega_range = np.linspace(-omega_max, omega_max, n)
    f_values = f(omega_range, sigma, alpha)
    inverse_f = np.fft.ifftshift(np.fft.ifft(np.fft.fftshift(f_values)))
    return inverse_f
If more explanation is needed for the code: f is the function, omega_max is the range of omega I want to sample from, the bigger the better the quality must be, and n is the number of samples taken from -omega to +omaga, bigger n means better quality.

However, I have two main concerns:

  1. The x-axis of the result ranges from 0 to n, which doesn't seem correct. I don't know how to approach it.
  2. I'm unsure if the overall approach is correct, particularly regarding the sampling and normalization.

Any help or guidance would be greatly appreciated. Thank you!
<p>I'm trying to implement a function that calculates the inverse Fourier transform of a continuous function <code>F(ω)</code> to obtain <code>f(x)</code>.</p>
<p>My input function is continuous (you can assume it is a lambda function) so I have to approximate it discretely using discrete sampling. Here's my current implementation:</p>
<pre><code>import numpy as np

def fourier_inverse(f, n, omega_max):
"""
:param f: The function to be transformed
:param n: Number of samples
:param omega_max: The max frequency we want to be samples
"""
omega_range = np.linspace(-omega_max, omega_max, n)
f_values = f(omega_range, sigma, alpha)
inverse_f = np.fft.ifftshift(np.fft.ifft(np.fft.fftshift(f_values)))
return inverse_f
</code></pre>
<blockquote>
<p><em>If more explanation is needed for the code</em>: f is the function,
omega_max is the range of omega I want to sample from, the bigger the
better the quality must be, and n is the number of samples taken from
-omega to +omaga, bigger n means better quality.</p>
</blockquote>
<p>However, I have two main concerns:</p>
<ol>
<li>The x-axis of the result ranges from 0 to n, which doesn't seem
correct. I don't know how to approach it.</li>
<li>I'm unsure if the overall approach is correct, particularly
regarding the sampling and normalization.</li>
</ol>
<p>Any help or guidance would be greatly appreciated. Thank you!</p>
 

Latest posts

Top