问题是您希望噪声具有某种特征。曲线上有很多样本,并且您希望它保持“连接”。您想要相当平滑的结果,并且希望曲线保持闭合。因此,按顺序:随机游走噪声将使点保持连接。低通滤波噪声将使曲线保持平滑。并将噪声端点固定为零(平滑)以确保闭合结果。下面是一些代码,可生成 16 种不同类型的噪声 (4x4),改变总体规模和总体过滤量。您必须根据数据的“采样率”和形状的整体比例来调整这两个选择。
% Generate sample data
[x,y] = pol2cart(0:0.01:2*pi, 1);
% Pick a set of 4 noise scale, and noise filter values
scales = [.01 .05 .1 .5];
filterstrength = [.1 .5 .9 .98];
% Plot a 4x4 grid, picking a different type of noise for each one
for i=1:4
for j=1:4
scale = scales(i);
f = filterstrength(j);
% Generate noise for x and y, by filtering a 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))));
% We want a closed polygon, so "detrend" the result so that
% the last point is the same as the 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 the noise
plot(x+nx,y+ny);
end
end
其他你可以改变的事情:你对过滤器形状有几乎无限的选择,这将影响变形的风格。