function f = build_powerlaw_tf(gain, corner_points)
%BUILD_POWERLAW_TF Builds a transfer function following a power law.
%   For each power of f, take a crossing point as (f, dbmag)
%   Parameters:
%    - gain: magnitude (in dB) of the f^0 floor.
%    - corner_points: transition points from f^n to f^(n-1)

arguments
    gain (1,1) {mustBeNumeric, mustBeReal, mustBeNonNan}
    corner_points (1,:) {mustBePositive}
end

corner_points = sort(corner_points, 'descend');
gain = [gain, zeros(1, numel(corner_points)-1)];

f = 0;
if isfinite(gain)
    f = f + tf(db2mag(gain(1)), 1); % white f^0 floor
end
for i = 1:numel(corner_points)
    if i > 1
        gain(i) = gain(i-1) + 20 * (i-1) * log10(corner_points(i-1) / corner_points(i));
    end

    f = f + tf(db2mag(gain(i)) * corner_points(i)^i, [1, zeros(1, i)]);
end
end