Hadamard正交编码+BPSK误码性能分析

%%%%%   Hadamard正交编码+BPSK误码性能分析  %%%%%%%%%%%%%%%%
NVec = [8 16 32 64 128  ]; % Values of N to consider(编码效率)
EbNoVec =3:9;SNRVec=zeros(1,length(NVec));
nSamp = 1; 
M = 2;                      % Size of signal constellation
k = log2(M);                % Number of bits per symbol
cont=0;
hMod = modem.pskmod(M);         % Create a M-PSK modulator
hMod.InputType = 'Bit';         % Accept bits as inputs
hMod.SymbolOrder = 'Gray';      % Accept bits as inputs
hDemod = modem.pskdemod(hMod);

number_of_errors = zeros(length(NVec),length(EbNoVec));
bit_error_rate1  = zeros(length(NVec),length(EbNoVec));
 
for idxN = 1:length(NVec)
 N=NVec(idxN);%  符号比特数;
 H=hadamard(N);   % 生成Hadamard矩阵  
 h = log2(N);  % 消息比特数;
 coderate=h/N;%符号率
  for i=1:N                   % 符号替换
      for j=1:N 
        if (H(i,j)==-1),
            H(i,j)=0;
        end;
    end;
end 

n = h*floor(100000   /h); % Number of bits to process
  for idxEbNo = 1:length(EbNoVec)                       
  figure(1);      

%% Simulation loops

      
    x = randi([0 1],n,1); % Random binary data stream
    xsym = bi2de(reshape(x,h,length(x)/h).','left-msb');% 产生(0 to h-1)
    x_enc=xsym+1 ;% 从1到 h范围的信息符号字
   
   codeword=zeros(length(xsym),N); 
   decodeword=zeros(length(xsym),N); 
   zsym=zeros(length(xsym),1);
   
  for l=1:length(x_enc)   
   codeword(l,:)=H(x_enc(l),:) ; %  对每个信息符号相当的符号字
   f=codeword(l,:)';
   y = modulate(hMod,f) ; 
   yTx = y;
   
   %% Channel
   % Send signal over an AWGN channel.
   EbNo = EbNoVec(idxEbNo); % In dB
   SNR = EbNo +10*log10(k*coderate) - 10*log10(nSamp);
   SNRVec(idxEbNo)=SNR;
   yNoisy = awgn(yTx,SNR,'measured');
   
   %% Received Signal
   yRx = yNoisy;   
   
   %%  Demodulating 
   rcvword_C = demodulate(hDemod,yRx) ;
   %% Hadamard_decoding
   rcvword =rcvword_C';
   tt=xor(f,rcvword_C);%tt'
   minnum=1 ;
   min=N ;
for i=1:N
    d=0;
    for j=1:N %计算接受符号和Hadamard行列各行之间的汉明距离
        if (rcvword(1,j)~=H(i,j)),
            d=d+1;
        end;
    end;
    if (d<min),%探索最小汉明距离
        min=d; 
        minnum=i; 
    end;
end;
  zsym(l)=minnum-1;
  decodeword(l,:)=H(minnum,:);
  if((f~=rcvword_C  )), %&&  (decodeword(l,:)==codeword(l,:) )
      cont=cont+1;
  end;
 end  ;    
  z = de2bi(zsym',h,'left-msb'); % Convert integers to bits.
  % Convert z from a matrix to a vector.
  z = reshape(z.',numel(z),1);  
  
 
  %% BER Computation
      % Compare x and z to obtain the number of errors and
      % the bit error rate.
      [number_of_errors(idxN,idxEbNo),bit_error_rate1(idxN,idxEbNo)] = ...
          biterr(x,z) 
    
 
  end % End of loop over EbNo values

 markerchoice1 =   '.xo*sd';
 markerchoice2 =   'bgcmyk';
 figure(1);
   plotsym = [markerchoice1(idxN) markerchoice2(idxN) '-']; % Plotting style for this curve
   semilogy(EbNoVec,bit_error_rate1(idxN,:),plotsym); % Plot one curve.
   drawnow; % Update the plot instead of waiting until the end.
   hold on; % Make sure next iteration does not remove this curve.
  figure(2);
  plotsym = [markerchoice1(idxN) markerchoice2(idxN) '-']; % Plotting style for this curve
   semilogy(SNRVec,bit_error_rate1(idxN,:),plotsym); % Plot one curve.
   drawnow; % Update the plot instead of waiting until the end.
   hold on; % Make sure next iteration does not remove this curve.
end  % End of loop over N values

%% Complete the plot.

%%%%%%%%%%%%%%%%%%%%%%% Noncoded-BPSK %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
M = 2;                      % Size of signal constellation
k = log2(M);                % Number of bits per symbol
n=100000                    % Number of bits to process
nSamp = 1; 

hMod = modem.pskmod(M);         % Create a MPSK modulator
hMod.InputType = 'Bit';         % Accept bits as inputs
hMod.SymbolOrder = 'Gray';      % Accept bits as inputs
hDemod = modem.pskdemod(hMod);


%% Preallocate space for results.

bit_error_rate2   = zeros(1,length(EbNoVec));

  for idxEbNo = 1:length(EbNoVec)                
           
    x = randi([0 1],n,1); % Random binary data stream
    y = modulate(hMod,x) ; 
   yTx = y;
   
   %% Channel
   % Send signal over an AWGN channel.
   EbNo = EbNoVec(idxEbNo); % In dB
   SNR = EbNo + 10*log10(k) - 10*log10(nSamp);
   SNRVec(idxEbNo)=SNR;
   yNoisy = awgn(yTx,SNR,'measured');
   
   %% Received Signal
   yRx = yNoisy;   
   
   %%  Demodulating 
  z  = demodulate(hDemod,yRx) ;
   
  %% BER Computation
      % Compare x and z to obtain the number of errors and
      % the bit error rate.
      [number_of_errors(1,idxEbNo),bit_error_rate2(1,idxEbNo)] = ...
          biterr(x,z)  
      
  end % End of loop over EbNo values
  
figure(1)
   semilogy(EbNoVec,bit_error_rate2(1,:),'-rd'); % Plot one curve.
   drawnow; % Update the plot instead of waiting until the end.
   hold on; % Make sure next iteration does not rermove this curve.
figure(2)
   semilogy(SNRVec,bit_error_rate2(1,:),'-rd'); % Plot one curve.
   drawnow; % Update the plot instead of waiting until the end.
   hold on; % Make sure next iteration does not rermove this curve.

figure(1)
title('Performance of Hadamard-BPSK for Varying N');
xlabel('EbNo (dB)'); ylabel('BER');
 legend('N =8','N =16','N =32','N=64','N=128','Noncoded BPSK',...
   'Location','SouthWest')  
figure(2)
title('Performance of Hadamard-BPSK for Varying N');
xlabel('SNR (dB)'); ylabel('BER');
legend('N =8','N =16','N =32','N=64','N=128','Noncoded BPSK',...
   'Location','SouthWest')  
  
  
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

fpga和matlab

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值