首页 文章

为什么我的BER变得不变,我的代码是不正确的?

提问于
浏览
-1

我正在努力用卷积码和QAM-16的调制方案来模拟CDMA中2个用户之间的BER . 从我附上的图表中,用户1和用户2的BER是相同且恒定的 . 似乎SNR不会影响传输 . 无论如何我可以改进图表吗?这是我的代码:

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

1 回答

  • 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]

    首先,我承认我没有特别认真地看你的代码,因为我在图中看到的错误来自与CDMA无关的错误或手头的调制 .

    我要说最显着的错误不是图形不变,而是BER超过1.这根本没有任何意义,并且表明,至少,你的BER本身的表述有问题 .

    此外,如果BER实际为1并且没有超过它,那么它仍然没有意义 . 考虑到BER为1(更不用说超过1)意味着您无法每次都正确恢复符号 . 通过简单的统计,即使随机选择它们,您也应该正确地恢复其中一些 . 这是此类应用程序中的另一种常见错误情况 .

    也就是说,检查您的BER配方并绘制一些中间值 . 不要一步到位(例如:尝试没有校正码的系统) .

    我希望这会让你朝着正确的方向前进 .

相关问题