Why do I receive unexpected results if I use the BIN2GRAY function with the PSKMOD function in Communications Toolbox 3.1 (R14SP2)?

3 views (last 30 days)
I execute the following code using Communications Toolbox 3.1 (R14SP2):
pskdemod(pskmod(bin2gray(0:7,'psk',8),8),8,0,'gray')
I expect the result to be
0 1 2 3 4 5 6 7
but instead I receive
0 1 2 3 5 4 7 6

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This enhancement has been incorporated in Release 2006a (R2006a). For previous product releases, read below for any possible workarounds:
The symbol order for the PSKMOD function must be set to 'gray' if you want to use a Gray constellation ordering. If the symbol order option is not set to 'gray', the input data is directly mapped to the natural binary-coded ordering using the following modulation formula:
theta = 2*pi*x/M;
y = exp(j*(theta + ini_phase));
where, x is the input data and M is the modulation order.
If you wish to perform Gray encoding with the PSKMOD function, use the following syntax:
x = 0:7;
pskmod(x,8,0,'gray');
This will ensure that 'x' is first mapped to a Gray constellation before being modulated.
The following code further illustrates the correct method for using the PSKMOD function with symbol ordering set to 'gray':
y = [0:7];
xmap = pskmod(y,8,[]);
k=log2(8);
scatterplot(xmap);
h = get(gca,'Children');
hline = findobj(h,'type','line');
set(hline,'MarkerFaceColor','auto');
hold on;
for jj=1:length(xmap)
text(real(xmap(jj))-0.15,imag(xmap(jj))+0.15,dec2base(jj-1,2,3));
end
set(gca,'yTick',(-(k+1)/4:(k+1)/4),'xTick',(-(k+1)/4:(k+1)/4),...
'XLim',[-(k+1)/2 (k+1)/2],'YLim',[-(k+1)/2 (k+1)/2],'Box','on',...
'YGrid','on', 'XGrid','on');
hold off;
title('Scatter plot 8-PSK input = [0,1,2,3,4,5,6,7]');
%%%INCORRECT RESULTS
y = bin2gray([0:7],'psk',8);
xmap = pskmod(y,8,[]);
k=log2(8);
scatterplot(xmap);
h = get(gca,'Children');
hline = findobj(h,'type','line');
set(hline,'MarkerFaceColor','auto');
hold on;
for jj=1:length(xmap)
text(real(xmap(jj))-0.15,imag(xmap(jj))+0.15,dec2base(jj-1,2,3));
end
set(gca,'yTick',(-(k+1)/4:(k+1)/4),'xTick',(-(k+1)/4:(k+1)/4),...
'XLim',[-(k+1)/2 (k+1)/2],'YLim',[-(k+1)/2 (k+1)/2],'Box','on',...
'YGrid','on', 'XGrid','on');
hold off;
title({'Scatter plot 8-PSK pre Gray encoding','input = bin2gray([0:7],''psk'',8)=[0,1,3,2,6,7,5,4]'});
%%%CORRECT RESULTS
y = [0:7];
xmap = pskmod(y,8,[],'gray');
k=log2(8);
scatterplot(xmap);
h = get(gca,'Children');
hline = findobj(h,'type','line');
set(hline,'MarkerFaceColor','auto');
hold on;
for jj=1:length(xmap)
text(real(xmap(jj))-0.15,imag(xmap(jj))+0.15,dec2base(jj-1,2,3));
end
set(gca,'yTick',(-(k+1)/4:(k+1)/4),'xTick',(-(k+1)/4:(k+1)/4),...
'XLim',[-(k+1)/2 (k+1)/2],'YLim',[-(k+1)/2 (k+1)/2],'Box','on',...
'YGrid','on', 'XGrid','on');
hold off;
title('Scatter plot 8-PSK Gray map input = [0,1,2,3,4,5,6,7]');
Figure 2 shows the incorrect results. As you can see, this is not a Gray encoded map, which is one where adjacent elements differ by more than one bit. This is a direct consequence of the input being used for calculations.
Figure 3 shows the correct results. As you can see, this is a Gray encoded map, as adjacent elements differ by only one bit.

More Answers (0)

Products


Release

R14SP2

Community Treasure Hunt

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

Start Hunting!