function [f1,f2] = freqspace(n,flag)
%MATLAB Code Generation Library Function

%   Copyright 1984-2016 The MathWorks, Inc.
%#codegen

eml_invariant(nargin>0, ...
    'MATLAB:minrhs');
eml_invariant(eml_is_const(size(n)), ...
    'Coder:toolbox:freqspace_2', ...
    'IfNotConst','Fail');
eml_invariant(isvector(n) && (numel(n) == 1 || numel(n) == 2), ...
    'Coder:toolbox:freqspace_3', ...
    'IfNotConst','Fail');
eml_invariant(nargout > 1 || isscalar(n), ...
    'Coder:toolbox:freqspace_4', ...
    'IfNotConst','Fail');
eml_invariant(eml_is_const(n) || eml_option('VariableSizing'), ...
    'Coder:toolbox:freqspace_5', ...
    'IfNotConst','Fail');
eml_invariant(isreal(n), ...
    'Coder:toolbox:freqspace_6', ...
    'IfNotConst','Fail');
eml_invariant(isa(n,'float'), ...
    'Coder:toolbox:unsupportedClass','freqspace',class(n));
eml_invariant(nargin < 2 || coder.internal.isCharOrScalarString(flag), ...
    'Coder:toolbox:freqspace_8', ...
    'IfNotConst','Fail');
if nargout > 1
    if isscalar(n)
        r = floor(coder.internal.div(n,2));
        s = coder.internal.div(2,n);
        if nargin > 1
            a = ((0:n-1) - r)*s;
            [f1,f2] = meshgrid(a);
        else
            f1 = ((0:n-1) - r)*s;
            f2 = f1;
        end
    else
        r1 = floor(coder.internal.div(n(1),2));
        r2 = floor(coder.internal.div(n(2),2));
        s1 = coder.internal.div(2,n(1));
        s2 = coder.internal.div(2,n(2));
        if nargin > 1
            a = ((0:n(2)-1) - r2)*s2;
            b = ((0:n(1)-1) - r1)*s1;
            [f1,f2] = meshgrid(a,b);
        else
            f1 = ((0:n(2)-1) - r2)*s2;
            f2 = ((0:n(1)-1) - r1)*s1;
        end
    end
elseif nargin > 1
    if n < 1
        f1 = zeros(1,0,class(n)); 
    else
        f1 = colon(0,coder.internal.div(2,n),coder.internal.div(2*(n-1),n));
    end
else % nargin == 1 && nargout == 1
    if n <= 0          % [-Inf, 0]
        f1 = zeros(1,0,class(n));
    elseif n < 2      % (0, 2)
        f1 = zeros(class(n));
    else              % (2, Inf]
        f1 = colon(0,coder.internal.div(2,n),1);
    end
end
