Commit fcf9ba922496363a0723b1911cee37001ebec1fc
1 parent
4163b70995
Exists in
master
edit credit
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
demapper
View file @
fcf9ba9
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 1 | 1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
% Project code file for ECE 257B SP2018 % | 2 | 2 | % Project code file for ECE 257B SP2018 % | |
% Author: Yu-Jen Ku, Xueshi Hu % | 3 | 3 | % Author: Yu-Jen Ku, Xueshi Hou % | |
% Department of Electrical and Computer Engineering, % | 4 | 4 | % Department of Electrical and Computer Engineering, % | |
% University in San Diego, California, USA % | 5 | 5 | % University in San Diego, California, USA % | |
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 6 | 6 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
7 | 7 | |||
function [map_out]=demapper(data,mode,c) | 8 | 8 | function [map_out]=demapper(data,mode,c) | |
9 | 9 | |||
m_out=data; | 10 | 10 | m_out=data; | |
% mode : Modulation order in power of 2 (1/2/4/6 = BSPK/QPSK/16-QAM/64-QAM) | 11 | 11 | % mode : Modulation order in power of 2 (1/2/4/6 = BSPK/QPSK/16-QAM/64-QAM) | |
% c = 1; | 12 | 12 | % c = 1; | |
13 | 13 | |||
switch mode | 14 | 14 | switch mode | |
case 1 | 15 | 15 | case 1 | |
b=c*[1 -1]; | 16 | 16 | b=c*[1 -1]; | |
case 2 | 17 | 17 | case 2 | |
b=c*[1+1i -1+1i 1-1i -1-1i]; | 18 | 18 | b=c*[1+1i -1+1i 1-1i -1-1i]; | |
case 4 | 19 | 19 | case 4 | |
b=c*[1+1i 1+3i 1-1i 1-3i 3+1i 3+3i 3-1i 3-3i -1+1i -1+3i -1-1i -1-3i -3+1i -3+3i -3-1i -3-3i]; | 20 | 20 | b=c*[1+1i 1+3i 1-1i 1-3i 3+1i 3+3i 3-1i 3-3i -1+1i -1+3i -1-1i -1-3i -3+1i -3+3i -3-1i -3-3i]; | |
case 6 | 21 | 21 | case 6 | |
b=c*[3+3i 3+1i 3+5i 3+7i 3-3i 3-1i 3-5i 3-7i 1+3i 1+1i 1+5i 1+7i 1-3i 1-1i 1-5i 1-7i 5+3i 5+1i 5+5i 5+7i 5-3i 5-1i 5-5i 5-7i 7+3i 7+1i 7+5i 7+7i 7-3i 7-1i 7-5i 7-7i -3+3i -3+1i -3+5i -3+7i -3-3i -3-1i -3-5i -3-7i -1+3i -1+1i -1+5i -1+7i -1-3i -1-1i -1-5i -1-7i -5+3i -5+1i -5+5i -5+7i -5-3i -5-1i -5-5i -5-7i -7+3i -7+1i -7+5i -7+7i -7-3i -7-1i -7-5i -7-7i]; | 22 | 22 | b=c*[3+3i 3+1i 3+5i 3+7i 3-3i 3-1i 3-5i 3-7i 1+3i 1+1i 1+5i 1+7i 1-3i 1-1i 1-5i 1-7i 5+3i 5+1i 5+5i 5+7i 5-3i 5-1i 5-5i 5-7i 7+3i 7+1i 7+5i 7+7i 7-3i 7-1i 7-5i 7-7i -3+3i -3+1i -3+5i -3+7i -3-3i -3-1i -3-5i -3-7i -1+3i -1+1i -1+5i -1+7i -1-3i -1-1i -1-5i -1-7i -5+3i -5+1i -5+5i -5+7i -5-3i -5-1i -5-5i -5-7i -7+3i -7+1i -7+5i -7+7i -7-3i -7-1i -7-5i -7-7i]; | |
otherwise | 23 | 23 | otherwise | |
error('wrong choice'); | 24 | 24 | error('wrong choice'); | |
end | 25 | 25 | end | |
26 | 26 | |||
temp = zeros(size(m_out)); | 27 | 27 | temp = zeros(size(m_out)); | |
28 | 28 | |||
for k=1:length(m_out) | 29 | 29 | for k=1:length(m_out) | |
z=find( (abs(b-m_out(k))).^2-min(abs((b-m_out(k))).^2)==0); | 30 | 30 | z=find( (abs(b-m_out(k))).^2-min(abs((b-m_out(k))).^2)==0); | |
if length(z)==1 | 31 | 31 | if length(z)==1 | |
temp(k)=z-1; | 32 | 32 | temp(k)=z-1; | |
else | 33 | 33 | else | |
temp(k)=z(randi(1,1,[1,length(z)]))-1; | 34 | 34 | temp(k)=z(randi(1,1,[1,length(z)]))-1; |