Question

I'd like to generate a 2D image of arbitrary size containing randomly generated pink noise. Wikipedia suggests that the 2D generalization of pink noise will have energy that falls off as 1/f^2. I found some code on the MATLAB File Exchange that computes a 1D pink noise vector. But I don't know how to properly generalize it to two dimensions -- I'm not very familiar with the fft, and my naive attempt below produces complex vectors when I compute the ifft.

function pink = pinkNoiseImage(nrow,ncol)

rnrow = 2.^(ceil(log2(nrow)));
rncol = 2.^(ceil(log2(ncol)));
r = randn(rnrow,rncol);
rf = fft(r);
rnup = rnrow/2+1;
cnup = rncol/2+1;
frf = kron(1./sqrt(1:cnup),1./sqrt(1:rnup)');

rf(1:rnup,1:cnup) = rf(1:rnup,1:cnup).*frf;
rf(rnup+1:rnrow,1:cnup) = real(frf(rnrow/2:-1:2,1:cnup))-1i*imag(frf(rnrow/2:-1:2,1:cnup));
rf(1:rnup,cnup+1:rncol) = real(frf(1:rnup,rncol/2:-1:2))-1i*imag(frf(1:rnup,rncol/2:-1:2));
rf(rnup+1:rnrow,cnup+1:rncol) = real(frf(rnrow/2:-1:2,rncol/2:-1:2))-1i*imag(frf(rnrow/2:-1:2,rncol/2:-1:2));

pink = ifft(rf);

How can I generate a 2D matrix containing pink noise?

Was it helpful?

Solution

First, don't always believe what Wikipedia tells you. Or, read carefully, because the definition of Pink noise is not one to one for 2D. Second, you can use the following FEX file to generate 1/f^beta spatial noise, with a normal error distribution. Read more in the documentation of that file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top