DSPRelated.com
Forums

Gray mapped 8PSK

Started by oa00...@surrey.ac.uk March 15, 2011
Does anyone know of a way to reduce this code and still achieve gray mapping, because when M (in MPSK) gets higher, gray mapping using the method I used below will be too lenghty. Thanks

clear all
clc
M=8;
N00;
data=rand(1,N)>0.5;
Mpsk_symbol=zeros(1,length(data)/3);
for n=1:length(data)/3
p1a(3*n-2);
p2a(3*n-1);
p3a(3*n);
if p1==0 && p2==0 && p3==1
Mpsk_symbol(n)=exp(0);% 001-->0
end
if p1==0 && p2==0 && p3==0
Mpsk_symbol(n)=exp(1i*pi/4);% 000-->45
end
if p1==1 && p2==0 && p3==0
Mpsk_symbol(n)=exp(1i*2*pi/4);% 100-->90
end
if p1==1 && p2==1 && p3==0
Mpsk_symbol(n)=exp(1i*3*pi/4);% 110-->135
end
if p1==0 && p2==1 && p3==0
Mpsk_symbol(n)=exp(1i*4*pi/4);% 010-->180
end
if p1==0 && p2==1 && p3==1
Mpsk_symbol(n)=exp(1i*5*pi/4);% 011-->225
end
if p1==1 && p2==1 && p3==1
Mpsk_symbol(n)=exp(1i*6*pi/4);% 111-->270
end
if p1==1 && p2==0 && p3==1
Mpsk_symbol(n)=exp(1i*7*pi/4);% 101-->315
end

end
MSym=Mpsk_symbol;
plot(MSym,'o'),grid on
axis([-2 2 -2 2])