annotate general/numerical/smooth_with.m @ 6:0ce3c2070089

Removed duplicate code and fixed doc in timed_action.
author samer
date Mon, 14 Jan 2013 14:33:37 +0000
parents e44f49929e56
children
rev   line source
samer@4 1 function Z=smooth_with(h,i,Y)
samer@4 2 % smooth_with - Smooth a signal by convolution without changing length
samer@4 3 %
samer@4 4 % smooth_with :: [[M]], 1..M, [[N]] -> [[N]].
samer@4 5
samer@4 6 m=length(h);
samer@4 7 h=stoch(h(:))';
samer@4 8 csh=cumsum(h);
samer@4 9 rsh=fliplr(cumsum(fliplr(h)));
samer@4 10
samer@4 11 if isvector(Y), Z=sm(Y);
samer@4 12 else Z=maprows(@sm,Y);
samer@4 13 end
samer@4 14
samer@4 15 function z=sm(y)
samer@4 16 z=conv(h,y); % complete convolution
samer@4 17 z=z(i:end-(m-i)); % trim the ends
samer@4 18
samer@4 19 % rescale end bits
samer@4 20 z(1:m-i)=z(1:m-i)./csh(i:end-1);
samer@4 21 z(end-i+2:end)=z(end-i+2:end)./rsh(2:i);
samer@4 22 end
samer@4 23
samer@4 24 end