ip_07_10.m
上传用户:loeagle
上传日期:2013-03-02
资源大小:1236k
文件大小:1k
源码类别:

通讯编程文档

开发平台:

Matlab

  1. % MATLAB script for Illustrative Problem 10, Chapter 7.
  2. echo on
  3. K=10;N=2*K;T=100;variance=1;
  4. noise=sqrt(variance)*randn(1,N);
  5. a=rand(1,36);
  6. a=sign(a-0.5);
  7. b=reshape(a,9,4);
  8. % Generate the 16QAM points
  9. XXX=2*b(:,1)+b(:,2)+j*(2*b(:,3)+b(:,4));
  10. XX=XXX';
  11. X=[0 XX 0 conj(XX(9:-1:1))];
  12. x=zeros(1,N);
  13. for n=0:N-1
  14.   for k=0:N-1
  15.     x(n+1)=x(n+1)+1/sqrt(N)*X(k+1)*exp(j*2*pi*n*k/N);
  16.     echo off
  17.   end
  18. end
  19. echo on
  20. r=x+noise;
  21. Y=zeros(1,10);
  22. for k=1:9
  23.   for n=0:N-1
  24.     Y(1,k+1)=Y(1,k+1)+1/sqrt(N)*r(n+1)*exp(-j*2*pi*k*n/N);
  25.     echo off
  26.   end
  27. end
  28. echo on
  29. % Detect the nearest neighbor in the 16QAM constellation
  30. for k=1:9
  31.   if real(Y(1,k+1))>0
  32.     if real(Y(1,k+1))>2
  33.       Z(1,k+1)=3;
  34.     else
  35.       Z(1,k+1)=1;
  36.     end
  37.   else
  38.     if real(Y(1,k+1))<-2
  39.       Z(1,k+1)=-3;
  40.     else
  41.       Z(1,k+1)=-1;
  42.     end
  43.   end
  44.   if imag(Y(1,k+1))>0
  45.     if imag(Y(1,k+1))>2
  46.       Z(1,k+1)=Z(1,k+1)+3*j;
  47.     else
  48.       Z(1,k+1)=Z(1,k+1)+j;
  49.     end
  50.   else
  51.     if imag(Y(1,k+1))<-2
  52.       Z(1,k+1)=Z(1,k+1)-3*j;
  53.     else
  54.       Z(1,k+1)=Z(1,k+1)-j;
  55.     end
  56.   end
  57.   echo off
  58. end
  59. echo on
  60. error=max(size(find(Z(1,2:10)-X(1,2:10))));