Advertisement
makispaiktis

Eidikes Keraies - Ergasia2 - Part2

Jul 9th, 2021 (edited)
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 2.67 KB | None | 0 0
  1. clear all
  2. clc
  3.  
  4.  
  5. % Main Function
  6. % Standard data
  7. M = 24;
  8. N = 13;
  9. Pg = 1;
  10. SNR = 10;
  11. thetaList = [];
  12. counter = 0;
  13. for angle = 30:10:150
  14.     counter = counter + 1;
  15.     thetaList(counter) = angle * pi/180;
  16. end
  17. THETA_LIST = thetaList * 180/pi
  18. run(M, N, Pg, SNR, thetaList);
  19.  
  20.  
  21. % ===============================================================
  22. % ===============================================================
  23. % ======================== Functions ============================
  24. % ===============================================================
  25. % ===============================================================
  26.  
  27. % Function 1 - Steering vector
  28. function a = steeringVector(M, theta)
  29.     a = [];    
  30.     for m = 1 : M
  31.         a(m) = exp(i * pi * (m-1) * cos(theta));
  32.     end
  33.     a = a';
  34.     a;
  35. end
  36.  
  37. % Function 2 - Steering Matrix
  38. function A = steeringMatrix(M, thetaList)
  39.     A = [];
  40.     for index = 1 : length(thetaList)
  41.         A(:, index) = steeringVector(M, thetaList(index));
  42.     end
  43.     A;
  44. end
  45.  
  46. % Function 3 - DoA: LP = Linear Prediction
  47. function spectrum = draw_LP_Spectrum(M, N, A,Pg, P_noise, thetaList)
  48.     Rgg = Pg * eye(N);
  49.     Rnn = P_noise * eye(M);
  50.     Rxx = A * Rgg * A' + Rnn;
  51.     % Draw χωρικό φάσμα ισχύος του εκτιμητή
  52.     % We suppose 1st element as the reference
  53.     e1 = zeros(1, M);
  54.     e1(1) = 1;
  55.     e1 = e1';            % Now, its a column-vector with size = 24x1
  56.     nominator = e1' * inv(Rxx) * e1;
  57.     % For denominator, I need to make a vector "ad" which refers to a random
  58.     % angle signal
  59.     counter = 0;
  60.     angles = [];            % x axis
  61.     spectrum = [];          % y axis
  62.     for angle = 0:0.1:180
  63.         counter = counter + 1;
  64.         angles(counter) = angle;        % In degrees
  65.         angleRad = angle * pi/180;      % In rad
  66.         ad = steeringMatrix(M, angleRad);
  67.         % For calculations, I will need rad angles
  68.         denominator = (norm(e1' * inv(Rxx) * ad))^2;
  69.         spectrum(counter) = nominator / denominator;
  70.     end
  71.     plot(angles, spectrum);
  72.     myTitle = "";
  73.     THETA_LIST = thetaList * 180/pi;
  74.     for i = 1:length(THETA_LIST)
  75.         t = "θ" + int2str(i) + "=" + num2str(THETA_LIST(i));
  76.         if i < length(THETA_LIST)
  77.             t = t + ", ";
  78.         end
  79.         myTitle = myTitle + t;
  80.     end
  81.     title(myTitle);
  82.     xlabel("θ in degrees");
  83.     ylabel("10log(P / Pmax)");
  84.     spectrum;
  85. end
  86.  
  87. % Function 4 - Run with data
  88. function run(M, N, Pg, SNR, thetaList)
  89.     SNR_noDB = 10^(SNR/10);
  90.     P_noise = Pg / SNR_noDB;
  91.     A = steeringMatrix(M, thetaList);        % Size = 24x13
  92.     spectrum = draw_LP_Spectrum(M, N, A, Pg, P_noise, thetaList);
  93. end
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement