1

I am trying to generate a set of k, random, unit, complex vectors with n components in matlab.

I understand that there can be some issues with making sure the resulting vectors are isotropic. Would something like the following work?

vectors=exp(2i*pi*rand(k,n)).*randn(k,n);
for i=1:k
    vectors(i,:)=vectors(i,:)/norm(vectors(i,:);
end

Thanks for your help,

Stan

Stan
  • 113
  • 1
  • 3
  • 2
    see this answer on how "A random normal distribution of coordinates gives you a uniform distribution of directions." - http://stackoverflow.com/questions/9750908/how-to-generate-a-unit-vector-pointing-in-a-random-direction-with-isotropic-dist – marsei Sep 18 '13 at 16:39

1 Answers1

5

That should be fine. The key is that multidimensional normal random variables are already spherically symmetric (isotropic). The random angle, though, seems a little clunky. I would just use more randn:

vectors = complex(randn(k,n), randn(k,n));

Then continue with the normalization step. Here's a vectorized version of the normalization:

vectors = bsxfun(@rdivide, vectors, sqrt(sum(vectors.*conj(vectors), 2)));
Peter
  • 14,559
  • 35
  • 55
  • but this would not give a uniform distribution in the angle whereas the OPs would? – Buck Thorn Sep 18 '13 at 16:38
  • 2
    Yes, it would. Multidimensional gaussian is isotropic. Try it: `hist(angle(complex(randn(1000000,1), randn(1000000,1))));` If you use rand instead of randn, you're exactly right. – Peter Sep 18 '13 at 16:41
  • Dear Peter, the sum is in the wrong direction: X = complex(randn(D, N), randn(D, N)); X = bsxfun(@rdivide, X, sqrt(sum(X .* conj(X), 1))); – Lukas Feb 27 '15 at 13:37
  • The sum can be in whatever direction you want it. I wrote `sum(..., 2)` to match the conventions preferred by the OP. If you want column vectors instead of row vectors, then by all means normalize over the columns instead by summing along the first dimension. – Peter Feb 27 '15 at 14:05