comparison dsp/smooth_with.m @ 32:c3b0cd708782

Imported core dsp tools.
author samer
date Sun, 20 Jan 2013 13:48:47 +0000
parents
children
comparison
equal deleted inserted replaced
31:8cc4f326fc66 32:c3b0cd708782
1 function Z=smooth_with(h,i,Y)
2 % smooth_with - Smooth a signal by convolution without changing length
3 %
4 % smooth_with :: [[M]], 1..M, [[N]] -> [[N]].
5
6 m=length(h);
7 h=stoch(h(:))';
8 csh=cumsum(h);
9 rsh=fliplr(cumsum(fliplr(h)));
10
11 if isvector(Y), Z=sm(Y);
12 else Z=maprows(@sm,Y);
13 end
14
15 function z=sm(y)
16 z=conv(h,y); % complete convolution
17 z=z(i:end-(m-i)); % trim the ends
18
19 % rescale end bits
20 z(1:m-i)=z(1:m-i)./csh(i:end-1);
21 z(end-i+2:end)=z(end-i+2:end)./rsh(2:i);
22 end
23
24 end