idamnjanovic@60: function f = pwsmoothfield(n,var,alpha) idamnjanovic@60: % PWSMOOTHFIELD(N,VAR,ALPHA) idamnjanovic@60: % Generate an image of piecewise smooth filtered white noise idamnjanovic@60: % idamnjanovic@60: % N = sidelength of the field in pixels idamnjanovic@60: % VAR = variance of original white nose idamnjanovic@60: % ALPHA = fraction of FFT coefficents to keep idamnjanovic@60: % idamnjanovic@60: % Returns an N-by-N array idamnjanovic@60: % idamnjanovic@60: % This file is used with the kind permission of Stephen J. Wright idamnjanovic@60: % (swright@cs.wisc.edu), and was originally included in the GPSR idamnjanovic@60: % v1.0 distribution: http://www.lx.it.pt/~mtf/GPSR . idamnjanovic@60: idamnjanovic@60: % $Id: pwsmoothfield.m 1040 2008-06-26 20:29:02Z ewout78 $ idamnjanovic@60: idamnjanovic@60: f = sqrt(var)*randn(n); idamnjanovic@60: F = fft2(f); idamnjanovic@60: a = ceil(n*alpha/2); idamnjanovic@60: b = fix(n*(1-alpha)); idamnjanovic@60: F(a+1:a+b,:) = 0; idamnjanovic@60: F(:,a+1:a+b) = 0; idamnjanovic@60: f = real(ifft2(F)); idamnjanovic@60: idamnjanovic@60: for i = 1:n idamnjanovic@60: for j = 1:n idamnjanovic@60: if (j/n >= 15*(i/n - 0.5)^3 + 0.4) idamnjanovic@60: f(i,j) = f(i,j) + sqrt(var); idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: end idamnjanovic@60: