Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. clear; close all; clc
  2. rng default
  3. M = 4; % Modulation order
  4. k = log2(M); % Bits per symbol
  5. EbNoVec = (0:20)'; % Eb/No values (dB)
  6. numSymPerFrame = 100000; % Number of QAM symbols per frame
  7.  
  8. modul = comm.RectangularQAMModulator(M, 'BitInput', true);
  9. berEstSoft = zeros(size(EbNoVec));
  10.  
  11.  
  12. trellis = poly2trellis(7,[171 133]);
  13. tbl = 32;
  14. rate = 1/2;
  15.  
  16. decoders = comm.ViterbiDecoder(trellis,'TracebackDepth',tbl,...
  17. 'TerminationMethod','Continuous','InputFormat','Unquantized');
  18.  
  19.  
  20. for n = 1:length(EbNoVec)
  21. % Convert Eb/No to SNR
  22. snrdB = EbNoVec(n) + 10*log10(k*rate);
  23. % Noise variance calculation for unity average signal power.
  24. noiseVar = 10.^(-snrdB/10);
  25. % Reset the error and bit counters
  26. [numErrsSoft, numErrsHard, numBits] = deal(0);
  27.  
  28. while numErrsSoft < 100 && numBits < 1e7
  29. % Generate binary data and convert to symbols
  30. dataIn = randi([0 1], numSymPerFrame*k, 1);
  31.  
  32. % Convolutionally encode the data
  33. dataEnc = convenc(dataIn, trellis);
  34.  
  35. % QAM modulate
  36. txSig = step(modul, dataEnc);
  37.  
  38. % Pass through AWGN channel
  39. rxSig = awgn(txSig, snrdB, 'measured');
  40.  
  41. % Demodulate the noisy signal using hard decision (bit) and
  42. % soft decision (approximate LLR) approaches.
  43. demods = comm.RectangularQAMDemodulator(M, 'BitOutput', true, ...
  44. 'DecisionMethod', 'Approximate log-likelihood ratio',...
  45. 'VarianceSource', 'Property', 'Variance', noiseVar);
  46. rxDataSoft = step(demods, rxSig);
  47.  
  48. % Viterbi decode the demodulated data
  49. dataSoft = step(decoders, rxDataSoft);
  50.  
  51. % Calculate the number of bit errors in the frame. Adjust for the
  52. % decoding delay, which is equal to the traceback depth.
  53. numErrsInFrameSoft = biterr(dataIn(1:end-tbl), dataSoft(tbl+1:end));
  54.  
  55. % Increment the error and bit counters
  56. numErrsSoft = numErrsSoft + numErrsInFrameSoft;
  57. numBits = numBits + numSymPerFrame*k;
  58.  
  59. end
  60.  
  61. % Estimate the BER for both methods
  62. berEstSoft(n) = numErrsSoft/numBits;
  63. end
  64.  
  65. semilogy(EbNoVec, berEstSoft,'-o','LineWidth', 1.5)
  66. hold on
  67. legend('Soft','location','best')
  68. grid
  69. xlabel('Eb/No (dB)')
  70. ylabel('Bit Error Rate')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement