Advertisement
makispaiktis

Course 6 - Multipath Channel (FIR)

Aug 25th, 2023 (edited)
1,054
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.37 KB | None | 0 0
  1. clear all
  2. close all
  3. clc
  4.  
  5. % 1. Simulation parameters
  6. numBits = 20000;
  7. modOrder = 16;  % for 16-QAM
  8. bitsPerSymbol = log2(modOrder);  % modOrder = 2^bitsPerSymbol
  9. txFilt = comm.RaisedCosineTransmitFilter;
  10. rxFilt = comm.RaisedCosineReceiveFilter;
  11.  
  12. srcBits = randi([0,1],numBits,1);
  13. modOut = qammod(srcBits,modOrder,"InputType","bit","UnitAveragePower",true);
  14. txFiltOut = txFilt(modOut);
  15.  
  16.  
  17. % 2. Multipath Channel - Finite Impulse Response Filter
  18. mpChan = zeros(17, 1);
  19. mpChan(1) = 0.8;
  20. mpChan(9) = -0.5;
  21. mpChan(17) = 0.34;
  22. stem(mpChan);
  23.  
  24.  
  25. % 3. Apply the FIR filter simulating the multipath channel
  26. mpChanOut = filter(mpChan, 1, txFiltOut)
  27.  
  28.  
  29. % 4. Continue the process
  30. SNR = 15;  % dB
  31. chanOut = awgn(mpChanOut, SNR, "measured");
  32. rxFiltOut = rxFilt(chanOut);
  33.    
  34. scatterplot(rxFiltOut)
  35. title("Receive Filter Output")
  36. demodOut = qamdemod(rxFiltOut,modOrder,"OutputType","bit","UnitAveragePower",true);
  37.    
  38. % Calculate the BER
  39. delayInSymbols = txFilt.FilterSpanInSymbols/2 + rxFilt.FilterSpanInSymbols/2;
  40. delayInBits = delayInSymbols * bitsPerSymbol;
  41. srcAligned = srcBits(1:(end-delayInBits));
  42. demodAligned = demodOut((delayInBits+1):end);
  43.  
  44. numBitErrors = nnz(srcAligned~=demodAligned)
  45. BER = numBitErrors/length(srcAligned)
  46.  
  47.  
  48. % 5. Spectral Analysis
  49. specAn = dsp.SpectrumAnalyzer("NumInputPorts",2, "SpectralAverages",50,"ShowLegend",true);
  50. specAn(txFiltOut,chanOut)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement