-1

I am working to simulate the BER between 2 users in CDMA with convolutional codes and modulation scheme of QAM-16. From the graph i've attached, the BER of user 1 and user 2 are the same and constant. It seems that the SNR does not affect the transmission. Is there anyway i can improve the graph? Here is my code:

M = 16;                 % Modulation order
k = log2(M);            % Bits per symbol
EbNoVec = (0:20)';      % Eb/No values (dB)
numSymPerFrame = 1;   % Number of QAM symbols per frame
users=2;            % Number of Users
trellis = poly2trellis(7,[171 133]);
tbl = 32;
rate = 1/2;
%------------------Generation of Walsh code--------------------------------
noOfSubCarrier =20;                               %Number of  Data Sub-Carriers
walsh=hadamard(noOfSubCarrier);
code1=walsh(10,:);                   
code2=walsh(20,:); 

berEst1 = zeros(size(EbNoVec));
berEst2 = zeros(size(EbNoVec));%Initialize the results vector

% The main processing loop executes the following steps:
% Generate binary data and convert to 64-ary symbols
% QAM modulate the data symbols
% Pass the modulated signal through an AWGN channel
% Demodulate the received signal
% Convert the demoduated symbols into binary data
% Calculate the number of bit errors

for n = 1:length(EbNoVec)
    % Convert Eb/No to SNR
    snrdB = EbNoVec(n) + 10*log10(k*rate);
    % Reset the error and bit counters
    numErrs1 = 0;
    numErrs2 = 0;
    numBits = 0;

    % Generate binary data and convert to symbols
    B=10;
    dataIn1= rand(1,B);
    dataIn2=rand(1,B);
    symbols1= unique(dataIn1);
    symbols2= unique(dataIn2);
    probs1 = histc(dataIn1,symbols1)./numel(dataIn1);
    probs2 = histc(dataIn2,symbols2)./numel(dataIn2);
    [dict1, avglen1] = huffmandict(symbols1, probs1);
    [dict2, avglen2] = huffmandict(symbols2, probs2);
    comp1 = huffmanenco(dataIn1,dict1);
    comp2 = huffmanenco(dataIn2,dict2);
     % Convolutionally encode the data
    dataEnc1 = convenc(comp1,trellis);
    dataEnc2 = convenc(comp2,trellis);

    % QAM modulate
    txSig1 = qammod(dataEnc1,M,0);
    txSig2 = qammod(dataEnc2,M,0);
    %------------------Spreading & IFFT for User1------------------------------
    Tx_data1=txSig1';
    Spread_User1=Tx_data1*code1;    % Spreading 
    Spread1=(Spread_User1)';
    ifftdata_user1=ifft(Spread1);      % Taking the IFFT
    ifftdata1=ifftdata_user1';
    %------------------Spreading & IFFT for User2------------------------------
    Tx_data2=txSig2';
    Spread_User2=Tx_data2*code2;    % Spreading 
    Spread2=(Spread_User2)';
    ifftdata_user2=ifft(Spread2);      % Taking the IFFT
    ifftdata2=ifftdata_user2';
    %----------------------Addition of all signal------------------------------
    TotSignal = Spread1+Spread2;
    % Pass through AWGN channel
    AwTotSignal = awgn(TotSignal,snrdB,'measured');
    %-----------------------Removing the FFT & De-Spreading--------------------
    fft_data_received =fft(AwTotSignal);
    Rec_Data1=(AwTotSignal'*code1');
    Rec_Data2=(AwTotSignal'*code2');
    % Demodulate the noisy signal
    rxSym1 = qamdemod(Rec_Data1,M,0);
    rxSym2 = qamdemod(Rec_Data2,M,0);
    data1=vitdec(rxSym1,trellis,5,'cont','unquant');
    data2=vitdec(rxSym2,trellis,5,'cont','unquant');
    % Convert received symbols to bits
    %dataOut1 = de2bi(data1,k);
    %dataOut2 = de2bi(data2,k);
    % Calculate the number of bit errors
    nErrors1 = biterr(comp1',data1);
    nErrors2 = biterr(comp2',data2);
    % Increment the error and bit counters
    numErrs1 = numErrs1 + nErrors1;
    numErrs2 = numErrs2 + nErrors2;
    numBits= numBits + numSymPerFrame*k;

    % Estimate the BER
    berEst1(n) = numErrs1/numBits;
    berEst2(n) = numErrs2/numBits;
end

graph of BER

Ms Nas
  • 21
  • 2

1 Answers1

1

[NOTE: This should actually be a comment, but I cannot write them with my current SO reputation and this is something the OP should know]

First of all, I confess I didn't have a particularly hard look at your code because the errors I see in the graphs come from bugs unrelated to CDMA or the modulation at hand.

I'd say the most remarkable error is not the graphs being constant, but the BER being over 1. That makes no sense at all and indicates that, at least, there's something wrong with your formulation of the BER itself.

Moreover, if the BER was actually 1 and not over it it would still make no sense. Take into account that a BER of 1 (let alone OVER 1) implies that you fail to recover the symbol correctly every single time. By simple statistics you should recover at least some of them correctly even if picking them at random. That's another common error scenario in this kind of applications.

That said, check your BER formulation and plot some intermediate values. Don't do everything in one step (e.g: Try the system without the correction codes).

I hope that gives you a bump in the right direction.

agvallejo
  • 36
  • 4
  • Thanks for the feedback. I'll check the formulation as you've suggested. I've used the coding provided at Matlab website (tutorials). When i ran the sample coding without modification, the code worked fine and show a logic outputs of BER. The problem is when I've added two users and CDMA. – Ms Nas Mar 28 '16 at 16:53