daffv17_effective_bounds.m 868 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
%
%  OpenDAFF
%

function [ lwr, upr ] = daffv17_effective_bounds( fcoeffs, threshold )
%DAFF_EFFECTIVE_BOUNDS Find boundaries of effective 'zones' in impulses
%responses (where filter coefficients are unequal zero)
    
    if ~isvector(fcoeffs), error('Input parameter ''fcoeffs'' must be a vector'); end;
    
    n = length(fcoeffs);
    if (n == 0), error('Input parameter ''fcoeffs'' may not be an empty vector'); end;
    
    x = abs(fcoeffs);
    lwr = 1;
    upr = n;
    
    % Scan from the left
    while (lwr <= n)
        if (x(lwr) >= threshold), break; end;
        lwr = lwr + 1;
    end
    
    % Special case: Everything below threshold
    if (lwr == (n+1))
        lwr = -1;
        upr = -1;
        return;
    end

    % Scan from the right
    while (upr > 1)
        if (x(upr) >= threshold), break; end;
        upr = upr - 1;
    end
end