% plot MCPF for all listeners at both frequencies
function mcpf
fa=0.005;
frq=[1 4];
lev=(0:120)';
[lis,med]=simlis_prepare('coeffdata',lev,fa);
[nlis,nfrq,~,~]=size(lis);
fig=0;
nrow=4;
ncol=5;
for kfrq=1:nfrq
    for klis=1:nlis
        thr=med(klis,kfrq,1); % listener threshold
        lab=sprintf('L=%.0f F=%.0f T=%.0f\n',klis,frq(kfrq),thr);
        pan=1+mod(klis-1,nrow*ncol);
        if (pan==1)
            fig=fig+1;
            figure(fig);clf
        end
        subplot(nrow,ncol,pan)
        mcpf=squeeze(lis(klis,kfrq,:,:));
        plot(lev,mcpf);
        text(5,0.5,lab)
        axis([-5 105 -0.05 1.05])
    end
end
return

%========================================

function [lis,med]=simlis_prepare(dfn,lev,fa)
load(dfn);
nlv=length(lev);
nnh=size(all_coeff1,1);
nhi=size(all_coeff1_HL,1);
ns=nnh+nhi;
coeff=zeros(2,ns,20);
coeff(1,:,:)=[all_coeff1;all_coeff1_HL];
coeff(2,:,:)=[all_coeff4;all_coeff4_HL];
lis=zeros(ns,2,nlv,10);
med=zeros(ns,2,10);
for i=1:2
    for j=1:ns
        C=0;
        for k=1:10
            A=k*fa;
            B=coeff(i,j,k);
            C=coeff(i,j,k+10)+C;
            D=1+(k-10)*fa;
            y=D+(A-D)./(1+(lev./C).^B);
            lis(j,i,:,k)=y;
            med(j,i,k)=C;
        end
    end
end
return
