Advertisement
redsees

Untitled

Apr 17th, 2017
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.28 KB | None | 0 0
  1. % Lab1 Matlab - Digital Communication Systems Course
  2. % Team:
  3. % Abdullah Mohamed Abdullah - 1557
  4. % AbdelRahman Tarik ElBakri - 2447
  5. % Ahmed Tawfieck - 1386
  6.  
  7. function Lab1(Num_of_Bits, SNR_Begin, SNR_Step, SNR_End)
  8.    
  9.     % BER matrix containing BER per SNR
  10.     BER = [];
  11.    
  12.     for SNR = SNR_Begin:SNR_Step:SNR_End
  13.         % Generate <Num_of_Bits> random bits
  14.         Tx_Bits = randi([0 1], 1, Num_of_Bits);
  15.        
  16.         % Calculate AWGN power
  17.         AWGN_Power = Gen_AWGN(Tx_Bits, SNR);
  18.        
  19.         % Apply AWGN to the transmitted signal
  20.         Rx_Bits = Tx_Bits + AWGN_Power;
  21.        
  22.         % Decide whether the received bit is 1 or 0 with threshold 0.5
  23.         Rx_Bits = Rx_Bits > 0.5;
  24.        
  25.         % Calculate BER Comparing between transmitted and received signals
  26.         BER = [BER biterr(Tx_Bits, Rx_Bits)];
  27.        
  28.     end
  29.    
  30.     % Plot SNR against BER on a logarithmic scale Y-axis
  31.     semilogy([SNR_Begin:SNR_Step:SNR_End], BER);
  32.     ylabel('BER');
  33.     xlabel('SNR (dB)');
  34.     grid;
  35. end
  36.  
  37. % Defining local function to calculate AWGN
  38. function NoisePower = Gen_AWGN(Tx_Bits, SNR)
  39.     % Calculating transmitted signal power
  40.     Ptx = mean(Tx_Bits.^2);
  41.    
  42.     % Calculate AWGN power
  43.     NoisePower = sqrt(Ptx/(2*SNR)) * [randn(size(Tx_Bits)) + 1j * randn(size(Tx_Bits))];
  44.  
  45. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement