Mercurial > hg > ishara
annotate dsp/smooth_with.m @ 61:eff6bddf82e3 tip
Finally implemented perceptual brightness thing.
author | samer |
---|---|
date | Sun, 11 Oct 2015 10:20:42 +0100 |
parents | c3b0cd708782 |
children |
rev | line source |
---|---|
samer@32 | 1 function Z=smooth_with(h,i,Y) |
samer@32 | 2 % smooth_with - Smooth a signal by convolution without changing length |
samer@32 | 3 % |
samer@32 | 4 % smooth_with :: [[M]], 1..M, [[N]] -> [[N]]. |
samer@32 | 5 |
samer@32 | 6 m=length(h); |
samer@32 | 7 h=stoch(h(:))'; |
samer@32 | 8 csh=cumsum(h); |
samer@32 | 9 rsh=fliplr(cumsum(fliplr(h))); |
samer@32 | 10 |
samer@32 | 11 if isvector(Y), Z=sm(Y); |
samer@32 | 12 else Z=maprows(@sm,Y); |
samer@32 | 13 end |
samer@32 | 14 |
samer@32 | 15 function z=sm(y) |
samer@32 | 16 z=conv(h,y); % complete convolution |
samer@32 | 17 z=z(i:end-(m-i)); % trim the ends |
samer@32 | 18 |
samer@32 | 19 % rescale end bits |
samer@32 | 20 z(1:m-i)=z(1:m-i)./csh(i:end-1); |
samer@32 | 21 z(end-i+2:end)=z(end-i+2:end)./rsh(2:i); |
samer@32 | 22 end |
samer@32 | 23 |
samer@32 | 24 end |