I want to add a noise made of harmonic functions to my 2D matrix. I thought it could be made by adding random amplitudes to modes in Fourier domain. I keep Hermitian symmetry of the matrix so that the IFFT gave me a real matrix (I iterate N/2 times over each positive and its conjugate negative frequency).

Why is the first element of the final matrix always the maximum?

Maximum at the first element

If I, however, not only add but add or subtract a random number then the maximum is placed in a random place.

Maximum at random place

I've written an example in MATLAB:

N = 16; %dimensions

x2d = ones(N); %basic 2D N*N matrix
y2d = fft2(x2d); %its FFT

%adding a random number to the spectrum paying attention to its conjugate
%part so the basic matrix remains real
upfreq = N/2;
for chn1=2:upfreq
    for chn2 = 2:upfreq % N/2+1 is skipped
          rnd = rand; %if changed to rand-0.5 it gives random maximum point
            y2d(chn1,chn2)=y2d(chn1,chn2) +rnd ;


Could you explain me why is it so?


If you use random real valued frequencies (e.g. just magnitudes), they all correspond to cosine functions, which all peak at zero (cos(0 * f) == 0). To get more random peak locations, use random complex frequencies as the input to your ifft2d, which randomizes the phase so all the peaks don't line up at zero.

|improve this answer|||||
  • $\begingroup$ Thank you, I was thinking it may be related to cumulated cosine functions, but I wasn't sure. Now I got it - if the "root" function of the transform is of the form e^(-2pi i*k)/n, then from Euler's formula for each k-mode it evaluates to cosine. $\endgroup$ – Paweł J Jan 29 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.