Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[moved] OFDM Index modulation (code gives wrong result)

Status
Not open for further replies.

syee

Newbie level 3
Joined
Feb 6, 2019
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
65
can someone tell me what is wrong with my code, the result is incorrect
----------------------------------------------------------------------
place this code first on a different file first for the function
Code:
function table2=BPSKAA(table2)


table2=[[1;0;1;0],[1;0;-1;0],[-1;0;-1;0],[-1;0;1;0],[0;1;0;1],[0;1;0;-1],[0;-1;0;-1],[0;-1;0;1],[1;0;0;1],[1;0;0;-1],[-1;0;0;-1],[-1;0;0;1],[0;1;1;0],[0;1;-1;0],[0;-1;-1;0],[0;-1;1;0]];
end
------------------------------------------------------------------------
Code:
clc
clear all;
close all;
% rand('seed',183);   randn('seed',321);
  

 %% MODEULATION AND DEMODULATION OBJECT BPSK
 M = 2;
;
       Eac = 2;
  
  taps=10;
%%
      SNR = 0:2:40;               % signal-to-noise ratio in dB
       No = (Eac)*10.^(-SNR/10);  % noise variance
     L_SNR = length(SNR);         % length of SNR
       ber = zeros (L_SNR,1);     % initializating BER
       Result_table=zeros(4 ,128);
      %  bit_RL=zeros(L_SNR,1); 
      
 Nframe=10000;
  bit_RL=zeros(21,1); 
  ;
%digMod1=zeros(2 , length(digMod));
;
        % initializating BER
 
     ; 
%% ============================= Transmitter ===============================
 for iL=1:Nframe % sending 1000 frame
           
     
bit_T= randi([0 1],512,1);     % generate random bits
G_bits = reshape(bit_T,4,128);    % grouping bits into blocks
  
%% taking the first two rows for index modulation selection    
Index_selection=  [G_bits(1:2,:)].'; 

%% Doing BPSK modulation for third and fourth rows for G_bits
AW=reshape(G_bits(2+1:end,:),1,[]);
digMod1 = 2*(AW)-1;
digMod=reshape(digMod1,2,[]);

% digMod = 2*(G_bits(2+1:end,:))-1;



%% Create a block 4x128 to add result for BPSK modulation depending on sub carrier position 
  block = zeros(4 , length(digMod));
ab=  zeros(2 , 128);
% ML = zeros(1,16);
%% Chosing which sub carrier active in each colum  
 for i=1:length(Index_selection)
     
    
if Index_selection(i,1:end)==[0 0]
    sub_no(i,1:2)=[1,3];
elseif Index_selection(i,1:2)==[0 1]
    sub_no(i,1:2)=[2,4];
elseif Index_selection(i,1:2)==[1 0]
    sub_no(i,1:2)=[1,4];
elseif Index_selection(i,1:end)==[1 1]
    sub_no(i,1:2)=[2,3]; 
end
    
%% Adding the modulated signal on active carriers    
block(sub_no(i,1:2) , i)=digMod(1:2,i);
 end
 
transmitted_signa =block; % transmitted_signal
%% Pass the signal through IFFT 
 transmitted_signa1=reshape(transmitted_signa,512,1);

 IFFT_data = ifft(fftshift(transmitted_signa1.')).';
 a=max(max(abs(IFFT_data)));
 transmitted_signa_IFFT=IFFT_data./a; % normalization
 %% % transmitted sinal with IFFT
transmitted_signa_IFFT=reshape(transmitted_signa_IFFT,4,128);
%% Appending cylic prefix
% transmitted_signa_IFFT2 = [transmitted_signa_IFFT(:,[112128]) transmitted_signa_IFFT];
 

   transmitted_signa_IFFT=reshape(transmitted_signa_IFFT,512,1);
%% Calling a table for all posible position for BPSK modulation in INdex modaulation 
 table=BPSKAA;
%   for iL=1:Nframe
%% Creating a channel and receiver 
ber=[];
   for  ii  =1: L_SNR  
          % for pp = 1 :128
  %% Creating  channel  and noise 
   ch = sqrt(.5)*( randn(1,1,1) + 1i*randn(1,1,1));
% %   ch=sqrt(.5)*(randn(1,1)+j*randn(1,1));
% 
  noise = sqrt(.5)*(randn(1 , 1) + 1i*randn(1 , 1))* sqrt(No(ii));
% % noise =awgn(xt,SNR(ii),'measured');

  %% Passing signal through noise amd channel


        received_signal = ch.*transmitted_signa_IFFT;
%         received_signal=awgn(received_signal,SNR(ii));
 received_signal=awgn(received_signal,SNR(ii));

 %% removing cyclic prefix
%  received_signal = received_signal(:,[33:160]);
 
%% Applying FFT and normalize the signal
%  received_signal=reshape(received_signal,4,128);
received_signal1  = a.*fftshift(fft(received_signal.' )).'; 
 
received_signal2=reshape(received_signal1,4,128);
    for pp= 1 : 128
   %% Maximum Likelihood 
   
   
   ML = zeros(1,16);
   
A=received_signal2(:,pp);
B= repmat(A,[1,16]);
%  AAA=awgn(table,SNR(ii));
 
 ML= sum(abs( (B) - (ch.*table).^2));
% %       
%  
             [temp1 temp2] = min(ML);
       
                  KL(pp)=temp2;
%   
  %% finding which sub carrier active in each colum    
  if  (  KL(pp)>=1 &&   KL(pp)<=4)
    P_sub_B(pp,1:2)= [1,3];
    GET_INDEX_Selec(pp,1:2)=[0,0];
elseif (  KL(pp)>=5 &&   KL(pp)<=8)
     P_sub_B(pp,1:2)=[2,4];
     GET_INDEX_Selec(pp,1:2)=[0,1];
elseif  (  KL(pp)>=9 &&   KL(pp)<=12)
     P_sub_B(pp,1:2)=[1,4];
     GET_INDEX_Selec(pp,1:2)=[1,0];
elseif (  KL(pp)>=13 &&   KL(pp)<=16)
     P_sub_B(pp,1:2)=[2,3];
     GET_INDEX_Selec(pp,1:2)=[1,1];
    
  end
 AC_subcarrier=P_sub_B;
 %%chosing the two colum for the postion os subcarrier
 
 %% Demodulate the transmiited_signal using the  Index selection bits you detected in receiver after you chose for the first colum
   
    ab(1:2,pp)= (transmitted_signa(AC_subcarrier(pp,1:2),pp));
   % converting modulated values into 0 and 1
   bi_demod(1:2,pp) = ( (ab(1:2,pp))+1)/2 ;   
%     bi_demod(1:2,pp) = ( (ab(1:2,pp))+1)/2 ;  
%    bi_demod(1:2,pp)=demodulate(modem.pskdemod(2),ab(1:2,pp));
% % %   
 %% Creating a Result_table 4x128 after you detected the INdex selection bits and demodulated signal bits 
% % %  
     GET_INDEX_Selec1=GET_INDEX_Selec(pp,1:2).';
      bi_demod1= bi_demod(1:2,pp);
      
  
 %% Creating a Result_table 4x128 after you detected the INdex selection bits and demodulated signal bits 
  Result_table(:,pp)=[   GET_INDEX_Selec1;  bi_demod1];
     

   end
      
bit_R=reshape( floor(Result_table),512,1);
 [~,ber(ii,1)] = biterr(bit_T(:,1),bit_R(:));
% [number,ratio(ii,1)] = symerr(bit_T(:,1),bit_R(:),'row-wise');
   end
  


   
bit_RL= bit_RL+ ber;



%% Adding the previous ber for thw previous frame with the next frame after it
    
% % % 
 end
 bit_RL=bit_RL/Nframe;
 

Attachments

  • Paper 2016 - Index Modulation Techniques for 5G Wireless Networks.pdf
    621.4 KB · Views: 107

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top