Advertisement
makispaiktis

Course 10 - Null subcarriers

Aug 25th, 2023
1,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.87 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5.  
  6. % 1. Simulation parameters
  7.  
  8. modOrder = 16;  % for 16-QAM
  9. bitsPerSymbol = log2(modOrder)  % modOrder = 2^bitsPerSymbol
  10. mpChan = [0.8; zeros(7,1); -0.5; zeros(7,1); 0.34];  % multipath channel
  11. SNR = 15   % dB, signal-to-noise ratio of AWGN
  12. numCarr = 8192;  % number of subcarriers
  13. cycPrefLen = 32;  % cyclic prefix length
  14.  
  15.  
  16. % 2. Define the indeces of guard bands (left and right)
  17.  
  18. numGBCarr = numCarr / 16;
  19. gbLeft = 1 : numGBCarr;
  20. gbRight = (numCarr - numGBCarr + 1) : numCarr;
  21.  
  22.  
  23. % 3. Add the DC component index
  24.  
  25. dcIdx = numCarr / 2 + 1;        % Center of vector
  26. nullIdx = [gbLeft dcIdx gbRight]';
  27.  
  28.  
  29. % 4. Calculate the number of source bits that will be sent
  30.  
  31. numDataCarr = numCarr - length(nullIdx);
  32. numBits = numDataCarr * bitsPerSymbol;
  33.  
  34.  
  35. % 5. QAM Modulation
  36.  
  37. srcBits = randi([0,1],numBits,1);
  38. qamModOut = qammod(srcBits,modOrder,"InputType","bit","UnitAveragePower",true);
  39.  
  40.  
  41. % 6. OFDM Modulation
  42.  
  43. ofdmModOut = ofdmmod(qamModOut, numCarr, cycPrefLen, nullIdx);
  44.  
  45.  
  46. % 7. Channel
  47.  
  48. mpChanOut = filter(mpChan,1,ofdmModOut);
  49. chanOut = awgn(mpChanOut,SNR,"measured");
  50.  
  51.  
  52. % 8. OFDM Demodulation
  53.  
  54. symbolSamplingOffset = cycPrefLen;
  55. ofdmDemodOut = ofdmdemod(chanOut, numCarr, cycPrefLen, symbolSamplingOffset, nullIdx);
  56.  
  57.  
  58. % 9. The channel frequency response has numCarr frequency components. However, the OFDM demodulator output contains only the data
  59. % subcarriers. To perform the elementwise division, you need to remove the null subcarrier frequency components from the channel
  60. % frequency response.
  61.  
  62. mpChanFreq = fftshift(fft(mpChan, numCarr));
  63. mpChanFreq(nullIdx) = [];
  64.  
  65.  
  66. % 10. Equalizer
  67.  
  68. eqOut = ofdmDemodOut ./ mpChanFreq;
  69. scatterplot(eqOut);
  70.  
  71.  
  72. % 11. QAM Demodulation
  73.  
  74. qamDemodOut = qamdemod(eqOut,modOrder,"OutputType","bit","UnitAveragePower",true);
  75. numBitErrors = nnz(srcBits~=qamDemodOut)
  76. BER = numBitErrors/numBits
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement