From 771e83fed52a03d26df0fbe75d63cd329d69129e Mon Sep 17 00:00:00 2001
From: ZaellixA <axilleaz@protonmail.com>
Date: Mon, 27 Jan 2025 15:11:13 +0000
Subject: [PATCH] Vectorise calculation of array manifolds

---
 .../MATLAB/Functions/firstOrderDma.m          | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m b/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m
index b7b0440..7d03383 100644
--- a/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m	
+++ b/Signal Processing/Array Processing/MATLAB/Functions/firstOrderDma.m	
@@ -3,7 +3,7 @@
 % Author: Achilles Kappis
 % e-mail: axilleaz@protonmail.com
 %
-% Date: 04/01/2025 (DD/MM/YYYY)
+% Date: 27/01/2025 (DD/MM/YYYY)
 %
 % Copyright: MIT
 % --------------------------------------------------
@@ -130,7 +130,7 @@ function [h, output] = firstOrderDma(freq, d, pPattern, beta, input)
                 pPattern = pi/2;
                 beta = 0;
             case 'cardioid'
-                pPattern = pi;
+                pPattern = -pi;
                 beta = 0;
             case 'hypercardioid'
                 pPattern = (2 * pi/3);
@@ -146,10 +146,13 @@ function [h, output] = firstOrderDma(freq, d, pPattern, beta, input)
     end
 
 
+    % Calculate array manifolds (per frequency)
+    arrManMtx(:, 2, :) = arrManLoc(pPattern, d, freq, 343);
+    arrManMtx(:, 1, :) = arrManLoc(0, d, freq, 343);
+
     % Calculate filter(s)
-    for freqIdx = length(freq):-1:1
-        arrManLocMtx = [arrManLoc(0, d, freq(freqIdx), 343), arrManLoc(pPattern, d, freq(freqIdx), 343)];
-        h(:, freqIdx) = (arrManLocMtx')\[1; beta];
+    for fIdx = length(freq):-1:1
+        h(:, fIdx) = (arrManMtx(:, :, fIdx)')\[1; beta];
     end
 
 
@@ -158,10 +161,10 @@ function [h, output] = firstOrderDma(freq, d, pPattern, beta, input)
     % ====================================================
     if nargout > 1 && ~isempty(input)
         % Go through the frequencies
-        for freqIdx = length(freq):-1:1
+        for fIdx = length(freq):-1:1
             for pairIdx = size(input, 1)/2:-1:1
                 % Multiply the array filter with the input
-                output(pairIdx, :, freqIdx) = h(:, freqIdx)' * input(pairIdx * 2 - 1:pairIdx * 2, :, freqIdx);
+                output(pairIdx, :, fIdx) = h(:, fIdx)' * input(pairIdx * 2 - 1:pairIdx * 2, :, fIdx);
             end
         end
     else
@@ -173,6 +176,6 @@ end
 %% Utility functions
 % Calculate the array manifold
 function am = arrManLoc(phi, d, freq, c)
-    k = -2j * pi * freq * cos(phi)/c;
+    k = -2j * pi * freq * cos(phi)/c; k = k(:).';
     am = [exp(k * (-d/2)); exp(k * (d/2))];
 end
\ No newline at end of file
-- 
GitLab