samer@0: function Y=unbuffer(X,hop) samer@0: % UNBUFFER - Opposite of buffer using overlap and add (for sequences) samer@0: % samer@0: % Usage: x=unbuffer(X,hop) samer@0: % X: sequences of [[N]] frames of signal data samer@0: % hop: Determines how much overlap there is between neighbouring frames samer@0: samer@0: samer@0: if isa(hop,'data') samer@0: Y=zipaccum(@olap2,[],{hop,X}); samer@0: else samer@0: if isscalar(hop) samer@0: N=max(size(X)); samer@0: ol=N-hop; samer@0: if ol<=hop samer@0: I=1:hop; J=1:ol; K=hop+1:N; samer@0: Y=sfndata(@olap1,zeros(ol,1),X); samer@0: else samer@0: I=1:hop; J=hop+1:ol; K=ol+1:N; samer@0: Y=sfndata(@olap3,zeros(ol,1),X); samer@0: end samer@0: else samer@0: Y=zipaccum(@olap2,[],{windowdata(repeat(hop)),X}); samer@0: end samer@0: end samer@0: samer@0: function [y,s1]=olap1(x,s) samer@0: y=x(I)'; samer@0: y(J)=y(J)+s'; samer@0: s1=x(K); samer@0: end samer@0: samer@0: function [y,s1]=olap3(x,s) samer@0: y=(s(I)+x(I))'; samer@0: s1=[s(J)+x(J);x(K)]; samer@0: end samer@0: samer@0: function [y,s1]=olap2(hop,x,s) samer@0: ls=length(s); samer@0: lx=length(x); samer@0: if lx>=hop samer@0: if ls>=hop samer@0: % NB: this will fail if ls>lx, but this shouldn't happen since ls<=lx-hop samer@0: y=(x(1:hop)+s(1:hop))'; samer@0: s1=[s(hop+1:ls)+x(hop+1:ls);x(ls+1:end)]; samer@0: else samer@0: y=[x(1:ls)+s;x(ls+1:hop)]'; samer@0: s1=x(hop+1:end); samer@0: end samer@0: else samer@0: if ls>=hop samer@0: y=[s(1:lx)+x;s(lx+1:hop)]'; samer@0: s1=s(hop+1:end); samer@0: else samer@0: y=zeros(1,hop); samer@0: y(1:ls)=y(1:ls)+s'; samer@0: y(1:lx)=y(1:lx)+x'; samer@0: end samer@0: end samer@0: samer@0: % y=x(1:hop)'; samer@0: % ch=min(hop,ls); samer@0: % J=(1:ch)'; samer@0: % y(J)=y(J)+s(J)'; samer@0: % s1=x(hop+1:end)+[s(ch+1:end);zeros(lx-max(hop,ls),1)]; samer@0: end samer@0: end samer@0: