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