randi generating random complex numbers from 4-QAM

13 ビュー (過去 30 日間)
Jose Iglesias
Jose Iglesias 2023 年 4 月 4 日
コメント済み: the cyclist 2023 年 4 月 4 日
I am trying to generate the transmitted symbol x randomly from the set of constellation points seen below from a 4-QAM constellation diagram. This is in respect to the input-output model y = h · x + w for a total of 10^4 independent realizations. I went to the Matlab site and found the following code:
a = randi([-5,5],10,1,"like",1i)
I tweaked it to represent the points on my 4-QAM diagram as so
a = randi([-2,2],10e4,1,"like",1i)
However when I try to run it I get the following error:
Error using randi
Complex or sparse input following 'like' is not supported.
Error in Untitled (line 2)
a = randi([-2,2],10,1,"like",1i)
Perhaps I am overcomplicating this but I can use some assistance in updating my code to produce a random generation of complex numbers in respect to the constellation points on the 4-QAM diagram seen below. Thank you in advance.

採用された回答

the cyclist
the cyclist 2023 年 4 月 4 日
Your code works fine for me, and here:
a = randi([-2,2],10e4,1,"like",1i);
plot(real(a),imag(a),"o")
I'm not sure what to suggest, other than restarting MATLAB. What do you get from
which randi -all
  3 件のコメント
Walter Roberson
Walter Roberson 2023 年 4 月 4 日
I notice the user has marked R2020a; perhaps it was not supported then.
(I had no idea it was supported at all!)
the cyclist
the cyclist 2023 年 4 月 4 日
編集済み: the cyclist 2023 年 4 月 4 日
I think you are correct. I looked for this in the version history of randi, but missed it! Looks like this was introduced in R2022a.
EDIT: The Mathematics section of the release notes (for R2022a) corroborates this.

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2023 年 4 月 4 日
編集済み: the cyclist 2023 年 4 月 4 日
My other answer focused on "Why didn't this syntax work?" (and concluded that you don't have a recent enough version).
This is answer is focused "How can I do what I need?"
There are two straightforward solutions:
(1) Generate the real and imaginary parts separately, and add them. For example.
N = 11;
re = 4*randi(2,N,1) - 6;
im = 4*randi(2,N,1) - 6;
c = re + i*im
c =
2.0000 + 2.0000i -2.0000 + 2.0000i -2.0000 + 2.0000i 2.0000 - 2.0000i 2.0000 + 2.0000i -2.0000 - 2.0000i 2.0000 - 2.0000i 2.0000 + 2.0000i -2.0000 + 2.0000i -2.0000 + 2.0000i -2.0000 - 2.0000i
(2) Generate a random value from 1 to 4 (because you have 4 distinct points), and use that as an index into the complex values you want.
N = 11;
c_vals = [-2-2*i, -2+2*i, 2-2*i,2+2*i];
idx = randi(4,N,1);
c = c_vals(idx)'
c =
-2.0000 + 2.0000i 2.0000 + 2.0000i 2.0000 + 2.0000i 2.0000 - 2.0000i 2.0000 - 2.0000i -2.0000 + 2.0000i -2.0000 + 2.0000i -2.0000 - 2.0000i -2.0000 - 2.0000i 2.0000 + 2.0000i 2.0000 + 2.0000i
  2 件のコメント
Jose Iglesias
Jose Iglesias 2023 年 4 月 4 日
Thank you for your input. I ended up upgrading to R2023a and it ran the original code a = randi([-5,5],10,1,"like",1i) with no issues.
the cyclist
the cyclist 2023 年 4 月 4 日
Glad to hear you have a solution

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeTest and Measurement についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by