Skip to main content
10 votes
Accepted

Computing numeric derivative via FFT - SciPy

FFT returns a complex array that has the same dimensions as the input array. The output array is ordered as follows: Element 0 contains the zero frequency component, F0. The array element F1 ...
Maxim Umansky's user avatar
10 votes

Why not use the convolution theorem for explicit timestepping?

This is a linear PDE, and so while this technique works here, it would not work for any nonlinear PDE. Often times when people are solving these equations it is to get experience with common solution ...
EMP's user avatar
  • 2,089
10 votes
Accepted

compute accurate derivatives using FFT

There is little you can do about it beyond just using more terms in the Fourier expansion. What you observe is called Gibbs phenomenon. It, in essence, says that if you have a function that is ...
Wolfgang Bangerth's user avatar
9 votes

Computing numeric derivative via FFT - SciPy

Maxim Umansky’s answer describes the storage convention of the FFT frequency components in detail, but doesn’t necessarily explain why the original code didn’t work. There are three main problems in ...
Socob's user avatar
  • 191
8 votes
Accepted

Numerically computing the advection equation

I see several issues: The DFT computed with fft puts the zero mode at the beginning of the array, and if you want to compute the derivative, it is necessary to ...
Kirill's user avatar
  • 11.4k
7 votes

DFT of $g(\omega) \exp(i C \omega^2)$. How to do it ,if uniform sampling requires too much memory?

Expanding upon my comment above, if you only need a few digits of accuracy you can probably use the method of stationary phase. We can follow the procedure on Wikipedia. We can write the transform as ...
smh's user avatar
  • 663
7 votes

Numpy FFT gives me a pulse shorter than it should be. Not sure what I am doing wrong

