function[a_resp, a_pos, a_neg] = arbit_engine(a1,a2,b1,b2,b3,yy)
% Fast, stable scalar 2nd-order IIR recursion
% a1,a2,b1,b2,b3 are 1×1 scalars
% yy is the input vector

    yy = yy(:);
    N  = length(yy);

    a_resp = zeros(N,1);

    % Handle first sample
    y1 = 0;     % y[n-1]
    y2 = 0;     % y[n-2]
    x1 = 0;
    x2 = 0;

    % n = 1
    x0 = yy(1);
    y  = b1*x0 + b2*x1 + b3*x2;
    a_resp(1) = y;

    % update states
    y2 = y1;  
    y1 = y;
    x2 = x1;
    x1 = x0;

    if N >= 2
        % n = 2
        x0 = yy(2);
        y  = b1*x0 + b2*x1 + b3*x2 + a1*y1 + a2*y2;
        a_resp(2) = y;

        y2 = y1;
        y1 = y;
        x2 = x1;
        x1 = x0;
    end

    % MAIN LOOP (n >= 3)
    for n = 3:N
        x0 = yy(n);
        % Fully valid DF-I recursion, all scalar, no illegal indexing
        y  = b1*x0 + b2*x1 + b3*x2 + a1*y1 + a2*y2;
        a_resp(n) = y;

        % shift x, y states
        x2 = x1;
        x1 = x0;

        y2 = y1;
        y1 = y;
    end

    a_pos = abs(max(a_resp));
    a_neg = abs(min(a_resp));

    a_resp = fix_size(a_resp);
end
