function p=v_stoi2prob(s,m)
%V_STOI2PROB convert STOI to probability
%
%  Inputs:  S(M,N)       matrix containing STOI values
%           M            mapping: 'i' IEEE sentences [default]
%                                 'd' Dantale corpus
%
% Outputs:  P(M,N)       Corresponding probability values
%
% STOI is an intelligibility metric described in [1]. The
% mapping from STOI to intelligibilty is corpus-dependent:
% this functions implements two mappings given in [1].
%
% [1]	C. H. Taal, R. C. Hendriks, R. Heusdens, and J. Jensen.
%       An algorithm for intelligibility prediction of time-frequency weighted noisy speech.
%       IEEE Trans. Audio, Speech, Language Processing, 19 (7): 2125-2136, 2011.
%       doi: 10.1109/TASL.2011.2114881.

%      Copyright (C) Mike Brookes 2014
%      Version: $Id: v_stoi2prob.m 10865 2018-09-21 17:22:45Z dmb $
%
%   VOICEBOX is a MATLAB toolbox for speech processing.
%   Home page: http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%   This program is free software; you can redistribute it and/or modify
%   it under the terms of the GNU Lesser General Public License as published by
%   the Free Software Foundation; either version 3 of the License, or
%   (at your option) any later version.
%
%   This program is distributed in the hope that it will be useful,
%   but WITHOUT ANY WARRANTY; without even the implied warranty of
%   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%   GNU Lesser General Public License for more details.
%
%   You can obtain a copy of the GNU Lesser General Public License from
%   https://www.gnu.org/licenses/ .
%    See files gpl-3.0.txt and lgpl-3.0.txt included in this distribution.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if nargin<2 || ~numel(m) || m(1)=='i'
    a=-17.4906;
    b=9.6921;
    if ~nargin
        s=[];
    end
else
    a=-14.5435;
    b=7.0792;
end
p=1./(1+exp(a*s+b));
if ~nargout
    if ~nargin
        s=linspace(0,1,100);
    end
    plot(s,v_stoi2prob(s,'d'),':k',s,v_stoi2prob(s,'i'),'-k')
    xlabel('STOI');
    ylabel('Intelligibility');
    legend('Dantale corpus','IEEE sentences','location','best');
end