ND Convolution on a mesh

2 次查看(过去 30 天)
Ifechi Ejidike
Ifechi Ejidike 2024-1-18
Hi,
I'm doing some FE modelling on MATLAB and comparing to results from a monte carlo simulation. As part of that I need to translate the results of the simulation correctly by doing a 4D convolution.
Currently I have my a struct called mesh that defines my working space. mesh.node is an N x 3 array of the x,y,z positions of each node N and I have my values at each node in a N x T array where T corresponds to each time bin.
I'm looking for an efficient way to convolve my node values with some other simalry structured values.
If we call the value at each node a response function g(x,y,z,t) and my other source function f(x,y,z,t) is there some way I could compute
without having to rearrange all my values into a 4D data-cube?
Thanks!

回答(1 个)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU 2024-1-24
Hi Ifechi,
To perform a 4D convolution of your node values with another similarly structured set of values without rearranging them into a 4D data-cube, you can use the following MATLAB example snippet:
% Define the size of the grid
N = 10; % Grid dimensions (N x N x N)
T = 1; % Number of time points
% Generate random test values for g and f
g_values = rand(N, N, N, T);
f_values = rand(N, N, N, T);
% Assuming g_values and f_values are N x T arrays for g(x,y,z,t) and f(x,y,z,t)
% Fourier transform of the response and source functions
G_fft = fftn(g_values);
F_fft = fftn(f_values);
% Element-wise multiplication in the Fourier domain (convolution theorem)
convolved_fft = G_fft .* F_fft;
% Inverse Fourier transform to get the convolved data
convolved_data = ifftn(convolved_fft);
% Display the size of the convolved data to verify
disp(size(convolved_data));
This code applies the convolution theorem using the Fast Fourier Transform (FFT) to efficiently compute the convolution across all dimensions. The “fftn” and “ifftn” functions handle the multi-dimensional aspect of your data.
Refer to the following documentation for more details:
  1. fftn: https://www.mathworks.com/help/matlab/ref/fftn.html.
  2. ifftn: https://www.mathworks.com/help/matlab/ref/ifftn.html.
Alternatively, if your mesh is sparse or you prefer not to use FFT, you can:
  1. Convolve your data iteratively over each dimension, one at a time.
  2. If your data is sparse, leverage MATLAB's sparse data structures to save memory and computation time.
  3. Create a custom convolution function tailored to your data structure, which could be more efficient for your specific application.
I hope this helps with your finite element (FE) modelling and Monte Carlo simulation comparison in MATLAB.
  1 个评论
Ifechi Ejidike
Ifechi Ejidike 2024-1-24
Thanks for this but it doesn't do what I was hoping. Your code assumes the data is in a 4D data cube in the first instance but my mesh is not necassarily cubic. Also with the product of two FFTs only gives the circular convolution, the arrays need to be padded and cropped on output to generate the linear convolution which I need.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Fourier Analysis and Filtering 的更多信息

产品


版本

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by