Mercurial > hg > ishara
annotate sequences/@data/unbuffer.m @ 0:672052bd81f8
Initial partial import.
author | samer |
---|---|
date | Wed, 19 Dec 2012 22:38:28 +0000 |
parents | |
children |
rev | line source |
---|---|
samer@0 | 1 function Y=unbuffer(X,hop) |
samer@0 | 2 % UNBUFFER - Opposite of buffer using overlap and add (for sequences) |
samer@0 | 3 % |
samer@0 | 4 % Usage: x=unbuffer(X,hop) |
samer@0 | 5 % X: sequences of [[N]] frames of signal data |
samer@0 | 6 % hop: Determines how much overlap there is between neighbouring frames |
samer@0 | 7 |
samer@0 | 8 |
samer@0 | 9 if isa(hop,'data') |
samer@0 | 10 Y=zipaccum(@olap2,[],{hop,X}); |
samer@0 | 11 else |
samer@0 | 12 if isscalar(hop) |
samer@0 | 13 N=max(size(X)); |
samer@0 | 14 ol=N-hop; |
samer@0 | 15 if ol<=hop |
samer@0 | 16 I=1:hop; J=1:ol; K=hop+1:N; |
samer@0 | 17 Y=sfndata(@olap1,zeros(ol,1),X); |
samer@0 | 18 else |
samer@0 | 19 I=1:hop; J=hop+1:ol; K=ol+1:N; |
samer@0 | 20 Y=sfndata(@olap3,zeros(ol,1),X); |
samer@0 | 21 end |
samer@0 | 22 else |
samer@0 | 23 Y=zipaccum(@olap2,[],{windowdata(repeat(hop)),X}); |
samer@0 | 24 end |
samer@0 | 25 end |
samer@0 | 26 |
samer@0 | 27 function [y,s1]=olap1(x,s) |
samer@0 | 28 y=x(I)'; |
samer@0 | 29 y(J)=y(J)+s'; |
samer@0 | 30 s1=x(K); |
samer@0 | 31 end |
samer@0 | 32 |
samer@0 | 33 function [y,s1]=olap3(x,s) |
samer@0 | 34 y=(s(I)+x(I))'; |
samer@0 | 35 s1=[s(J)+x(J);x(K)]; |
samer@0 | 36 end |
samer@0 | 37 |
samer@0 | 38 function [y,s1]=olap2(hop,x,s) |
samer@0 | 39 ls=length(s); |
samer@0 | 40 lx=length(x); |
samer@0 | 41 if lx>=hop |
samer@0 | 42 if ls>=hop |
samer@0 | 43 % NB: this will fail if ls>lx, but this shouldn't happen since ls<=lx-hop |
samer@0 | 44 y=(x(1:hop)+s(1:hop))'; |
samer@0 | 45 s1=[s(hop+1:ls)+x(hop+1:ls);x(ls+1:end)]; |
samer@0 | 46 else |
samer@0 | 47 y=[x(1:ls)+s;x(ls+1:hop)]'; |
samer@0 | 48 s1=x(hop+1:end); |
samer@0 | 49 end |
samer@0 | 50 else |
samer@0 | 51 if ls>=hop |
samer@0 | 52 y=[s(1:lx)+x;s(lx+1:hop)]'; |
samer@0 | 53 s1=s(hop+1:end); |
samer@0 | 54 else |
samer@0 | 55 y=zeros(1,hop); |
samer@0 | 56 y(1:ls)=y(1:ls)+s'; |
samer@0 | 57 y(1:lx)=y(1:lx)+x'; |
samer@0 | 58 end |
samer@0 | 59 end |
samer@0 | 60 |
samer@0 | 61 % y=x(1:hop)'; |
samer@0 | 62 % ch=min(hop,ls); |
samer@0 | 63 % J=(1:ch)'; |
samer@0 | 64 % y(J)=y(J)+s(J)'; |
samer@0 | 65 % s1=x(hop+1:end)+[s(ch+1:end);zeros(lx-max(hop,ls),1)]; |
samer@0 | 66 end |
samer@0 | 67 end |
samer@0 | 68 |