Filter löschen
Filter löschen

ND Convolution on a mesh

6 Ansichten (letzte 30 Tage)
Ifechi Ejidike
Ifechi Ejidike am 18 Jan. 2024
Kommentiert: Ifechi Ejidike am 24 Jan. 2024
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!

Antworten (1)

UDAYA PEDDIRAJU
UDAYA PEDDIRAJU am 24 Jan. 2024
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 Kommentar
Ifechi Ejidike
Ifechi Ejidike am 24 Jan. 2024
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Help Center und File Exchange

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by