samer@34: function x=blockdata(gen,dur,s0,varargin) samer@34: % blockdata - Signal as a sequence of blocks from signal generator object samer@34: % samer@34: % blockdata :: samer@34: % gen(A,B{1:N}) ~'signal generator object with state A and N params B', samer@34: % seq(natural) ~'number of samples to generate in each block', samer@34: % A ~'initial state', samer@34: % seq(B{1}) ~'sequence of 1st param values', samer@34: % ... samer@34: % seq(B{N}) ~'sequence of Nth param values', samer@34: % -> seq([[1,_]]) ~'heterogenous sequence of arrays'. samer@34: % samer@34: % The main point of this construct is to maintain state samer@34: % between calls to the block method of the signal generator, and samer@34: % also to supply the generator with a sequence of parameter samer@34: % values. samer@34: samer@34: nargs=length(varargin)+1; samer@34: params=cellmap(@dd,varargin); % make sure all input sequences actually are samer@34: perm=[nargs+1,1,2:nargs]; samer@36: x=zipaccum(@blockgen,s0,dd(dur),params{:}); samer@34: samer@34: function [y,state]=blockgen(varargin) samer@34: % this is weird - for some reason Matlab crashes if I call block samer@34: % directly from here, but is ok if I go via the non-nested bblock samer@34: [y,state]=bblock(gen,varargin{perm}); samer@34: end samer@34: samer@34: % function y=blockgen_nostate(theta) samer@34: % y=block(gen,s0,ceil(theta{1}),theta{2:end}); samer@34: % end samer@34: end samer@34: samer@34: function [y,s]=bblock(varargin) samer@34: [y,s]=block(varargin{:}); samer@34: end samer@34: