function Z = magPhaseToComplex(model,varargin)
%magPhaseToComplex
% Returns the magnitude and phase of a model as a an array of complex
% numbers for a range of frequencies. If only the model is passed as input,
% the range of frequencies used are the ones from the model, otherwise it
% uses the frequencies passed in the second parameter

%   Project: IMPACT
%   Title of Code: magPhaseToComplex
%   Relevant additional documentation:
%   Developer: Carlos Gonzalez
%   External Dependencies: NA
%
%   Disclaimer
%   CAUTION: It is strongly recommended that changes to this code
%   should be avoided without first consulting with authors.

if nargin>1
    arFreq = varargin{1};
    arMagnitude = interp1(model.arFreq,model.arMagnitude,arFreq);
    arPhase = interp1(model.arFreq,model.arPhase,arFreq);
    Z = arMagnitude.*exp(1i*arPhase*pi/180);
else
    Z = model.arMagnitude.*exp(1i*model.arPhase*pi/180);
end