Help - How to plot a graph with multiple colors?
4 views (last 30 days)
Show older comments
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:
0 Comments
Answers (2)
Walter Roberson
on 31 May 2021
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 Comments
Walter Roberson
on 1 Jun 2021
[wasfound, idx] = ismembertol([real(Ui(:)), imag(Ui(:))], [real(Sn(:)), imag(Sn(:))], 'byrows', true);
Sulaymon Eshkabilov
on 31 May 2021
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!