如何定义3维的功率谱?

问题描述

我正在尝试将一些现有的matlab代码从2维修改为3维,并运行到概念块中。原始脚本通过在功率谱和随机噪声乘积上运行ifft(3),从2d随机噪声生成分形。为了定义功率谱,我必须定义U,V和W维度的频率。

我对W维频率相对于U和V的模样有所了解。显然,它们不只是U或V的转置。在开头和结尾处包括一些额外的代码是否有助于澄清问题。 var powerspectrum当前返回2d矩阵,应该为3d。谢谢!

beta = -2;
imsize = [sidelength,sidelength,sidelength]; %length of sides of image in pixels;

% Generate the grid of frequencies. u is the set of frequencies along the first dimension
u = [(0:floor(imsize(1)/2)) -(ceil(imsize(1)/2)-1:-1:1)]'/imsize(1); % First quadrant are positive frequencies.  Zero frequency is at u(1,1).
u = repmat(u,1,imsize(2)); % Reproduce these frequencies along ever row.
v = [(0:floor(imsize(2)/2)) -(ceil(imsize(2)/2)-1:-1:1)]/imsize(2); % v is the set of frequencies along the second dimension.  For a square region it will be the transpose of u.
v = repmat(v,imsize(1),1); % Reproduce these frequencies along ever column.
w = [(0:floor(imsize(3)/2)) -(ceil(imsize(3)/2)-1:-1:1)]/imsize(3); % W is the set of frequencies along the *third* dimension.
w = repmat(w,imsize(3),1); % Reproduce these frequencies along every PAGE.

powerspectrum = (u.^2 + v.^2 + w.^2).^(beta/2); % Generate the power spectrum 
phases = randn(imsize); % Generate a grid of random phase shifts
complexpattern = ifftn(powerspectrum.^0.5 .* (cos(2*pi*phases)+1i*sin(2*pi*phases))); % Inverse Fourier transform to obtain the the spatial pattern

解决方法

您可以reshape repmatuv代替w[sidelength 1 1][1 sidelength 1]和{{ 1}}数组,并让implicit expansion做其工作并创建一个[1 1 sidelength]数组:

[sidelength sidelength sidelength]