modulate.m
上传用户:zhongmeidz
上传日期:2013-06-24
资源大小:177k
文件大小:1k
源码类别:

matlab例程

开发平台:

Matlab

  1. function y = modulate(x,b,e, s2,s4,s16,s64,s256)
  2. % function y = modulate(x,b,e, s2,s4,s16,s64,s256)
  3. %
  4. %    y - modulated output, in the form of a row vector
  5. %    x - a vector of input bits, for all the subcarriers (row vector)
  6. %    b - subcarrier bit allocation (64 elements in this matrix, each one
  7. %        corresponding to the number of bits to be allocated to the subcarrier
  8. %        having the same index)
  9. %    e - subcarrier energy allocation (64 elements in this matrix, each one
  10. %        corresponding to the energy to be allocated to the subcarrier
  11. %        having the same index)
  12. %    s_ - the encoder for a given constellation size
  13. y=[];
  14. b2 = zeros(1,length(b));
  15. b2(1) = 1;
  16. for i = 1:length(b)
  17.     b2(i+1) = b(i) + b2(i);
  18. end
  19. for i = 1:length(b)
  20.     switch b(i)
  21.     case {1}
  22.         y = [y s2(x(b2(i))+1)*sqrt(e(i))];
  23.     case {2}
  24.         y = [y s4(x(b2(i):(b2(i+1)-1))*[2;1]+1)*sqrt(e(i))];
  25.     case {4}
  26.         y = [y s16(x(b2(i):(b2(i+1)-1))*[8;4;2;1]+1)*sqrt(e(i))];
  27.     case {6}
  28.         y = [y s64(x(b2(i):(b2(i+1)-1))*[32;16;8;4;2;1]+1)*sqrt(e(i))];
  29.     case {8}
  30.         y = [y s256(x(b2(i):(b2(i+1)-1))*[128;64;32;16;8;4;2;1]+1)*sqrt(e(i))];
  31.     otherwise
  32.         % must be zero bits allocated
  33.         y = [y 0];
  34.     end
  35. end