Mercurial > hg > ishara
diff dsp/smooth_with.m @ 32:c3b0cd708782
Imported core dsp tools.
| author | samer |
|---|---|
| date | Sun, 20 Jan 2013 13:48:47 +0000 |
| parents | |
| children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dsp/smooth_with.m Sun Jan 20 13:48:47 2013 +0000 @@ -0,0 +1,24 @@ +function Z=smooth_with(h,i,Y) +% smooth_with - Smooth a signal by convolution without changing length +% +% smooth_with :: [[M]], 1..M, [[N]] -> [[N]]. + +m=length(h); +h=stoch(h(:))'; +csh=cumsum(h); +rsh=fliplr(cumsum(fliplr(h))); + +if isvector(Y), Z=sm(Y); +else Z=maprows(@sm,Y); +end + +function z=sm(y) + z=conv(h,y); % complete convolution + z=z(i:end-(m-i)); % trim the ends + + % rescale end bits + z(1:m-i)=z(1:m-i)./csh(i:end-1); + z(end-i+2:end)=z(end-i+2:end)./rsh(2:i); +end + +end