Running your code, it seems like your pulse looks kinda like this: (sorry for not adding units to the plots, I used the same as you, i.e. t is in fs and w in rad/fs) So, the FWHM is not correct (...
matthiaw91's user avatar
7 votes

Fourier transform by FFT : by using cubic splines to interpolate between data points, do we change the frequency content of the Fourier transform?

The frequency content of the interpolated signal is significantly influenced by the interpolation basis. If you have a band-limited function that you have adequately sampled (i.e. satisfying Nyquist ...
coolguy1000000's user avatar
6 votes

Fourier transform by FFT : by using cubic splines to interpolate between data points, do we change the frequency content of the Fourier transform?

The interpolation indeed affects the Fourier transform. @Steve already gives the correct answer in general, but I want to give you an example that helps the intuition more. Think for example that you ...
Wolfgang Bangerth's user avatar
6 votes
Accepted

How do I avoid divide-by-zero when solving the Poisson equation with Fourier transforms?

You are solving Poisson's equation: $$\nabla^2 \Phi = 4\pi G \rho.$$ Notice that if $\Phi$ is a solution, then so is $\Phi+C$ for any constant $C$. Furthermore, $C$ will have no effect on your ...
David Ketcheson's user avatar
5 votes

Why do problems arise in FFT for smaller value of df in Python?

The discrete Fourier transform for a signal of period $T$ with $N$ samples reads in its inverse or reconstruction form as $$ y(t)=\frac1{N}\sum_{k=-N/2}^{N/2}c_k e^{i2\pi k\frac{t}{T}} $$ with ...
Lutz Lehmann's user avatar
  • 6,064
5 votes

Why not use the convolution theorem for explicit timestepping?

For the linear, constant coefficient advection equation on a torus, one can simply use the exact solution. So there are no "popular" numerical methods for this problem.
David Ketcheson's user avatar
4 votes

Problem implementing convolutions exactly with the FFT

It looks to me that the FFT convolution algorithm is doing what is expected here. Remember that you work with discretized signals, and therefore, discretized convolution. There are a few ways to ...
QuantumApple's user avatar
4 votes

How to define a dimensionless Objective function for determining how peaked a curve is?

Let $f(\omega)$ be your power spectrum. Then maybe something like $$ \frac{\|f\|_{L^\infty}\|f\|_{L^0}}{\|f\|_{L^1}} = \frac{\mathrm{max}_{\omega\in\Omega} f(\omega)\cdot|\omega_{max}-\omega_{min}|}{\...
whpowell96's user avatar
  • 2,443
4 votes

Numerical solution of 2D wave equation using Fourier transform and finite differences

Correction in the expression It appears that complex iota $i$ has not been included in the exponents in the expression for the inverse Fourier transform. The correct expression is: $$ u(x,y,t) = \iint ...
G R Krishna Chand Avatar's user avatar
4 votes
Accepted

Does DCT diagonalize the FD discretisation of the Laplacian with Neumann boundary conditions?

The "issue" seems to have been that there is a discrepancy between the used transforms. The DCT transforms discussed in the linked paper are orthogonal, i.e. $U^{-1}=U^T$, where the even one ...
lightxbulb's user avatar
  • 2,122
3 votes

Obtain velocity from imposed energy spectrum using the inverse FFT

I recommend you first read answer here to find out why $\tilde{E}(\mathbf{k}) \neq \frac{1}{2} \tilde{\mathbf{u}}(\mathbf{k}) \cdot \tilde{\mathbf{u}}(\mathbf{k})$. In order to find velocity profile ...
Mithridates the Great's user avatar
3 votes

My calculated laser pulse duration is too large. Where am I wrong?

Seems like I'm a bit late, but I was just answering a similar question. The first thing here, is that you probably want to pay attention to the definition of the w-axis. The FFT-algorithm will ...
matthiaw91's user avatar
3 votes

Fourier pseudo-spectral method and numerical dissipation

The accepted answer above is very misleading and @nat-chouf has it correct. In the spirit of the original question, running a pseudo-spectral mode of isotropic turbulence, then zero-ing out $k>\...
Jeffrey J. Early's user avatar
3 votes

C++ libraries for Fast Fourier Transform in high precision

You might want to take a look at the Eigen C++ matrix class library. http://eigen.tuxfamily.org/index.php?title=Main_Page There is an FFT class in the unsupported section of the library but my ...
Bill Greene's user avatar
  • 6,064
3 votes

Why not use the convolution theorem for explicit timestepping?

Reharding the question in the comment: After discretization you get a system of the form $ \partial_t C = (M_x + M_y) C $ where $M_x$ and $M_y$ are commuting matrices obtained by discretizing the time-...
davidhigh's user avatar
  • 3,127
3 votes

Free Time Dependent Schrodinger Equation with Inhomogeneous Dirichlet boundary

The TDSE is given by $$i\partial_t|\phi(t)\rangle = \hat H |\phi(t)\rangle\,.$$ Expanding the wavefunction $|\phi \rangle $ into a set of eigenfunctions of the Hamiltonian, $$ \hat H |\psi_i\rangle = ...
davidhigh's user avatar
  • 3,127
2 votes
Accepted

MPI support for discrete Fourier transform (DFT) in Python

I think you are looking for mpi4py-fft, which is a Python package (BSD-2 licensed) with its wrappers on the serial FFTW library. From pretty extensive mpi4py documentation: Parallel FFTs are ...
Anton Menshov's user avatar
  • 8,672
2 votes
Accepted

0 Hz (quite sharp) peak in FFT and division by 0

I would need additional information about your attempt (e.g., example code) to help with your first question, but here's my input for the division-by-zero question. First, do you really need to ...
Endulum's user avatar
  • 735
2 votes

Fast(er) computation of dot product of two convolutions?

Parseval's theorem tells you that the dot product between two vectors equals the dot product of the Fourier transforms, possibly up to a constant. Consequently, you do not need to transform back the ...
Wolfgang Bangerth's user avatar
2 votes
Accepted

How to calculate efficiently and accurately the Fourier transform of a radial function in Fortran

I have tried the following code in Julia for $f(r) = exp(-r)$ with 1D FFT, which seems to be working somehow. So, could you compare your code with it and see if there is some difference of ...
roygvib's user avatar
  • 156
2 votes
Accepted

FFT of "implicitly" uniform data

Since your histogram is very sparse, your density field is approximately a sum of weighted delta functions: $$\rho(\vec r) = \sum_{j=1}^{N_{\mathrm{bins}}} w_j\, \delta(\vec r - \vec r_j)$$ where $r_j$...
Endulum's user avatar
  • 735
2 votes

Incorporating a potential barrier in a wave-packet simulation (Fourier Transform method)

The neat thing about Fourier codes is that you can achieve very high order derivatives and if you are describing physics which is about waves, then the trigonometric base functions are a good choice. ...
MPIchael's user avatar
  • 2,935
2 votes
Accepted

Power spectrum incorrectly yielding negative values

This is due to an implicit time shift, which corresponds to a phase shift, perceived here as a sign inversion. The signal you are Fourier transforming is symmetric around t=0 and this is why you ...
zap's user avatar
  • 220
2 votes

Calculating the Convolution Using DFT (FFT)

You need to pay attention that unless properly padded the Multiplication in the Frequency Domain (DFT) applies Circular Convolution while you're after Linear Convolution. For practical examples and ...
Royi's user avatar
  • 332

Only top scored, non community-wiki answers of a minimum length are eligible