%% Component for the 2D-FFT.
%
%  INPUTS
%   measData: input matrix of input data of selected frame
%   SpdoCorrection: calibration matrix
%   PRS_h1D: Hamming window for the first FFT
%   PRS_h2D: Hamming window for the second FFT
%   K: number of chirps
%   N: number of samples
%   nrRx: number of RX antennas
%
%  OUTPUTS
%   Fft2D_permuted: matrix of 2D-FFT of input data

function Fft2D_permuted = FFT_2D(measData, SpdoCorrection, PRS_h1D, PRS_h2D,...
    K, N, nrRx)
    % just to match the dimensions needed
    VideoChirp2D = permute(measData,[2 1 3]);
    
    FirstFftData = 16*fft(double(VideoChirp2D).*repmat(PRS_h1D',1,K,nrRx)...
        ,N,1)/N;
    
    % discard negative range bins
    % range x doppler x channel
    ComplexFft2D = 16*fft(double(FirstFftData(1:N/2,:,:)).*repmat(PRS_h2D,...
        N/2,1,nrRx),K,2)/K;
    % calibration 
    Fft2D_temp = ComplexFft2D.*(repmat(SpdoCorrection,[N/(2),K,1]));
    
    % just to match the dimensions needed
    Fft2D_permuted = permute(Fft2D_temp,[2 1 3]);
end