⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rect_qam.m

📁 this file contain some useful common communication matlab m tool. like QAM PSK and simulation of rec
💻 M
字号:

clear all ; close all;

E = 1 ;       % normalized to unit energy
snr_dB = 36 ;
snr_dB = 6 ;

N = 10000 ;    % no of bits  ...
MH = 4 ; MV = 4 ;   % simulate MH levels horizontally MV levels vertically ...
M = MH*MV ;        % no. of levels ...
phi = 10*pi/180  ;     % carrier phase off-set in radian ..
phi = 0 ;

snr = exp(snr_dB*log(10)/10) ;
sig = E/sqrt(2*snr) ;       % this is detector noise std deviation

% the detector signals and symbol error ....
err = 0 ;
for i=1:N
   tt = rand;            %  tt is uniformly distributed in 0->1 .
   srch = floor(rand*MH) ; %  simulate symbols 0 -- MH-1 ....
   srcv = floor(rand*MV) ; %  simulate symbols 0 -- MV-1 ....
    
   r0(i) = (2*srch - MH + 1)*cos(phi) - (2*srcv - MV + 1)*sin(phi) + sig*randn ;  % WGN 
   r1(i) = (2*srcv - MV + 1)*cos(phi) + (2*srch - MH + 1)*sin(phi) + sig*randn ;
   
   deth = floor(r0(i)/2) + 2 ;
   deth = max(0, deth) ; deth = min(MH-1,deth) ;   % limit between 0 and 3 ;
   detv = floor(r1(i)/2) + 2 ;
   detv = max(0, detv) ; detv = min(MV-1,detv) ;   % limit between 0 and 3 ;
   
   if(deth ~= srch) 
      err = err + 1 ;    
     elseif(detv ~=srcv)
         err = err + 1 ;
   end ;
end;
SER = err/N ;

% calculte therotical BER ...in a SNR (db) range
dbR = 0:1:20 ;
for i = 1:length(dbR)
   snr = exp(dbR(i)*log(10)/10) ;
   PH = (1-1/sqrt(MH))*erfc(sqrt(snr));
   PV = (1-1/sqrt(MV))*erfc(sqrt(snr));
   SERT(i) = 1 - (1-PH)*(1-PV) ;
end ;

figure(1); plot(r0,r1,'.');
hold on ; 
for k=0:MH-2
  plot([2*k-MH+2 2*k-MH+2], [-4 4],'r--') ; 
end ;
for k=0:MV-2
  plot([-4 4], [2*k-MV+2 2*k-MV+2],'r--') ; 
end ;
hold off ;
axis([-4 4 -4 4]); 
grid;
title('Signal constellations (normalized by Energy)');
xlabel('real part');
ylabel('imaginary part');
figure(2); semilogy(dbR, SERT, snr_dB, SER,'r*') ; 
grid ;
xlabel('SNR in dB');
ylabel('Symbol Error Probability, Pm');
title('Theoretical (blue) and simulated (red *) Pm');

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -