Mercurial > hg > aimmat
view aim-mat/tools/@signal/bin.m @ 0:74dedb26614d
Initial checkin of AIM-MAT version 1.5 (6.4.2011).
author | tomwalters |
---|---|
date | Fri, 20 May 2011 12:32:31 +0100 |
parents | |
children | 20ada0af3d7d |
line wrap: on
line source
% calculate the binned version of the signal function retsig=bin(sig,binwidth) new_sr=1/binwidth; % the sr of the binned signal old_sr=getsr(sig); cvals=getvalues(sig); nrbinspro=old_sr/new_sr; nr_bins=round(getlength(sig)/binwidth); new_val=zeros(nr_bins,1); for k=1:nr_bins start_bin=round((k-1)*nrbinspro+1); stop_bin=round(k*nrbinspro); stop_bin=min(stop_bin,length(cvals)); new_val(k)=sum(cvals(start_bin:stop_bin)); end retsig=signal(new_val); retsig=setsr(retsig,new_sr); retsig=setname(retsig,sprintf('binned signal %s with binwidth %3.2fms',getname(sig),binwidth*1000));