%% Component for the MUSIC preprocessing.
%
%  INPUTS
%   Fft2D_permuted: matrix with 2D-FFT data
%
%  OUTPUTS
%   targetAntPhasors: 3D matrix with selected phasors
%   targetRangeBin: range bin of selected target

function [targetAntPhasors, targetRangeBin] = AntPhasors(Fft2D_permuted)
    % fftshift through first dimension (rows) - velocity, for the zero
    % velocity to be in the middle of the range
    thisRVData = fftshift(Fft2D_permuted, 1);
    thisRVData(:,1:5,:) = 0;
    % finding at which position of cut R-V plot for 1. antenna does the
    % strongest target is placed (result index is linear)
    [~, indTarget] = max(abs(thisRVData(:, :, 1)), [], 'all', 'linear');
    
    % it is necessarry to convert te linear index to numbers of rows and
    % columns
    [targetSpeedBin,targetRangeBin] = ind2sub(size(thisRVData,[1 2]),indTarget);
    
    % finding, which are the recieved phasors at the corresponding antennas
    % for the detected target
    targetAntPhasors = squeeze(thisRVData(targetSpeedBin, targetRangeBin, :));
   
end