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