Advertisement
makispaiktis

Course 8 - OFDM in multipath channels (with IFFT)

Aug 25th, 2023
1,290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.10 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. % 1. Modulation and IFFT
  6.  
  7. numBits = 32768;  % power of 2, to optimize performance of fft/ifft
  8. modOrder = 16;  % for 16-QAM
  9. srcBits = randi([0,1],numBits,1);
  10. qamModOut = qammod(srcBits,modOrder,"InputType","bit","UnitAveragePower",true);
  11. ofdmModOut = ifft(qamModOut);
  12.  
  13.  
  14. % 2. Channel
  15.  
  16. hasMultipath = true;
  17. hasAWGN = true;
  18. SNR = 15;
  19. chanOut = channel(ofdmModOut,hasMultipath,hasAWGN,SNR);
  20.  
  21.  
  22. % 3. FFT and Demodulation
  23.  
  24. ofdmDemodOut = fft(chanOut);
  25. scatterplot(ofdmDemodOut)
  26. title("OFDM Demodulator Output")
  27. qamDemodOut = qamdemod(ofdmDemodOut,modOrder,"OutputType","bit","UnitAveragePower",true);
  28. numBitErrors = nnz(srcBits~=qamDemodOut)
  29. BER = numBitErrors/numBits
  30.  
  31.  
  32.  
  33. function chanOut = channel(sig,hasMP,hasAWGN,SNR)
  34.     % Apply multipath channel if selected
  35.     if hasMP
  36.         mpChan = [0.8; zeros(7,1); -0.5; zeros(7,1); 0.34];
  37.         mpChanOut = filter(mpChan,1,sig);
  38.     else
  39.         mpChanOut = sig;
  40.     end
  41.     % Apply AWGN if selected
  42.     if hasAWGN
  43.         chanOut = awgn(mpChanOut,SNR,"measured");
  44.     else
  45.         chanOut = mpChanOut;
  46.     end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement