diff sequences/@seq/unbuffer.m @ 3:3f77126f7b5f

First major revision of sequence library, now using classdef form, STILL A BIT BROKEN!
author samer
date Wed, 09 Jan 2013 22:22:21 +0000
parents
children 79038cbcce00
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sequences/@seq/unbuffer.m	Wed Jan 09 22:22:21 2013 +0000
@@ -0,0 +1,36 @@
+% unbuffer - Opposite of buffer using overlap and add (for sequences)
+%
+% unbuffer :: 
+%    seq([[N]])  ~'sequence of overlapping frames',
+%    M:natural   ~'hop size'
+% -> seq([[1,M]])~'sequence of de-overlapped frames'.
+%
+% NB. what about windowing function?
+
+function Y=unbuffer(X,hop)
+	if isscalar(hop)
+		N=max(size(X));
+		ol=N-hop;
+		if ol<=hop
+			I=1:hop; J=1:ol; K=hop+1:N;
+			Y=mapaccum(@olap1,X,zeros(ol,1));
+		else
+			I=1:hop; J=hop+1:ol; K=ol+1:N;
+			Y=mapaccum(@olap3,X,zeros(ol,1));
+		end
+	else
+		Y=zipaccum(@olap2,{windowdata(repeat(hop)),X},[]);
+	end
+
+	function [y,s1]=olap1(x,s)
+		y=x(I)';
+		y(J)=y(J)+s';
+		s1=x(K);
+	end
+
+	function [y,s1]=olap3(x,s)
+		y=(s(I)+x(I))';
+		s1=[s(J)+x(J);x(K)];
+	end
+end
+