function [ F0_mag, F0_phase] = FwtoF0( Fw_mag, Fw_phase, mode )
%FwtoF0 - is function for transformation transfer Fw(closed loop) to F0(open loop)
%   [INPUT]
%   Fw_mag - magnitude of Fw
%   Fw_phase - phase of Fw[rad]
%   mode - overflow control:
%           - Base - without overflow control
%           - OverCheck - with overflow control
%        - if the parameter is empry => computing phase with overflow control
%   [OUTPUT]
%   F0_mag - magnitude of F0
%   F0_phase - phase of F0[rad]

% Trasformation Fw to complex numbers
% Fw_compl = Fw_mag.*exp(1i.*(Fw_phase));
Fw_compl = Fw_mag.*(cos(Fw_phase) + 1i*sin(Fw_phase));

% Calculation F0
F0_compl = Fw_compl./(1-Fw_compl);

F0_mag = abs(F0_compl);

if nargin == 2
    F0_phase = phaseM(F0_compl);    % with overflow control
elseif nargin == 3
    if strcmp(mode,'Base')== true
        F0_phase = phaseE(F0_compl);    % without overflow control
    else
        F0_phase = phaseM(F0_compl);    % with overflow control
    end
end

end