function [RBG,COF]=FindFilter(NAME,flag,RBG_range,COF_range)

RBG=nan;
COF=nan;
Error=inf;

switch flag
    case 'H'
        file='%s/H_%i_%idb.mat';
    case 'H9'
        file='%s/H_%i_%idb.mat';
    case 'HRR'
        file='%s/H_%i_%idb.mat';
    case 'HRR9'
        file='%s/H_%i_%idb.mat';
    otherwise
        disp('Invalid flag');
        return
end
load([NAME '.mat'])


for i=COF_range
    for j=RBG_range
        F=sprintf(file,NAME,i,j);
        if exist(F,'file')
            load(F)
            M=HistSigmas([R.F_RatioR],false);
            E=M(4,3)-M(4,1);
            if (Error>E)&&(M(4,1)<E.p)&&(E.p<M(4,3))
                Error=E
                COF=i;
                RBG=j;
            end
        else
            disp(['Warning ' F ' is mising'])
        end
    end
end
