I am trying to understand how to use nufft from the Matlab doc.

My goal is to compute a FFT of an image (2D) which has missing points (not sampled). I have a list x and y of coordinates of the points that ARE sampled. These lists are for the x and y coordinates, like, say for a 64x64 image: x=[1,2,3,10,11,12...],y=[1,2,8,32,32,33,...]

t = [1:10 11:2:29]';
x = t;
y = t';
z = reshape(t,[1 1 20]);
X = cos(2*pi*0.01*x) + sin(2*pi*0.02*y) + cos(2*pi*0.03*z);
Y = nufftn(X,{t,t,t});

From this example I tought I could call the nufft() function like so:


However Matlab outputs an error message:

**Error using nufftn (line 107)
The total number of sample points must match the number of elements in the first input argument.**

I do not understand this message since by definition if it is "nonuniform" I will have less sample points in each dimension of the input ?!? I do

I do see that in the example, their X has the same number of values in each dimension but the problem is that I want to give as input an image with "holes", so unless I can put in a special value for the "holes" I don't see how to input the image unless I vectorize it and remove the "missing" samples but the nufftn is supposed to be designed to nD data.

I give as input an image img with zeros at the points that are not sampled, but I do not see how I could give an image with actual "holes" since it would result in a matrix with different number of columns in each row which is impossible.

  • $\begingroup$ Sorry, my matlab does not have this nufft() function... Yet, Nonuniform does not mean missing samples (though they are related). You should still supply as many data points as there are time-stamps, to make computations. The error you get tells that the supplied data size (which an image matrix of 256 x 256 samples) does not match with the supplied time-stamps in those xx and yy arrays. So make sure that vertical and horizontal number of elements in X do match with lengths of xx and yy. $\endgroup$
    – Fat32
    Nov 11, 2020 at 22:01
  • $\begingroup$ By missing I mean w.r.t. the example I gave, i.e. I removed every second point in img. Or I could have randomly removed some samples to simulate non uniform sampling if you see what I mean? How would you supply the image?I mean its original shape is 256x256 but if i remove an arbitrary amount of samples I could reshape the matrix in any shape... how to deal with that? (I do understand that the nufft is expecting the same input size matrix as the dimensions of the samples but its not convenient for me because I would end up with ambiguity of how to rehsape img) $\endgroup$
    – SheppLogan
    Nov 11, 2020 at 22:21
  • $\begingroup$ P.s. Thanks for answering so fast and its true that nuftt was onlyIntroduced in R2020a $\endgroup$
    – SheppLogan
    Nov 11, 2020 at 22:21


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.