annotate Problems/private/pwsmoothfield.m @ 61:42fcbcfca132

(none)
author idamnjanovic
date Tue, 15 Mar 2011 12:21:31 +0000
parents 217a33ac374e
children
rev   line source
idamnjanovic@51 1 function f = pwsmoothfield(n,var,alpha)
idamnjanovic@51 2 % PWSMOOTHFIELD(N,VAR,ALPHA)
idamnjanovic@51 3 % Generate an image of piecewise smooth filtered white noise
idamnjanovic@51 4 %
idamnjanovic@51 5 % N = sidelength of the field in pixels
idamnjanovic@51 6 % VAR = variance of original white nose
idamnjanovic@51 7 % ALPHA = fraction of FFT coefficents to keep
idamnjanovic@51 8 %
idamnjanovic@51 9 % Returns an N-by-N array
idamnjanovic@51 10 %
idamnjanovic@51 11 % This file is used with the kind permission of Stephen J. Wright
idamnjanovic@51 12 % (swright@cs.wisc.edu), and was originally included in the GPSR
idamnjanovic@51 13 % v1.0 distribution: http://www.lx.it.pt/~mtf/GPSR .
idamnjanovic@51 14
idamnjanovic@51 15 % $Id: pwsmoothfield.m 1040 2008-06-26 20:29:02Z ewout78 $
idamnjanovic@51 16
idamnjanovic@51 17 f = sqrt(var)*randn(n);
idamnjanovic@51 18 F = fft2(f);
idamnjanovic@51 19 a = ceil(n*alpha/2);
idamnjanovic@51 20 b = fix(n*(1-alpha));
idamnjanovic@51 21 F(a+1:a+b,:) = 0;
idamnjanovic@51 22 F(:,a+1:a+b) = 0;
idamnjanovic@51 23 f = real(ifft2(F));
idamnjanovic@51 24
idamnjanovic@51 25 for i = 1:n
idamnjanovic@51 26 for j = 1:n
idamnjanovic@51 27 if (j/n >= 15*(i/n - 0.5)^3 + 0.4)
idamnjanovic@51 28 f(i,j) = f(i,j) + sqrt(var);
idamnjanovic@51 29 end
idamnjanovic@51 30 end
idamnjanovic@51 31 end
idamnjanovic@51 32