matlab - How to add appropriate noise to a graph -
i have matlab graph. trajectory. want add noise graph. tried adding normal distribution noise. using rand. e.g.
x1=x+a*rand(size(x));
and y.
the results attached below. not want. gives me either scatter plot, or noisy plot. illustrated below. first row did, third row want.
different graph columns stand different standard deviation (value of a).
q. how obtain third type (row) of plot?
p.s. first row when use plot(...,".",markersize,1); , second row simple vector plot.
the issue want noise have characteristic. have many samples along curve, , you'd stay "connected". you'd smooth results, , want curve stay closed. so, in order: random walk noise keep points connected. low-pass-filtered noise keep curve smooth. , fix noise endpoint 0 (smoothly) ensure closed result. here's code generates 16 different kinds of noise (4x4), varying overall scale , overall amount of filtering. you'll have adjust both of these choices based on "sample rate" of data, , overall scale of shape.
% generate sample data [x,y] = pol2cart(0:0.01:2*pi, 1); % pick set of 4 noise scale, , noise filter values scales = [.01 .05 .1 .5]; filterstrength = [.1 .5 .9 .98]; % plot 4x4 grid, picking different type of noise each 1 i=1:4 j=1:4 scale = scales(i); f = filterstrength(j); % generate noise x , y, filtering std 1 gaussian random % walk nx = filter(scale*(1-f), [1 -f], cumsum(randn(size(x)))); ny = filter(scale*(1-f), [1 -f], cumsum(randn(size(y)))); % want closed polygon, "detrend" result % last point same first point nx = nx - linspace(0,1,length(nx)).*(nx(end)-nx(1)); ny = ny - linspace(0,1,length(ny)).*(ny(end)-ny(1)); subplot(4,4,4*(i-1)+j); % add noise plot(x+nx,y+ny); end end
other things vary: have infinite choices filter shape, affect style of deformation.
Comments
Post a Comment