Advertisement
adiee

OFDM

Mar 14th, 2022
1,002
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. clc
  2. clear all
  3. close all
  4.  
  5. %INITIATION
  6. no_of_data_bits=64;
  7. M=4;     %NO OF SUBCARRIERS
  8. n=256;   %NO OF BITS TO BE TRANSMITTED AT TRANSMITTER
  9. block_size=16; %OFDM BLOCK FOR CYCLIC PREFIX
  10. cp_len=floor(0.1*block_size);
  11.  
  12. %TRANSMITTER (TO GENERATE RANDOM DATA SOURCE)
  13. data=randsrc(1,no_of_data_bits,0:M-1);
  14. figure(1),
  15. stem(data);
  16. grid on;
  17. xlabel('Data points');
  18. ylabel('amplitude');
  19. title('original data');
  20.  
  21. %PERFORM QPSK MODULATION
  22. qpsk_modulated_data=pskmod(data,M);
  23. figure(2),
  24. stem(qpsk_modulated_data);
  25. title('QPSK Modulation');
  26.  
  27. S2P=reshape(qpsk_modulated_data,no_of_data_bits/M,M);
  28. sub_carrier1=S2P( :,1);
  29. sub_carrier2=S2P( :,2);
  30. sub_carrier3=S2P( :,3);
  31. sub_carrier4=S2P( :,4);
  32. figure(3),subplot(4,1,1),stem(sub_carrier1),title('Sub Carrier 1'),grid on;
  33. subplot(4,1,2),stem(sub_carrier2),title('Sub Carrier 2'),grid on;
  34. subplot(4,1,3),stem(sub_carrier3),title('Sub Carrier 3'),grid on;
  35. subplot(4,1,4),stem(sub_carrier4),title('Sub Carrier 4'),grid on;
  36.  
  37. %IFFT OF 4 SUBCARRIERS
  38. M=4;     %NO OF SUBCARRIERS
  39. cp_start=block_size-cp_len;
  40. ifft_subcarrier1 = ifft(sub_carrier1);
  41. ifft_subcarrier2 = ifft(sub_carrier2);
  42. ifft_subcarrier3 = ifft(sub_carrier3);
  43. ifft_subcarrier4 = ifft(sub_carrier4);
  44.  
  45. figure(4),subplot(4,1,1),plot(real(ifft_subcarrier1),'r'),
  46. title('IFFT ON ALL THE SUBCARRIERS')
  47. subplot(4,1,2),plot(real(ifft_subcarrier2),'c')
  48. subplot(4,1,3),plot(real(ifft_subcarrier3),'b')
  49. subplot(4,1,4),plot(real(ifft_subcarrier4),'d')
  50.  
  51. %ADD CYCLIC PREFIX
  52. for i=1:M
  53.     ifft_subcarrier (:,i) = ifft(S2P(:,i),16);
  54.     for j=1:cp_len
  55.         cyclic_prefix(j,i) = ifft_subcarrier (j+cp_start,i);
  56. end
  57. Append_prefix(:,i) = vertcat(cyclic_prefix(:,i),ifft_subcarrier(:,i));
  58. end
  59. A1=Append_prefix(:,1);
  60. A2=Append_prefix(:,2);
  61. A3=Append_prefix(:,3);
  62. A3=Append_prefix(:,4);
  63.  
  64. %Appends prefix to each subcarrier
  65. A1=Append_prefix(:,1);
  66. A2=Append_prefix(:,2);
  67. A3=Append_prefix(:,3);
  68. A4=Append_prefix(:,4);
  69.  
  70. figure(5),subplot(5,1,1),plot(real(A1),'r'),
  71. title('CYCLIC PREFIX ADDED')
  72. subplot(5,1,2),plot(real(ifft_subcarrier2),'c')
  73. subplot(5,1,3),plot(real(ifft_subcarrier3),'b')
  74. subplot(5,1,4),plot(real(ifft_subcarrier4),'d')
  75.  
  76. figure(6),plot(real(A2),'r'),
  77. title('ORTHOGONALITY'),hold on
  78. plot(real(A2),'c'),hold on
  79. plot(real(A3),'b'),hold on
  80. plot(real(A4),'d'),hold on
  81. grid on;
  82.  
  83.  
  84. %CONVERT SERIAL STREAM FOR TRANSMISSION
  85. [row_Append_prefix cols_Append_prefix]=size(Append_prefix);
  86. len_ofdm_data=row_Append_prefix*cols_Append_prefix;
  87.  
  88. ofdm_signal=reshape(Append_prefix,1,len_ofdm_data);
  89.  
  90. figure(7),
  91. plot(real(ofdm_signal));
  92. xlabel('TIME');
  93. ylabel('AMPLITUDE');
  94. title('OFDM SIGNAL');
  95. grid on;
  96.  
  97.  
Advertisement
RAW Paste Data Copied
Advertisement