Help - How to plot a graph with multiple colors?

조회 수: 3(최근 30일)
adriane duarte
adriane duarte 2021년 5월 31일
댓글: Walter Roberson 2021년 6월 1일
I'm trying to plot a graph where I can observe the points of the equation (in the sequence of bits 0 and 1). Each set will have a marker and a different color.
I am using the following code:
L = 1e4; %number of bits
SNRdB = -10:2:20;
SNR = 10.^(SNRdB/10);
alpha = 0.3;
cor = 'rbmkg'; % indicate bits an and bn
ident= '*xv+>'; % indicate bits dI and dQ
for count=1:length(SNRdB)
an = 2*randi([ 0 1 ],1,L)-1;
bn = 2*randi([ 0 1 ],1,L)-1;
dI = 2*randi([ 0 1 ],1,L)-1;
dQ = 2*randi([ 0 1 ],1,L)-1;
sn = an .* ( sqrt(1-alpha) + sqrt(alpha) .* dI ) + 1i .* bn .* ( sqrt(1-alpha) + sqrt(alpha) .* dQ );
end
k=1;
str=[];
figure;
for k1 = 1:4
for k2 = 1:4
str =[ str; num2str(max(an(k1),0)) num2str(max(bn(k1),0)) num2str(max(dI(k2),0)) num2str(max(dQ(k2),0))];
scatter(real(sn(k)),imag(sn(k)),[cor(k1) ident(k2)]);
hold on
k = k+1;
end
end
title('symbols')
legend(str);
axis([-2 3 -2 2])
I'm having as answer the following graph:
I don't know where I'm going wrong.
I would like to obtain a graph with all the combinations and respective colors as follows:

답변(2개)

Walter Roberson
Walter Roberson 2021년 5월 31일
for k1 = 1:4
for k2 = 1:4
str =[ str; num2str(max(an(k1),0)) num2str(max(bn(k1),0)) num2str(max(dI(k2),0)) num2str(max(dQ(k2),0))];
scatter(real(sn(k)),imag(sn(k)),[cor(k1) ident(k2)]);
hold on
k = k+1;
end
end
You are only plotting from the first 4 * 4 = 16 elements of sn, but the first 16 elements of sn might happen to not represent all of the bit combinations. Your sn is length 10000
You can instead do something like
U = uniquetol([real(sn).', imag(sn).'], 'byrows', true);
Ui = complex(U(:,1), U(:,2));
now Ui will be the (16) unique complex values, and you can plot them. However, you will need to figure out which one corresponds to which pattern of bits.
  댓글 수: 6
Walter Roberson
Walter Roberson 2021년 6월 1일
[wasfound, idx] = ismembertol([real(Ui(:)), imag(Ui(:))], [real(Sn(:)), imag(Sn(:))], 'byrows', true);

댓글을 달려면 로그인하십시오.


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 31일
Hi,
Here are corrected part of your script:
...
for k1 = 1:4
for k2 = 1:4
str =[ str; num2str(max(an(k1),0)) num2str(max(bn(k1),0)) num2str(max(dI(k2),0)) num2str(max(dQ(k2),0))];
scatter(real(sn(k1)),imag(sn(k2)),[cor(k1) ident(k2)]);
hold on
end
end
...
Good luck.
  댓글 수: 1
adriane duarte
adriane duarte 2021년 5월 31일
hi!!
I tested it that way but it still didn't work. Missing a combination.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by