Commit f6058b114fb0ced4708272ba0b4e44bbecfa3a45

Authored by Yujen Ku
1 parent 7573b824bb
Exists in master

mapping.m (same as Hw1 OFDM code)

Showing 1 changed file with 35 additions and 0 deletions Side-by-side Diff

  1 +function [map_out]=mapping(data,mode,scale)
  2 +
  3 +% mode : Modulation order in power of 2 (1/2/4/6 = BSPK/QPSK/16-QAM/64-QAM)
  4 +% scale : scaling up or down the modulation, default value = 1
  5 +
  6 +input_seq = data;
  7 +
  8 +switch mode
  9 + case 1
  10 + b=scale*[1 -1];
  11 + case 2
  12 + b=scale*[1+1i -1+1i 1-1i -1-1i];
  13 + case 4
  14 + b=scale*[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];
  15 + case 6
  16 + b=scale*[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];
  17 + otherwise
  18 + error('wrong choice');
  19 +end
  20 +
  21 +count=1;
  22 +map_out = zeros(1,ceil(length(input_seq)/mode));
  23 +
  24 +for i=1:(ceil(length(input_seq)/mode))
  25 + temp=0;
  26 + for j=1:mode
  27 + temp=bitor(temp,bitshift(input_seq(count),(j-1)));
  28 + count=count+1;
  29 + if(count>length(input_seq))
  30 + break;
  31 + end
  32 + end
  33 + map_out(i)=b(temp+1);
  34 +end