gpt4 book ai didi

matlab - 如何定义跨 3 个维度的功率谱?

转载 作者:行者123 更新时间:2023-12-04 08:48:26 25 4
gpt4 key购买 nike

我正在尝试将一些现有的 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

最佳答案

而不是使用 repmat您可以 reshape u , vw进入 [sidelength 1 1] , [1 sidelength 1][1 1 sidelength]数组分别并让 implicit expansion 做它的工作并创建一个 [sidelength sidelength sidelength]大批:

u = [(0:floor(imsize(1)/2)) -(ceil(imsize(1)/2)-1:-1:1)]'/imsize(1);
u = reshape(u,[],1)
v = [(0:floor(imsize(2)/2)) -(ceil(imsize(2)/2)-1:-1:1)]/imsize(2);
v = reshape(v,1,[]);
w = [(0:floor(imsize(3)/2)) -(ceil(imsize(3)/2)-1:-1:1)]/imsize(3);
w = reshape(w,1,1,[]);

powerspectrum = (u.^2 + v.^2 + w.^2).^(beta/2);
phases = randn(imsize);
complexpattern = ifftn(powerspectrum.^0.5 .* (cos(2*pi*phases)+1i*sin(2*pi*phases)));

关于matlab - 如何定义跨 3 个维度的功率谱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64191811/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com