Hi @Jerry Guern ,
After going through documentation provided at the link below,
https://www.mathworks.com/help/matlab/ref/double.nufftn.html
Let me break down the steps required and clarify the misunderstandings:
The nufftn( )function computes the NUDFT based on provided sample points and optionally, query points. Your goal is to convert your scattered samples into a structured grid, which requires careful setup of both the input data and the target grid. You have 100 random sample points (x, y) and corresponding values v. Make sure that x and y are properly formatted as matrices or vectors that correspond to the shape of your input data. The vector v should be a column vector of size 100, containing the values at each sample point. So, you need to specify the sample points correctly when calling nufftn( ). Instead of passing [x y], you should provide a cell array where each dimension's sample points are specified separately. For example:
t = {x, y}; % Cell array containing x and y as separate entries
To get a grid output, you need to define query points that correspond to the desired grid structure. For a 10x10 grid, create evenly spaced points within the range of your original data.For instance:
[Xq, Yq] = meshgrid(linspace(0, 1, 10), linspace(0, 1, 10)); % Create query
points
f = {Xq(:), Yq(:)}; % Reshape them into vectors for nufftn
At this point, you can call nufftn() using both your sample points and your query points:
c = nufftn(v, t, f); % Compute NUDFT at query points
This will give you frequency coefficients at your specified grid locations. Since you will receive coefficients in an array format corresponding to your query points, you may not need to reshape it into a square grid directly unless required for further processing. If you want to visualize it as a grid or perform an inverse transform (like in your original code), ensure that you handle dimensions appropriately. The resulting variable c will contain your interpolated values at the specified grid points. If you want to visualize this output or compare it with expected Gaussian values:
t = reshape(c, [10, 10]); % Reshape if necessary for visualization
surf(Xq, Yq, t); % Visualize using surface plot
The expectation that the output resembles Gaussian values is valid; however, remember that interpolation will depend heavily on how well your scattered samples represent the underlying function across the defined domain.
Hope this helps.
If further issues arise or if additional clarifications are needed on specific aspects of this process, feel free to ask!