samer@32: function Z=smooth_with(h,i,Y) samer@32: % smooth_with - Smooth a signal by convolution without changing length samer@32: % samer@32: % smooth_with :: [[M]], 1..M, [[N]] -> [[N]]. samer@32: samer@32: m=length(h); samer@32: h=stoch(h(:))'; samer@32: csh=cumsum(h); samer@32: rsh=fliplr(cumsum(fliplr(h))); samer@32: samer@32: if isvector(Y), Z=sm(Y); samer@32: else Z=maprows(@sm,Y); samer@32: end samer@32: samer@32: function z=sm(y) samer@32: z=conv(h,y); % complete convolution samer@32: z=z(i:end-(m-i)); % trim the ends samer@32: samer@32: % rescale end bits samer@32: z(1:m-i)=z(1:m-i)./csh(i:end-1); samer@32: z(end-i+2:end)=z(end-i+2:end)./rsh(2:i); samer@32: end samer@32: samer@32: end