Code covered by the BSD License  

Highlights from
Interactive Smoothing

image thumbnail
from Interactive Smoothing by Tom O'Haver
Interactive smoothing for time-series signals

smoothwidth. Faster than % convolution for smooth widths above 500 points. % T. C. O'Haver, 2008. w=round(smoothwidth); SumPoints=sum(Y(1:w)); % s=zeros(size(Y)); halfw=round(w/2); for k=1:length(Y)-w, s(k+halfw)=SumPoints./w; SumPoints=SumPoints-
function SmoothY=fastbsmooth2(Y,smoothwidth)
% fastbsmooth(Y,w) smooths vector Y by unweighted sliding-average
% (boxcar) smooth of width = smoothwidth. Faster than 
% convolution for smooth widths above 500 points.
%  T. C. O'Haver, 2008.
w=round(smoothwidth);
SumPoints=sum(Y(1:w));
% s=zeros(size(Y));
halfw=round(w/2);
for k=1:length(Y)-w,
   s(k+halfw)=SumPoints./w;
   SumPoints=SumPoints-Y(k);
   SumPoints=SumPoints+Y(k+w);
end
SmoothY=s;
startpoint=(smoothwidth + 1)/2;
L=length(Y);
SmoothY(1)=(Y(1)+Y(2))./2;
for k=2:startpoint,
    SmoothY(k)=mean(Y(1:(2*k-1)));
    SmoothY(L-k+1)=mean(Y(L-2*k+2:L));
end
SmoothY(L)=(Y(L)+Y(L-1))./2;

Contact us at files@mathworks.com