function sys_truncated = truncate_coeff(sys, threshold)
%TRUNCATE_COEFF Truncates model coefficients smaller in absolute value than threshold
    if isa(sys, 'ss')
        sys.A = truncate(sys.A, threshold);
        sys.B = truncate(sys.B, threshold);
        sys.C = truncate(sys.C, threshold);
        sys.D = truncate(sys.D, threshold);
        sys.E = truncate(sys.E, threshold);
    elseif isa(sys, 'tf')
        cellfun(@(x) truncate(x, threshold), sys.Numerator);
        cellfun(@(x) truncate(x, threshold), sys.Denominator);
    elseif isa(sys, 'zpk')
        sys.K = truncate(K, threshold);
        cellfun(@(x) truncate(x, threshold), sys.P);
        cellfun(@(x) truncate(x, threshold), sys.Z);
    elseif ismatrix(sys)
        sys = truncate(sys, threshold);
    end
    
    sys_truncated = sys;
end

function out = truncate(in, threshold)
    out = in;
    out(abs(in) <= threshold) = 0;
end