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
8 votes
Accepted

Taking derivative using FFT

I believe this stems from the fact that your function $f(x) = x^2$ does not have continuous derivatives once it is extended periodically like $$\tilde{f}(x) = f(x \ \mathrm{mod} \ 12 -6),$$ which ...
whpowell96's user avatar
  • 2,054
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
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
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
6 votes
Accepted

Von Neumann stability analysis with a constant term

From your link, consider the definition of the round off error and the statement "Since the exact solution must satisfy the discretized equation exactly, the error must also satisfy the discretized ...
origimbo's user avatar
  • 2,229
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

Can this finite difference dispersion be eliminated somehow?

It isn't the spike that's causing the dispersion. The scheme you use has a dispersion relationship whereby waves of different frequency travel at different speeds. Every numerical scheme has such a ...
Wolfgang Bangerth's user avatar
5 votes
Accepted

Fourier characteristics of repeated numerical derivative

Regarding point 1: generally, applying a discretized derivative (stencil) twice is not equivalent to applying an equivalent (i.e. same number of points) stencil for the second derivative. Example in ...
v-joe's user avatar
  • 211
5 votes
Accepted

MATLAB FFT Differentiation

1) You have misinterpreted the order the fft2 output elements are stored. This is a very common mistake, since it is very easy to get confused. Thankfully, there is an easy way to avoid such bugs. ...
zap's user avatar
  • 220
5 votes
Accepted

Does this Algorithm (probably Fourier like) Exist for 2D Shapes?

You can write a curve as a parametric equation ($x(t)$, $y(t)$) for a range say $0 < t < 1$. Then you can have a Fourier decomposition of both $x(t)$ and $y(t)$. A rectangle can be written as ...
Sarvottamananda's user avatar
5 votes

Solving numerically the 1D Kuramoto-Sivashinsky Equation using spectral methods

Indeed the problem was that you were trying to calculate your nonlinear term incorrectly and you forgot that: $$\mathcal{F}[(f(x))^{2}] \neq (\mathcal{F}[f(x)])^{2}$$ I changed your code to this: <...
Mithridates the Great'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
  • 5,554
4 votes

Convolution of two real functions using discrete Fourier transform (FFT): zero-padding and normalization

You want to calculate $$c(t)=\int_{-6}^6dx f(x)g(t-x)$$. Your functions are not periodic, but you pad them with zeros so that assuming them to be repeated periodically does not mess up the calculation ...
Gustav's user avatar
  • 141
4 votes

Rudin lecture -- if f(x) is not integrable on some interval, does it not have a Fourier Series expansion on that interval?

The point is to guarantee that the Fourier coefficients exist, not to make really fine distinctions about what might happen if the guarantee is violated. Furthermore, you would be hard pressed to find ...
Kirill's user avatar
  • 11.4k
4 votes

Generate high n quantum harmonic oscillator states numerically

I did some more investigating about the accuracy of the standard recurrence relation method vs. the newer Bunck algorithm. It seems that in fact the Bunck algorithm is generally more accurate for all $...
vibe's user avatar
  • 1,048
3 votes

Error propagation through an FFT

Assembled from comments of @AlexE: The Fourier transform is linear, so the error in the Fourier domain is the Fourier transform of the error in the spatial (original) domain. So, if $\sigma$ is ...
3 votes

How do I take the FFT of unevenly spaced data?

Addition to the accepted answer. Here is a link to an open source implementation of Greengard's and Lee's method: https://finufft.readthedocs.io/en/latest/ It has wrappers to C, fortran, MATLAB, ...
Raibyo's user avatar
  • 219
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
2 votes

How do I solve Laplace's equation in 2D using spectral methods?

So many options! This can be solved analytically using separation of variables. So that's good. Gives us something to check against, make sure that we are doing this right, and a good way of checking ...
PGnome's user avatar
  • 211
2 votes

Order of MATLAB FFT frequencies

Your question concerning wavenumber 'replacement' is rather tricky. In general, wavenumber modification of this sort is not intended to save flops, as some have suggested here, but instead designed to ...
Stuart Hilton'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

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
  • 725
2 votes

nodal lines of wave-function $\psi(x,y) = \sin 12x \sin y + (1 + \epsilon) \sin x \sin 12y$

Source [61] is the book Methods of Mathematical Physics Vol 1 by Courant and Hilbert. The preface is signed R. Courant, New Rochelle, New York, 1953 -- and in the preface we find the original German ...
john mangual's user avatar
2 votes

Rudin lecture -- if f(x) is not integrable on some interval, does it not have a Fourier Series expansion on that interval?

Applying Cauchy-Schwartz inequaility, we have: $$\begin{aligned} \left(\int_{0}^{\pi}f(x)\cos{(x)}\,dx \right)^2&\leq \left(\int_{0}^{\pi}|f(x)\cos{(x)}|\,dx \right)^2\\ &\leq \int_{0}^{\pi}f(...
HBR's user avatar
  • 1,628
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,627
2 votes

Demagnetizing field using scalar potential method

I think I see the confusion. Equation 14 of the cited publication indicates that $S_z$ is a scalar field and not a matrix. The i,j, and k components that appear in $S_z$ definition at equation 17 ...
mathew gunther's user avatar
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
2 votes

Galerkin method for heat equation

Inspired from this Computational Science SE post: Transform your problem from one with inhomogeneous BC to homogeneous BC. This is done by substracting any function $B(x,t)$ with the right ...
QuantumApple's user avatar

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