Daniel@0: function y=logsum(x,d) Daniel@0: %LOGSUM logsum(x,d)=log(sum(exp(x),d)) Daniel@0: % d gives dimension to sum along Daniel@0: Daniel@0: % Copyright (C) Mike Brookes 1998 Daniel@0: % Daniel@0: % Last modified Mon Oct 12 15:47:25 1998 Daniel@0: % Daniel@0: % VOICEBOX is a MATLAB toolbox for speech processing. Home page is at Daniel@0: % http://www.ee.ic.ac.uk/hp/staff/dmb/voicebox/voicebox.html Daniel@0: % Daniel@0: Daniel@0: if nargin==1 Daniel@0: d=[find(size(x)-1) 1]; Daniel@0: d=d(1); Daniel@0: end Daniel@0: n=size(x,d); Daniel@0: if n<=1, y=x; return; end Daniel@0: s=size(x); Daniel@0: p=[d:ndims(x) 1:d-1]; Daniel@0: z=reshape(permute(x,p),n,prod(s)/n); Daniel@0: Daniel@0: y=max(z); Daniel@0: y=y+log(sum(exp(z-y(ones(n,1),:)))); Daniel@0: Daniel@0: s(d)=1; Daniel@0: y=ipermute(reshape(y,s(p)),p); Daniel@0: