mathieu@14: function s = ebr (fg, bg, offset, fgScale) mathieu@14: % Computes the EBR of fg relatively to bg mathieu@14: % If the optional argument offset is provided, will compute the EBR of fg mathieu@14: % at position 'offset' in bg mathieu@14: % If the optional argument fgScale is provided, the SNR of fg*fgScale over mathieu@14: % bg will be returned instead mathieu@14: mathieu@14: % This program was written by Mathias Rossignol & Grégoire Lafay mathieu@14: % is Copyright (C) 2015 IRCAM mathieu@14: % mathieu@14: % This program is free software: you can redistribute it and/or modify it mathieu@14: % under the terms of the GNU General Public License as published by the Free mathieu@14: % Software Foundation, either version 3 of the License, or (at your option) mathieu@14: % any later version. mathieu@14: % mathieu@14: % This program is distributed in the hope that it will be useful, but mathieu@14: % WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY mathieu@14: % or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mathieu@14: % for more details. mathieu@14: % mathieu@14: % You should have received a copy of the GNU General Public License along mathieu@14: % with this program. If not, see . mathieu@14: mathieu@14: if (nargin<=2) offset=1; end mathieu@14: if (nargin<=3) fgScale=1; end mathieu@14: mathieu@14: endPosBg = min(offset+length(fg)-1, length(bg)); mathieu@14: endPosFg = endPosBg-offset+1; mathieu@14: mathieu@14: aFg = sqrt(sum((fg(1:endPosFg).*fgScale).^2)/endPosFg); %RMS mathieu@14: aBg = sqrt(sum(bg(offset:endPosBg).^2)/endPosFg); %RMS mathieu@14: mathieu@14: s = 20*log10(aFg/(aBg+.001)); mathieu@14: %fprintf('fg from position %i to %i, %i samples, scale = %f, bg pow = %f, fg pow = %f, snr = %f\n', offset, endPosBg, endPosFg, fgScale, aBg, aFg, s); mathieu@14: end