# Adding noise in frequency domain while solving an SPDE

**URL:** <https://discourse.julialang.org/t/adding-noise-in-frequency-domain-while-solving-an-spde/59240>\
**Category:** Numerics\
**Tags:** question, fftw, diffeq, dsp\
**Created:** [April 13, 2021, 10:57pm UTC](https://discourse.julialang.org/t/adding-noise-in-frequency-domain-while-solving-an-spde/59240 "2021-04-13T22:57:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiago](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tiago/32/22567_2.png) [@tiago](https://discourse.julialang.org/u/tiago)\
**Post date:** [April 13, 2021, 10:57pm UTC](https://discourse.julialang.org/t/adding-noise-in-frequency-domain-while-solving-an-spde/59240/1 "2021-04-13T22:57:41Z")

</div>

Hello,

I’m implementing a numerical solver to a certain kind of a 2D stochastic PDE using Fourier Transforms.  
So, this solver is a Galerkin type method, which means that choosing the right basis functions I can apply Fourier Transforms to compute the solution.

Long story short, applying the explicit Euler-Maruyama scheme to my SPDE and discretising the domain with N^2 nodes, the discrete version of the Fourier coefficients of `V` at time step `t_i+1` is given by:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/d/adf16ad432140f6a73c0f8a269a4185447c8b6cd.png)  
where the hat terms corresponds to the fourier coefficients of the equation, `eps` is the level of additive noise, `W` is a complex random matrix with distribution N(0,1) and `\lambda` is a spatial correlation matrix.  
**Notice** that the noise is being added in the **frequency** domain!

However, when comparing results with other numerical methods the effect of the noise is not the same, actually I have to scale up `eps` by a factor.

I’m using the `fftw.jl` package to compute the Fourier Transforms. Thus, it’s known that `fft(V) = N^2*v_mn`, i.e. the function `fft` gives us the fourier coefficients of a certain vector (matrix) scaled by a factor of `N` (`N^2`).  
So, the stochastic term of my expression showed above has not the same magnitude as the rest of the coefficients. Am I right?

To overcome this issue, I simply have to multiply `eps` by `N^2`, is this easy? Or adding noise in the frequency domain is more complicated than this?

Actually, an experimental evidence that the number of nodes influences the noise effect in the solution, is if I increase `N` I’ll also have to increase `eps` to continue to have similar behaviours than with less nodes.

Sorry for my question, but I’m a bit newbie in the Fourier world.

Thank you!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [April 14, 2021, 6:07am UTC](https://discourse.julialang.org/t/adding-noise-in-frequency-domain-while-solving-an-spde/59240/2 "2021-04-14T06:07:10Z")

</div>

One other factor to consider is whether the noise being added is band-limited or not, i.e., does it extend from 0 to a fraction of Nyquist or does it go up to Nyquist. This would require a normalization factor to preserve the meaning of epsilon in terms of noise variance.

More familiar with noise added in the physical data domain but, just in case, for white noise added in the frequency domain, in addition to the constant magnitude epsilon, one needs to randomize the phase - see [stack overflow post here](https://stackoverflow.com/a/41864529/14071775).

---

<div class="post-metadata">

**Author:** ![josuagrw](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/josuagrw/32/1015_2.png) [@josuagrw](https://discourse.julialang.org/u/josuagrw)\
**Post date:** [April 14, 2021, 6:41am UTC](https://discourse.julialang.org/t/adding-noise-in-frequency-domain-while-solving-an-spde/59240/3 "2021-04-14T06:41:06Z")

</div>

I think you got it right: The standard `fft` / `ifft` methods only normalize on the inverse transform (the classical convention; not the quantum convention). So if you want to manipulate data in the Fourier domain you need to scale your terms accordingly with the number of points.

---

<div class="post-metadata">

**Author:** ![tiago](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tiago/32/22567_2.png) [@tiago](https://discourse.julialang.org/u/tiago)\
**Post date:** [April 14, 2021, 2:35pm UTC](https://discourse.julialang.org/t/adding-noise-in-frequency-domain-while-solving-an-spde/59240/4 "2021-04-14T14:35:45Z")

</div>

> [@rafael.guerra](#):
>
> One other factor to consider is whether the noise being added is band-limited or not, i.e., does it extend from 0 to a fraction of Nyquist or does it go up to Nyquist. This would require a normalization factor to preserve the meaning of epsilon in terms of noise variance.

Hmm, I will study what you said here with more attention. I don’t know exactly if my noise is band-limited or not, I have to check if it extends up to the Nyquist frequency.

> [@rafael.guerra](#):
>
> More familiar with noise added in the physical data domain but, just in case, for white noise added in the frequency domain, in addition to the constant magnitude epsilon, one needs to randomize the phase - see [stack overflow post here](https://stackoverflow.com/a/41864529/14071775).

Thank you for mentioning this post! Well, the noise I’m working on is additive and I think it’s white noise, since W is a matrix with complex numbers where both real and imaginary parts are generated independently by a distribution N(0,1).  
This means that I’m uniformly randomising the phase? No! Right? is being generated by a normal distribution and not by an uniform distribution.

Actually, my data is real, so one of my uncertainties was if I needed to introduce complex noise or not. If not, randomising the phase does not apply to my case.
