Mercurial > hg > ishara
changeset 5:8972a4071294
Removing stuff after reorganisation
author | samer |
---|---|
date | Sat, 12 Jan 2013 22:32:08 +0000 |
parents | e44f49929e56 |
children | 0ce3c2070089 |
files | arrows/.DS_Store arrows/@aseq/aseq.m arrows/@aseq/construct.m arrows/@aseq/tostring.m audio/mp3read.m sequences/@bindcat/bindcat.m sequences/@bindcat/extract.m sequences/@bufferdata/bufferdata.m sequences/@bufferdata/hop.m sequences/@bufferdata/subsref.m sequences/@bufferdata/width.m sequences/@cache/cache.m sequences/@celldata/celldata.m sequences/@celldata/seq2cell.m sequences/@concat/concat.m sequences/@concat/extract.m sequences/@concat/source.m sequences/@cycle/cycle.m sequences/@cycle/extract.m sequences/@data/abs.m sequences/@data/binfun.m sequences/@data/binop.m sequences/@data/buffer.m sequences/@data/cat.m sequences/@data/char.m sequences/@data/cos.m sequences/@data/ctranspose.m sequences/@data/cumsum.m sequences/@data/data.m sequences/@data/datafn.m sequences/@data/decons.m sequences/@data/display.m sequences/@data/dispseq.m sequences/@data/double.m sequences/@data/dynfilter.m sequences/@data/end.m sequences/@data/eq.m sequences/@data/exp.m sequences/@data/extract.m sequences/@data/fft.m sequences/@data/filter.m sequences/@data/foldl.m sequences/@data/foreach.m sequences/@data/gather.m sequences/@data/ge.m sequences/@data/gt.m sequences/@data/head.m sequences/@data/horzcat.m sequences/@data/ifft.m sequences/@data/imagesc.m sequences/@data/integrate.m sequences/@data/isfinite.m sequences/@data/isinf.m sequences/@data/isnan.m sequences/@data/ldivide.m sequences/@data/le.m sequences/@data/length.m sequences/@data/limit.m sequences/@data/log.m sequences/@data/log10.m sequences/@data/log2.m sequences/@data/logmap.m sequences/@data/lt.m sequences/@data/magspec.m sequences/@data/map.m sequences/@data/mapaccum.m sequences/@data/max.m sequences/@data/mean.m sequences/@data/merge.m sequences/@data/min.m sequences/@data/minmax.m sequences/@data/minus.m sequences/@data/mldivide.m sequences/@data/mod.m sequences/@data/mrdivide.m sequences/@data/mtimes.m sequences/@data/next.m sequences/@data/numel.m sequences/@data/paren.m sequences/@data/phasespec.m sequences/@data/plot.m sequences/@data/plus.m sequences/@data/power.m sequences/@data/powspec.m sequences/@data/rdivide.m sequences/@data/reshape.m sequences/@data/scanl.m sequences/@data/setsize.m sequences/@data/sin.m sequences/@data/size.m sequences/@data/soundsc.m sequences/@data/specfilt.m sequences/@data/sqrt.m sequences/@data/subsref.m sequences/@data/sum.m sequences/@data/tanh.m sequences/@data/times.m sequences/@data/tostring.m sequences/@data/uminus.m sequences/@data/unbuffer.m sequences/@data/unzip.m sequences/@data/vecop.m sequences/@data/vertcat.m sequences/@data/wienerfilt.m sequences/@data/zip.m sequences/@data/zipwith.m sequences/@ddata/ddata.m sequences/@ddata/headsource.m sequences/@ddata/next_c.m sequences/@ddata/next_nc.m sequences/@ddata/nextsource.m sequences/@ddata/setsource.m sequences/@ddata/source.m sequences/@extractdata/extractdata.m sequences/@filterdata/extract.m sequences/@filterdata/filterdata.m sequences/@filterdata/testfn.m sequences/@fndata/fn.m sequences/@fndata/fndata.m sequences/@iterdata/iterdata.m sequences/@mergedata/mergedata.m sequences/@mergedata/sources.m sequences/@mp3data/channels.m sequences/@mp3data/extract.m sequences/@mp3data/file.m sequences/@mp3data/length.m sequences/@mp3data/mp3data.m sequences/@mp3data/play.m sequences/@mp3data/rate.m sequences/@mp3data/subsref.m sequences/@oggdata/channels.m sequences/@oggdata/extract.m sequences/@oggdata/file.m sequences/@oggdata/length.m sequences/@oggdata/oggdata.m sequences/@oggdata/play.m sequences/@oggdata/rate.m sequences/@oggdata/subsref.m sequences/@rnddata/model.m sequences/@rnddata/rnddata.m sequences/@rnddata/rndstate.m sequences/@scandata/scandata.m sequences/@scandata/scanfn.m sequences/@sfndata/sfn.m sequences/@sfndata/sfndata.m sequences/@sfndata/state.m sequences/@subsampdata/extract.m sequences/@subsampdata/subsampdata.m sequences/@take/extract.m sequences/@take/take.m sequences/@takewhile/extract.m sequences/@takewhile/takewhile.m sequences/@uidata/eventadder.m sequences/@uidata/ready.m sequences/@uidata/uidata.m sequences/@uidata/wait.m sequences/@unfold/fn.m sequences/@unfold/state.m sequences/@unfold/unfold.m sequences/@wavedata/channels.m sequences/@wavedata/extract.m sequences/@wavedata/file.m sequences/@wavedata/length.m sequences/@wavedata/play.m sequences/@wavedata/rate.m sequences/@wavedata/subsref.m sequences/@wavedata/wavedata.m sequences/@windowdata/hop.m sequences/@windowdata/length.m sequences/@windowdata/options.m sequences/@windowdata/position.m sequences/@windowdata/subsref.m sequences/@windowdata/windowdata.m sequences/@zipaccum/fn.m sequences/@zipaccum/sources.m sequences/@zipaccum/state.m sequences/@zipaccum/zipaccum.m sequences/@zipdata/sources.m sequences/@zipdata/zipdata.m sequences/append.m sequences/chunk.m sequences/cumsum_reset.m sequences/diffwith.m sequences/drop.m sequences/dropwhile.m sequences/extract.m sequences/folddata.m sequences/gathern.m sequences/head.m sequences/isdata.m sequences/last.m sequences/meandata.m sequences/next.m sequences/nth1.m sequences/once.m sequences/phasedata.m sequences/scandatacols.m sequences/skip.m sequences/span.m sequences/spanc.m sequences/spectraldata.m sequences/split.m sequences/squirt.m sequences/src_cell.m sequences/src_data.m sequences/src_subseq.m sequences/window.m sequences/window_ns.m sinks/sinkdata.m |
diffstat | 209 files changed, 0 insertions(+), 3188 deletions(-) [+] |
line wrap: on
line diff
--- a/arrows/@aseq/aseq.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -% aseq - arrow to sequence multiple finite generators -% -% aseq :: -% {[N]->arrow(A,B,_)} ~'cell array of arrows' -% -> arrow(A,B,aseq_state). -% - - -function o=aseq(ax) - if iscell(ax) ax=celldata(ax); end - s.arrows=ax; - o=class(s,'aseq',arrow(nargin(head(ax)),nargout(head(ax)))); -end
--- a/arrows/@aseq/construct.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -function u=construct(s,sizes_in) - - current_arrow = head(s.arrows); - remaining_arrows = next(s.arrows); - fprintf('aseq: starting with arrow %s...\n',tostring(current_arrow)); - - nin=nargin(current_arrow); - nout=nargout(current_arrow); - - running=0; - current_unit = construct(current_arrow,sizes_in(1:nin)); - current_proc = current_unit.process; - - u=mkunit(s); - u.sizes_out = current_unit.sizes_out; - u.starting = @starting; - u.stopping = @stopping; - u.dispose = @dispose; - u.get_state = @get_state; - u.set_state = @set_state; - u.process = @proc_nn; - - function starting, current_unit.starting(); running=1; end - function stopping, current_unit.stopping(); running=0; end - function dispose, current_unit.dispose(); end - - function s=get_state, s={current_arrow, remaining_arrows, current_unit.get_state()}; end - function set_state(s), replace_running_unit(s{1},s{2},s{3}); end - - function varargout=proc_nn(varargin) - try - [varargout{1:nout}]=current_proc(varargin{:}); - catch ex - if iseof(ex) && ~isempty(remaining_arrows) - next_arrow=head(remaining_arrows); - fprintf('aseq: continuing with next arrow %s...\n',tostring(next_arrow)); - replace_running_unit(next_arrow, next(remaining_arrows)); - [varargout{1:nout}]=proc_nn(varargin{:}); - else - rethrow(ex); - end - end - end - - function replace_running_unit(a,remaining,state) - if running - current_unit.stopping(); - current_unit.dispose(); - end - current_arrow=a; - current_unit=construct(a,sizes_in(1:nin)); - current_proc=current_unit.process; - remaining_arrows=remaining; - if nargin>2, current_unit.set_state(state); end - if running, current_unit.starting(); end - end -end - -
--- a/arrows/@aseq/tostring.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function s=tostring(a) - s=sprintf('seq(%s)',tostring(a.arrows));
--- a/audio/mp3read.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,205 +0,0 @@ -function [Y,FS,NBITS,OPTS] = mp3read(FILE,N,MONO,DOWNSAMP) -% [Y,FS,NBITS,OPTS] = mp3read(FILE,N,MONO,DOWNSAMP) Read MP3 audio file -% FILE is an MP3 audio file name. Optional scalar N limits the number -% of frames to read, or, if a two-element vector, specifies -% the first and last frames to read. -% Optional flag MONO forces result to be mono if nonzero; -% Optional factor DOWNSAMP performs downsampling by 2 or 4. -% Y returns the audio data, one channel per column; FS is the -% sampling rate. NBITS is the bit depth (always 16). -% OPTS.fmt is a format info string. -% 2003-07-20 dpwe@ee.columbia.edu This version calls mpg123. -% 2004-08-31 Fixed to read whole files correctly -% 2004-09-08 Uses mp3info to get info about mp3 files too -% 2004-09-18 Reports all mp3info fields in OPTS.fmt; handles MPG2LSF sizes -% + added MONO, DOWNSAMP flags, changed default behavior. - -if nargin < 2 - N = 0; -else - if length(N) == 1 - % Specified N was upper limit - N = [1 N]; - end -end -if nargin < 3 - forcemono = 0; -else - forcemono = (MONO ~= 0); -end -if nargin < 4 - downsamp = 1; -else - downsamp = DOWNSAMP; -end -if downsamp ~= 1 & downsamp ~= 2 & downsamp ~= 4 - error('DOWNSAMP can only be 1, 2, or 4'); -end - -%%%%%%% Hard-coded behavior -%% What factor should we downsample by? (1 = no downsampling, 2 = half, 4=qtr) -%downsamp = 4; -%% Do we want to force the data to be single channel? (1 = yes, 0= keep orig) -%forcemono = 1; - -%%%%%% Location of the binaries -% SA: removed directory parts - let OS find them -mpg123 = 'mpg123'; -mp3info = 'mp3info'; - -%%%%%% Constants -NBITS=16; - -%%%%%% Probe file to find format, size, etc. using "mp3info" utility -% SA: removed bitrate query as VBR mp3 break the code -%cmd = [mp3info, ' -p "%Q %u %r %v * %C %e %E %L %O %o %p" "', FILE,'"']; -cmd = [mp3info, ' -p "%Q %u %v * %C %e %E %L %O %o %p" "', FILE,'"']; -% Q = samprate, u = #frames, r = bitrate, v = mpeg version (1/2/2.5) -% C = Copyright, e = emph, E = CRC, L = layer, O = orig, o = mono, p = pad -w = mysystem(cmd); -% Break into numerical and ascii parts by finding the delimiter we put in -starpos = findstr(w,'*'); -nums = str2num(w(1:(starpos - 2))); -strs = tokenize(w((starpos+2):end)); - -SR = nums(1); -nframes = nums(2); -nchans = 2 - strcmp(strs{6}, 'mono'); -layer = length(strs{4}); -% bitrate = nums(3)*1000; -mpgv = nums(3); -% Figure samples per frame, after -% http://board.mp3-tech.org/view.php3?bn=agora_mp3techorg&key=1019510889 -if layer == 1 - smpspfrm = 384; -elseif SR < 32000 & layer ==3 - smpspfrm = 576; - if mpgv == 1 - error('SR < 32000 but mpeg version = 1'); - end -else - smpspfrm = 1152; -end - -%OPTS.fmt.mpgBitrate = bitrate; -OPTS.fmt.mpgVersion = mpgv; -% fields from wavread's OPTS -%OPTS.fmt.nAvgBytesPerSec = bitrate/8; -OPTS.fmt.nSamplesPerSec = SR; -OPTS.fmt.nChannels = nchans; -%OPTS.fmt.nBlockAlign = smpspfrm/SR*bitrate/8; -OPTS.fmt.nBitsPerSample = NBITS; -OPTS.fmt.mpgNFrames = nframes; -OPTS.fmt.mpgCopyright = strs{1}; -OPTS.fmt.mpgEmphasis = strs{2}; -OPTS.fmt.mpgCRC = strs{3}; -OPTS.fmt.mpgLayer = strs{4}; -OPTS.fmt.mpgOriginal = strs{5}; -OPTS.fmt.mpgChanmode = strs{6}; -OPTS.fmt.mpgPad = strs{7}; -OPTS.fmt.mpgSampsPerFrame = smpspfrm; - -if SR == 16000 & downsamp == 4 - error('mpg123 will not downsample 16 kHz files by 4 (only 2)'); -end - -% SA: -1 causes mono output -if downsamp>1, - downsampstr = [' -',num2str(downsamp)]; -else - downsampstr = ''; -end - -FS = SR/downsamp; - -if forcemono == 1 - nchans = 1; - chansstr = ' -m'; -else - chansstr = ''; -end - -% Size-reading version -if strcmp(N,'size') == 1 - % SA: fixed this (actually, it's still wrong most of the time...) - Y = [smpspfrm*ceil(nframes/downsamp), nchans]; -% Y = [floor(smpspfrm*nframes/downsamp), nchans]; -else - - % Temporary file to use - tmpfile = ['/tmp/tmp',num2str(round(1000*rand(1))),'.wav']; - - skipx = 0; - skipblks = 0; - skipstr = ''; - sttfrm = N(1)-1; - if sttfrm > 0 - skipblks = floor(sttfrm*downsamp/smpspfrm); - skipx = sttfrm - (skipblks*smpspfrm/downsamp); - skipstr = [' -k ', num2str(skipblks)]; - end - - lenstr = ''; - endfrm = -1; - if length(N) > 1 - endfrm = N(2); - if endfrm > sttfrm - decblk = 1+ceil(endfrm*downsamp/smpspfrm) - skipblks; - lenstr = [' -n ', num2str(decblk)]; - end - end - % Run the decode - cmd=[mpg123, downsampstr, chansstr, skipstr, lenstr, ' -q -w ', tmpfile, ' ', '"',FILE,'"']; - %disp(cmd); - mysystem(cmd); - - % Load the data - [Y,SR] = wavread(tmpfile); - - %fprintf('%d blocks decoded producing %d samples.\n',decblk,length(Y)); - % Delete tmp file - mysystem(['rm ', tmpfile]); - - % Select the desired part - if endfrm > sttfrm - Y = Y(skipx+[1:(endfrm-sttfrm)],:); - elseif skipx > 0 - Y = Y((skipx+1):end,:); - end - -end - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function w = mysystem(cmd) -% Run system command; report error; strip all but last line -[s,w] = system(cmd); -if s ~= 0 - error(['unable to execute ',cmd]); -end -% Keep just final line -w = w((1+max([0,findstr(w,10)])):end); -% Debug -%disp([cmd,' -> ','*',w,'*']); - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -function a = tokenize(s) -% Break space-separated string into cell array of strings -% 2004-09-18 dpwe@ee.columbia.edu -a = []; -p = 1; -n = 1; -l = length(s); -nss = findstr([s(p:end),' '],' '); -for ns = nss - % Skip initial spaces - if ns == p - p = p+1; - else - if p <= l - a{n} = s(p:(ns-1)); - n = n+1; - p = ns+1; - end - end -end -
--- a/sequences/@bindcat/bindcat.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -function o=bindcat(X,F,varargin) -% bindcat - sort of monadic bind for sequences. -% -% bindcat :: -% data A ~ 'the first sequence', -% (data A->data A)~ 'function to return second sequence given last element of first' -% -> data A ~ 'resultant sequence'. -% -% The resulting sequence consists of the entire sequence represented by the -% first parameter, followed by the sequence obtained by applying the second -% parameter to the last nonempty element of the first sequence. -% -% Example: -% -% gather(2,bindcat(celldata({1,2,3,4}),@(x)take(head(x),0))) -% -% ans = 1 2 3 4 0 0 0 0 - - -if nargin==0, o=bindcat(0,@id); -elseif nargin==1 && isa(sources,'bindcat'), o=elems; -else - if isempty(X), o=F(X); % degenerate case - else - o.nfn=F; - o=class(o,'bindcat',ddata(X,size(X), ... - 'datafn',@datafn,'charfn',@stringfn,'nextfn',@nextfn, ... - varargin{:})); - end -end - - -function x=datafn(o), x=headsource(o); -function s=stringfn(o), s=sprintf('%s >>= %s',tostring(source(o)),char(o.nfn)); -function o1=nextfn(o), - o1=next_c(o); - if isempty(o1), o1=o.nfn(source(o)); end - - - -
--- a/sequences/@bindcat/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array - -y=extract(o.source,dim,range);
--- a/sequences/@bufferdata/bufferdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,50 +0,0 @@ -function a=bufferdata(source,L,varargin) -% bufferdata - collect elements of sequence into sequence of arrays -% -% bufferdata :: -% data [[N]] ~'source signal', -% L:natural ~'buffer width', -% -> data [[N,L]]. ~'buffered sequence (no-overlapping)'. - - -if nargin==1 && isa(source,'bufferdata'), a=source; -elseif nargin==0, a=bufferdata([],1); -else - sz=size1(source); - - a.dim = length(sz)+1; - a.width = L; - [a.buf,source] = readcat(a.dim,source,L); - - if isempty(a.buf), a=[]; - else - % sort out function table - ft.datafn=@datafn; - ft.stringfn=@stringfn; - ft.nextfn = @nextfn; - - a=class(a,'bufferdata',ddata(source,[sz L],ft)); - end -end - -function s=stringfn(a), s=sprintf('buffer(%d)',a.width); -function x=datafn(a), x=a.buf; -function a=nextfn(a) - % read next lot of values and make an array - src=source(a); - [a.buf,src]=readcat(a.dim,source(a),a.width); - if isempty(a.buf), a=[]; - else - a=setsource(a,src); - %!! what if i<L? - %a.length=size(source(a),a.dim); - end - -function [buf,src]=readcat(dim,src,L) - buf=[]; - for i=1:L - if isempty(src), break; end - buf=cat(dim,buf,head(src)); - src=next(src); - end -
--- a/sequences/@bufferdata/hop.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function h=hop(o) -% HOP - Return hop size for windowed data object -h=o.hop; -
--- a/sequences/@bufferdata/subsref.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -function y=subsref(a,S) -% subsref - subsref for bufferdata - -switch S(1).type -case '()', y=paren(a,S(1)); -end - -if length(S)>1, y=subsref(y,S(2:end)); end - -
--- a/sequences/@bufferdata/width.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function h=width(o) -% width - return width of buffers -h=o.width; -
--- a/sequences/@cache/cache.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -function o=cache(source) -% CACHE- Cache each buffer to speed up multiple reads -% -% cache :: seq A -> seq A. -% -% The idea is that the data is cached on each call to NEXT, -% so that reading the array does not require calls to source. - -if nargin==0, o=cache(0); -elseif isa(source,'cache'), o=source; -else - ft.datafn=@datafn; - ft.stringfn=@stringfn; - ft.nextfn=@cachenext; - o.x=head(source); - o=class(o,'cache',ddata(source,size(source),ft)); -end - -function x=datafn(o), x=o.x; -function s=stringfn(o), s='cache'; -function o=cachenext(o) - o=next_c(o); - if ~isempty(o), o.x=head(source(o)); end - -
--- a/sequences/@celldata/celldata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -function o=celldata(elems,varargin) -% CELLDATA - Convert cell array directly to sequence -% -% celldata :: -% {[L]->[[[N,M]]A} ~ 'cell array of L N-by-M arrays', -% -> data [[N,M]]. ~ 'resultant sequence'. - - -if nargin==1 && isa(elems,'celldata'), o=elems; -elseif nargin==0, o=celldata({[]}); -elseif isempty(elems), o=[]; -else - o.elems=elems; - ft.datafn=@datafn; - ft.charfn=@stringfn; - ft.nextfn=@nextfn; - - o=class(o,'celldata',data(size(elems{1}),ft)); -end - -function x=datafn(o), x=o.elems{1}; -function s=stringfn(o), s=sprintf('celldata(%d)',length(o.elems)); -function o=nextfn(o), - if length(o.elems)>1, o.elems=o.elems(2:end); - else o=[]; - end - if ~isempty(o), - h=o.elems{1}; - if isa(h,'data') - o=setsize(o,[1,1]); - else - o=setsize(o,size(o.elems{1})); - end - end - - - -
--- a/sequences/@celldata/seq2cell.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -function Y=seq2cell(X) -% seq2cell - gather elements of sequence into a cell array -% -% seq2cell :: data A -> {[N]->A}. -% -% Note: this version is an optimised version for celldata -Y=X.elems;
--- a/sequences/@concat/concat.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,54 +0,0 @@ -function o=concat(sources,varargin) -% concat - Concatenate sequences -% -% concat :: -% seq (seq A) ~ 'sequence of sequences' -% -> seq A ~ 'resultant sequence'. -% -% concat :: -% {[N]->seq A} ~ 'cell array of N data objects', -% -> seq A ~ 'resultant sequence'. - - -if nargin==0, o=concat(repeat(0)); -elseif nargin==1 && isa(sources,'concat'), o=elems; -else - if iscell(sources), sources=celldata(sources); end - if isempty(sources), o=[]; return; end - - hd=head(sources); - while isempty(hd) - sources=next(sources); - if isempty(sources), o=[]; return; end - hd=head(sources); - end - o.current=hd; - o.sources=next(sources); - ft.datafn=@datafn; - ft.charfn=@stringfn; - ft.nextfn=@nextfn; - - o=class(o,'concat',data(size(o.current),ft)); -end - - -function x=datafn(o), x=head(o.current); -function s=stringfn(o), s=sprintf('concat(%s|...)',tostring(o.current)); -function o=nextfn(o), - s1=next(o.current); - if ~isempty(s1), - o.current=s1; - o=setsize(o,size(o.current)); - else - if isempty(o.sources), o=[]; return; end - - hd=head(o.sources); - while isempty(hd) - o.sources=next(o.sources); - if isempty(o.sources), o=[]; return; end - hd=head(o.sources); - end - o.current=hd; - o.sources=next(o.sources); - o=setsize(o,size(hd)); - end
--- a/sequences/@concat/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array - -y=extract(o.current,dim,range);
--- a/sequences/@concat/source.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function s=source(o), s=o.current;
--- a/sequences/@cycle/cycle.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -function o=cycle(source) -% cycle - cycles through input sequence repeatedly -% -% cycle :: seq A -> seq A. - -if nargin==0 - o=cycle(singleton(0)); -elseif isa(source,'cycle') - o=source -elseif isempty(source), o=[] -else - ft.stringfn=@stringfn; - ft.datafn=@datafn; - ft.nextfn=@nextfn; - o=class(struct('head',source),'cycle',ddata(source,size(source),ft)); -end - -function x=datafn(o), x=head(source(o)); -function s=stringfn(o), s='cycle'; -function o1=nextfn(o), - o1=next_c(o); - if isempty(o1), - o1=setsize(setsource(o,o.head),size(o.head)); - end
--- a/sequences/@cycle/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array - -y=extract(source(o),dim,range);
--- a/sequences/@data/abs.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function y=abs(x) - -y=fndata(@abs,x,'size',size(x));
--- a/sequences/@data/binfun.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -function o=binfun(A,B,fn,op) -% BINFUN - Apply binary function to one or two sequences -% -% Three cases: -% binfun :: seq A, seq B, (A,B->C), string -> seq C -% binfun :: A, seq B, (A,B->C), string -> seq C -% binfun :: seq A, B, (A,B->C), string -> seq C - - if isa(A,'data'), - if isa(B,'data'), - o=zipdata(fn,2,A,B,'charfn',@zipcharfn); - else - o=fndata( @(x)fn(x,B), A, ... - 'charfn',bind(@charfn,'.',tostring(B))); - end - else - o=fndata( @(y)fn(A,y), B, ... - 'charfn',bind(@charfn,tostring(A),'.')); - end - - function s=zipcharfn(o) - s=sprintf('{ %s, %s } >> %s',tostring(sources(o,1)),tostring(sources(o,2)),op); - end - - function s=charfn(a,b,o) - s=sprintf('%s >> %s(%s,%s)',tostring(source(o)),op,a,b); - end -end
--- a/sequences/@data/binop.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -function o=binop(A,B,fn,op) -% BINOP - Binary operation -% -% binop :: seq A, seq B, (A,B->C), string -> seq C. -% -% Three cases -% A is data, B is an array -% A is array, B is data - - if isa(A,'data'), - if isa(B,'data'), - o=zipdata(fn,2,A,B,'charfn',@zipcharfn); - else - o=fndata(@(x)fn(x,B), A, 'charfn',bind(@charfn,'',tostring(B))); - end - else - o=fndata(@(y)fn(A,y),B, 'charfn',bind(@charfn,tostring(A),'')); - end - - function s=zipcharfn(o) - s=sprintf('{ %s, %s } >> %s',tostring(sources(o,1)),tostring(sources(o,2)),op); - end - - function s=charfn(a,b,o) - s=sprintf('%s >> (%s%s%s)',tostring(source(o)),a,op,b); - end -end
--- a/sequences/@data/buffer.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -function o=buffer(source,n,m,varargin) -% BUFFER - Buffer abstract data object -% -% buffer :: (source:data, frame:natural, overlap:natural)->data -% Works exactly like the usual buffer function but when applied -% to a data object, returns a fndata object. - -args=[{n,m} varargin]; -o=fndata(@(z)buf(args,z),source,'charfn',@(o)charfn(n,n-m,o)); - -function x=buf(args,y) - x=buffer(y,args{:}); - -function s=charfn(n,m,o) - s=sprintf('%s >> buffer(%d/%d)',tostring(source(o)),n,m);
--- a/sequences/@data/cat.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -function o=cat(dim,varargin) -% CAT - array concatenation for data sequences - -if length(varargin)==2 - o=binfun(varargin{1},varargin{2},@(a,b)cat(dim,a,b),'cat(1,...)'); -else - o=zipdata(bind(@cat,dim),length(varargin),varargin{:}); -end
--- a/sequences/@data/char.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function s=char(d) -s=feval(d.charfn,d);
--- a/sequences/@data/cos.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=cos(x), y=fndata(@cos,x,'size',size(x));
--- a/sequences/@data/ctranspose.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=ctranspse(A) -% CTRANSPOSE - complex transpose of data source - -o=fndata(@ctranspose,A,'size',fliplr(size(A)));
--- a/sequences/@data/cumsum.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -function y=cumsum(x,n) -% cumsum - cumsum for data sequences -% -% cumsum :: seq [[N,M]], D:natural -> seq [[N,M]]. -% -% cumulative sum taken along Dth dimension of the array - -if length(size(x))>2 - error('cumsum not supported for >2 dim array sequences'); -end - -switch n - case 1 - y=scandata(@cs1,zeros(1,size(x,2)),x); - case 2 - y=scandata(@cs2,zeros(size(x,1),1),x); - case 3 - error('cumsum(.,3) not supported for sequences'); -end - -function w=cs1(s,z) - w=row(cumsum([s(end,:);z],1),2:size(z,1)+1); - -function w=cs2(s,z) - w=col(cumsum([s(:,end),z],2),2:size(z,2)+1);
--- a/sequences/@data/data.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -function o=data(b,varargin) -% DATA - Base class for abstract data objects -% -% data :: (size:[1,E], ~ size of data arrays -% options...) ~ vararg options -% -> data ~ data object -% -% Options -% 'datafn': data[size] -> [size] # required -% 'nextfn': data[size] -> data[size] # @id -% 'charfn': data[size] -> string # def=\d->'' -% -% Usage d:data[size] -% next(d) :: data[size] ~ next buffer in sequence -% head(d) :: [size] ~ current array -% d.size, size(d): size ~ size of array -% d(i:natural,j:natural):real ~ extract one element -% d(i:[n],j:[m]): [n,m:real] ~ extract sub-array -% char(d): string ~ format as string - -if nargin==0 - o=data([1,1],'datafn',@(z)0); -elseif isa(b,'data'), o=b; -else - p=prefs('nextfn',@id,'charfn',@charfn,varargin{:}); - a.size =b; - a.datafn=p.datafn; - a.nextfn=p.nextfn; - a.charfn=p.charfn; - o=class(a,'data'); -end - -function s=charfn(o), s='<data>'; -
--- a/sequences/@data/datafn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function f=datafn(o) -% datafn - return data function bound to this object - -f=bind(o.datafn,o);
--- a/sequences/@data/decons.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function [x,b]=decons(a) -% decons - Extract head and tail of sequence - -x=a.datafn(a); -b=a.nextfn(a);
--- a/sequences/@data/display.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function display(d) - -s=d.charfn(d); if ~isempty(s), s=[':' s]; end -display(sprintf(' [%s]%s\n',mat2str(size(d)),s));
--- a/sequences/@data/dispseq.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ -function dispseq(x,n,varargin) -% dispseq - Display elements of sequence -% -% dispseq :: seq A -> action. -% display elements of sequence with a pause in between each. -% -% dispseq :: seq A, N:natural -> action. -% display first N elements without pause. -% -% dispset :: seq A, N:natural, options {} -> action. -% display first N elements passing given options to foreach. -% If N is inf or [], the defaults is to pause betweem each -% element unless overridded by supplied options. - - if nargin<2 || isempty(n) || isinf(n), - foreach(@disp,x,'pause',1,varargin{:}); - else - foreach(@disp,take(n,x),varargin{:}); - end -
--- a/sequences/@data/double.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function x=double(a) -% DOUBLE - Convert data to double array - -x=a.datafn(a);
--- a/sequences/@data/dynfilter.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -function y=dynfilter(ab,x,z,dim) -% dynfilter - filter for sequences of array with dynamically varying filter coeffs -% -% dynfilter :: seq {[[P]],[[P]]}, seq [Size], [[P]], D:natural -> seq [Size]. -% dynfilter :: seq {[[P]],[[P]]}, seq [Size], [[P]] -> seq [Size]. -% dynfilter :: seq {[[P]],[[P]]}, seq [Size] -> seq [Size]. -% -% filtering is done along Dth dimension of the array (default=1) - -if nargin<5, - dim=find(size(x)>1,1); - if nargin<4, z=[]; end -end - -y = zipaccum(@(ab1,x1,z1)filter(ab1{1},ab1{2},x1,z1,dim),z,{ab,x});
--- a/sequences/@data/end.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function n=end(a,k,m) - -if m==length(a.size), n=a.size(k); -else n=prod(a.size); end
--- a/sequences/@data/eq.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function o=eq(A,B) -o=binop(A,B,@eq,'==');
--- a/sequences/@data/exp.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=exp(x), y=fndata(@exp,x,'size',size(x));
--- a/sequences/@data/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function x=extract(a,dim,range) -% EXTRACT - Extract a sub-array - -x=extract(head(a),dim,range);
--- a/sequences/@data/fft.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=fft(x), y=fndata(@fft,x,'size',size(x));
--- a/sequences/@data/filter.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -function y=filter(a,b,x,z,dim) -% filter - filter for sequences of array -% -% filter :: [[P]], [[P]], seq [Size], [[P]], D:natural -> seq [Size]. -% filter :: [[P]], [[P]], seq [Size], [[P]] -> seq [Size]. -% filter :: [[P]], [[P]], seq [Size] -> seq [Size]. -% -% filtering is done along Dth dimension of the array (default=1) - -if nargin<5, - dim=find(size(x)>1,1); - if isempty(dim), dim=1; end - if nargin<4, z=[]; end -end - -y = sfndata(@(x1,z1)filter(a,b,x1,z1,dim),z,x);
--- a/sequences/@data/foldl.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -function x=foldl(fn,e,y) -% foldl - Foldl combinator for data sequences -% -% This function applies an associative operator to a list of arguments, -% starting from the left using the given starting element. -% -% foldl :: -% (X,Y->X) ~'associative binary operator', -% X ~'initial element', -% seq Y ~'a lazy data sequence' -% -> X. - -if ~isdata(y) - error('stupid dumb arse matlab method dispatch is wrong'); -end - -x=folddata(fn,e,y);
--- a/sequences/@data/foreach.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,13 +0,0 @@ -function foreach(f,X,varargin) -% foreach - do an action for each element in a sequence in order -% -% foreach :: (A->action), seq A, options {} -> action. -% -% foreach takes the same options as iterate. - - iterate(@g,X,varargin{:}); - function x=g(x) - f(head(x)); - x=next(x); - end -end
--- a/sequences/@data/gather.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,76 +0,0 @@ -function [Y,X0]=gather(dim,X,varargin) -% gather - make big array of all arrays in a sequence -% -% gather :: N:natural, data [D] -> [E], data [D]. -% gather :: -% N:natural ~'the dimension along which to collect arrays', -% data [D] ~'the data to gather', -% options { -% draw :: boolean /0 ~'whether or not to call plotfn every iteration'; -% plotfn :: data [D]->handle ~'plotting function'; -% save :: natural /0 ~'if >0, then save state every this many interations'; -% recover:: boolean / 0 ~'if 1, then attempt to restart from saved state'; -% id :: string /'@gather' ~'file to save state' -% } -% -> [E], data [D]. -% -% E is such that E(I) = D(I) if I~=N. The second return -% is the final data object in the sequence - -Y=[]; i=1; -if nargin<3 % simple version - if ~isempty(X), - Y=head(X); - while 1 - X0=X; X=next(X0); - if isempty(X), break; end - Y=cat(dim,Y,head(X)); - end - end -else - opts=prefs('save',0,'recover',0,'draw',0,'plotfn',@nullplot,varargin{:}); - draw=opts.draw; - savn=opts.save; - - if opts.recover && exist([opts.id,'.mat'],'file') - load(opts.id); - X=next(X0); - fprintf('recovering from i=%d\n',i); - end - - if savn==0 && ~draw - if ~isempty(X) - Y=head(X); - while 1 - X0=X; X=next(X0); - if isempty(X), break; end - Y=cat(dim,Y,head(X)); - end - end - else - if savn>0 - fprintf('Will save every %d iterations to %s.mat\n',savn,opts.id); - end - - if ~isempty(X) - Y=head(X); - while 1 - X0=X; X=next(X0); i=i+1; - if draw, opts.plotfn(X0); end - if mod(i,savn)==0, - fprintf('saving at %d.\n',i); - save(opts.id,'X0','Y','opts','i','dim'); - end - optpause(opts); - if isempty(X), break; end - Y=cat(dim,Y,head(X)); - end - end - if savn>0, delete([opts.id '.mat']); end - % hope nothing goes wrong here! - end -end - -function nullplot(A,B), return - -
--- a/sequences/@data/ge.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function o=ge(A,B) -o=binop(A,B,@ge,'>=');
--- a/sequences/@data/gt.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function o=gt(A,B) -o=binop(A,B,@gt,'>');
--- a/sequences/@data/head.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function x=head(a) -% head - Extract head of sequence - -x=a.datafn(a);
--- a/sequences/@data/horzcat.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function o=horzcat(varargin) -% horzcat - horizontal array concatenation for data sequences -% -% horzcat :: -% seq [[N,M1,L]], -% seq [[N,M2,L]] -% -> seq [[N,M1+M2,L]]. - - -if length(varargin)==2 - o=binfun(varargin{1},varargin{2},@horzcat,'[,]'); -else - o=zipdata(@horzcat,length(varargin),varargin{:}); -end
--- a/sequences/@data/ifft.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=ifft(x), y=fndata(@ifft,x,'size',size(x));
--- a/sequences/@data/imagesc.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function h=imagesc(A,varargin) - -h=imagesc(head(A),varargin{:});
--- a/sequences/@data/integrate.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -function y=integrate(x,n,a,ff) -% integrate - integrate data sequence -% -% integrate :: -% seq [[N1,N2]] ~'sequence to integrate', -% D:natural ~'dimension to integrate along', -% [[M1,M2]] ~'initial value', -% ( [[M1,M2]] -> [[M1,M2]]) ~'function to filter initial value each block' -% -> seq [[N,M]]. -% -% cumulative sum taken along Dth dimension of the array - - if length(size(x))>2 - error('cumsum not supported for >2 dim array sequences'); - end - - if nargin<4, ff=@(t)t; end - - switch n - case 1, y=scandata(@cs1,a,x); - case 2, y=scandata(@cs2,a,x); - case 3, error('integrate(.,3) not supported for sequences'); - end - - function w=cs1(s,z), w=row(cumsum([ff(s(end,:));z],1),2:size(z,1)+1); end - function w=cs2(s,z), w=col(cumsum([ff(s(:,end)),z],2),2:size(z,2)+1); end -end
--- a/sequences/@data/isfinite.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=isfinite(A) -% isfinite - isfinite for sequences. - -o=fndata(@isfinite, A,'size',size(A));
--- a/sequences/@data/isinf.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=isinf(A) -% isinf - isinf for sequences. - -o=fndata(@isinf, A,'size',size(A));
--- a/sequences/@data/isnan.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=isnan(A) -% isnan - isnan for sequences. - -o=fndata(@isnan, A,'size',size(A));
--- a/sequences/@data/ldivide.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function o=ldivide(A,B) -% TIMES - Matrix multiplication for data objects -% -% usage: C=times(A,B)=A.*B -% -% Three cases -% A is data, B is an array -% A is array, B is data -% A and B are both data - can't handle this yet - -o=binop(A,B,@ldivide,'.\');
--- a/sequences/@data/le.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function o=le(A,B) -o=binop(A,B,@le,'<=');
--- a/sequences/@data/length.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function l=size(a,n) - -l=max(a.size);
--- a/sequences/@data/limit.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -function [y,its]=limit(d,X,varargin) -% limit - Get the limit of an infinite sequence if it exists -% -% limit :: -% (A,A->nonneg) ~ 'metric', -% seq A, ~ 'sequence of converging values', -% options { -% maxit/10e6 ~ 'maximum iterations'; -% tol/1e-5 ~ 'convergence tolerance' -% } -% -> A, natural. - opts=prefs('maxit',10e6,'tol',1e-5,varargin{:}); - - tol=opts.tol; - S.x=head(X); - S.X=next(X); - S.f=false; - S.its=0; - S=iterate(@converger,S,'its',opts.maxit); - y=S.x; - its=S.its; - - function S=converger(S) - xx=head(S.X); - S.X=next(S.X); - S.its=S.its+1; - if d(S.x,xx)<tol, S=[]; else S.x=xx; end - end -end
--- a/sequences/@data/log.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function y=log(x) - -y=fndata(@log,x,'size',size(x));
--- a/sequences/@data/log10.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function y=log(x) - -y=fndata(@log10,x,'size',size(x));
--- a/sequences/@data/log2.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function y=log(x) - -y=fndata(@log2,x,'size',size(x));
--- a/sequences/@data/logmap.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function y=logmap(x,varargin), - - argpos=1+(1:length(varargin)); - y=fndata(bindat(@logmap,argpos,varargin{:}),x,'size',size(x));
--- a/sequences/@data/lt.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function o=lt(A,B) -o=binop(A,B,@lt,'<');
--- a/sequences/@data/magspec.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=magspec(x), y=fndata(@magspec,x,'size',[1+size(x,1)/2 size(x,2)]);
--- a/sequences/@data/map.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -function x=map(fn,e,varargin) -% map - map function over data sequences -% -% map :: (Y->X), seq X -> seq Y. - -if ~isa(e,'data') - error('stupid dumb arse matlab method dispatch is wrong'); -end - -x=fndata(fn,e,varargin{:});
--- a/sequences/@data/mapaccum.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function x=mapaccum(fn,s0,y) -% mapaccum - map function over data sequences with accumulating state -% -% mapaccum :: (Y,S->X,S), S, seq X -> seq Y. -% -% This is just another name for sfndata. - -if ~isa(y,'data') - error('stupid dumb arse matlab method dispatch is wrong'); -end - -x=sfndata(fn,s0,y);
--- a/sequences/@data/max.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function o=max(A,B,DIM), -% max - max mapped over data sequence (ie NOT aggregate) - -if nargin==2 && ~isempty(B), o=binfun(A,B,@max,'max'); -else - if nargin<3, o=fndata(@max,A); - else o=fndata(bindat(@max,2:3,[],DIM),A); - end -end
--- a/sequences/@data/mean.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function o=mean(A,DIM), - -if nargin<2, o=fndata(@mean,A); -else o=fndata(bindat(@mean,2,DIM),A); -end
--- a/sequences/@data/merge.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function y=merge(f,varargin) -% mergedata - Combine several data sources using a given function -% -% mergedata :: -% ( (A1,...,An)->natural ~ chooser function, -% data A1,...,data An ~ n data sources, -% ) -> seq B - -y=mergedata(f,varargin);
--- a/sequences/@data/min.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function o=min(A,B,DIM), -% min - min mapped over data sequence (ie NOT aggregate) - -if nargin==2 && ~isempty(B), o=binfun(A,B,@min,'min'); -else - if nargin<3, o=fndata(@min,A); - else o=fndata(bindat(@min,2:3,[],DIM),A); - end -end
--- a/sequences/@data/minmax.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function R=minmax(X,dim) -% minmax - minmax for sequences operates over ENTIRE sequence -% -% minmax :: [D:[[1,E]]], I:[E] -> [set(D,I,2)]. -% -% If you want minmax on a per-buffer basis, use fndata: -% R=fndata(@(x)minmax(x,dim),X) - -R=folddata(@(r,t)minmax(cat(dim,r,t),dim),[],X);
--- a/sequences/@data/minus.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=minus(A,B) -% minus - -% usage: C=minus(A,B)=A-B -o=binop(A,B,@minus,'-');
--- a/sequences/@data/mldivide.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function o=mldivide(A,B) -% mldivide - Matrix left divide for data objects -% - -o=binop(A,B,@mldivide,'\');
--- a/sequences/@data/mod.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function o=mod(A,B) -% mod - mod for sequences -% - -o=binop(A,B,@mod,'mod');
--- a/sequences/@data/mrdivide.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=mrdivide(A,B) -% mrdivide - Matrix right divide for data objects - -o=binop(A,B,@mrdivide,'/');
--- a/sequences/@data/mtimes.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function o=mtimes(A,B) -% MTIMES - Matrix multiplication for data objects -% -% usage: C=mtimes(A,B)=A*B -% -% Three cases -% A is data, B is an array -% A is array, B is data -% A and B are both data - can't handle this yet - -o=binop(A,B,@mtimes,'*');
--- a/sequences/@data/next.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function b=next(a) -% NEXT - Return next buffer in sequence. -% -b=a.nextfn(a);
--- a/sequences/@data/numel.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -function n=numel(a, varargin) -% numel - number of elements in each array of a sequence -if nargin>1, - error('PANIC! data.numel called with multiple arguments.'); -end - -n=prod(a.size);
--- a/sequences/@data/paren.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function y=paren(a,S) -% paren - Map application of subsref with parentheses to sequence -% -% paren :: seq A, subs -> seq B :- (subsref :: A, subs -> B). - -% NOTE TO SELF: it would be good to work out the size of the -% array that will result when the function is evaluated, to -% save fndata evaluating it once on construction. -y=fndata(@(z)subsref(z,S),a,... - 'charfn',@(o)charfn(tostring(S.subs{:}),o)); - -function s=charfn(argstr,o) - s=sprintf('%s >> (%s)',tostring(source(o)),argstr); -
--- a/sequences/@data/phasespec.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=phasespec(x), y=fndata(@phasespec,x,'size',[1+size(x,1)/2 size(x,2)]);
--- a/sequences/@data/plot.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function varargout=plot(varargin) - -varargin=cellmap(@instantiate,varargin); -[varargout{1:nargout}]=plot(varargin{:}); - -function a=instantiate(a), if isa(a,'data'), a=head(a); end
--- a/sequences/@data/plus.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function o=plus(A,B) -% plus - Addition for data objects -o=binop(A,B,@plus,'+');
--- a/sequences/@data/power.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function o=power(A,B), o=binop(A,B,@power,'.^');
--- a/sequences/@data/powspec.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=powspec(x), y=fndata(@powspec,x,'size',[1+size(x,1)/2 size(x,2)]);
--- a/sequences/@data/rdivide.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function o=rdivide(A,B) -% TIMES - Matrix multiplication for data objects -% -% usage: C=times(A,B)=A.*B -% -% Three cases -% A is data, B is an array -% A is array, B is data -% A and B are both data - can't handle this yet - -o=binop(A,B,@rdivide,'./');
--- a/sequences/@data/reshape.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function o=reshape(source,varargin) -% reshape - Map reshape over elements of sequence -% -% reshape :: seq [Size->A], ... - > seq [Size1->A]. -% Works exactly like the usual reshape function but when applied -% to a sequence object, returns a new sequence. - -sz=tosize(varargin{:}); -o=fndata(@(x)reshape(x,varargin{:}),source,'charfn',@(o)charfn(sz,o), 'size',sz); - -function s=charfn(sz,o) - s=sprintf('%s >> reshape[%s]',tostring(source(o)),tostring(sz));
--- a/sequences/@data/scanl.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -function x=scanl(fn,e,y,varargin) -% scanl - scanl combinator for data sequences -% -% This function applies an associative operator to a list of arguments, -% starting from the left using the given starting element. -% -% foldl :: -% (X,Y->X) ~'associative binary operator', -% X ~'initial element', -% seq Y ~'a lazy data sequence' -% -> seq X. - -if ~isdata(y) - error('stupid dumb arse matlab method dispatch is wrong'); -end - -x=scandata(fn,e,y,varargin{:});
--- a/sequences/@data/setsize.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=setsize(o,sz) -% SETSIZE - Changes size of data object - -o.size=sz;
--- a/sequences/@data/sin.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function y=sin(x), y=fndata(@sin,x,'size',size(x));
--- a/sequences/@data/size.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function [s1,s2]=size(a,n) - -s=a.size; -if nargin>1, s1=s(n); -elseif nargout>1, s1=s(1); s2=s(1); -else s1=s; end;
--- a/sequences/@data/soundsc.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -function t=soundsc(D,varargin) -% SOUNDSC - Play sound from sequence of arrays -% -% soundsc :: data [[N,T]], maybe real~'sampling rate' -% -> natural~'total samples played'. - -foreach(@(z)soundsc(z,varargin{:}),D); -
--- a/sequences/@data/specfilt.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -function Y=specfilt(X,S,varargin) - opts=varargin; - Y=zipdata(@specfiltf,X,S); - - function Y=specfiltf(opts,x,s), - Y=unbuffer(ipowspec(s,phasespec(x)),opts{:}); end - end -end
--- a/sequences/@data/sqrt.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function y=sqrt(x) - -y=fndata(@sqrt,x,'size',size(x));
--- a/sequences/@data/subsref.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -function y=subsref(a,S) -% SUBSREF - Subscripted referencing - -switch S(1).type -case '()', y=paren(a,S(1)); -case '.', fn=S(1).subs; y=fndata(@(z)getfield(z,fn),a); -% switch S(1).subs -% case 'size', y=a.size; -% case 'data', y=feval(a.datafn,a); -% case 'next', y=feval(a.nextfn,a); -% end -end - -if length(S)>1, y=subsref(y,S(2:end)); end - -
--- a/sequences/@data/sum.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function o=sum(A,DIM), - -if nargin<2, o=fndata(@sum,A); -else o=fndata(@(x)sum(x,DIM),A); -end
--- a/sequences/@data/tanh.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function y=tanh(x) - -y=fndata(@tanh,x,'size',size(x));
--- a/sequences/@data/times.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function o=times(A,B) -% TIMES - Matrix multiplication for data objects -% -% usage: C=times(A,B)=A.*B -% -% Three cases -% A is data, B is an array -% A is array, B is data -% A and B are both data - can't handle this yet - -o=binop(A,B,@times,'.*');
--- a/sequences/@data/tostring.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function s=tostring(d) -s=d.charfn(d);
--- a/sequences/@data/uminus.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function o=uminus(A) -% Unary minus - -o=fndata(@uminus, A,'size',size(A));
--- a/sequences/@data/unbuffer.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -function Y=unbuffer(X,hop) -% UNBUFFER - Opposite of buffer using overlap and add (for sequences) -% -% Usage: x=unbuffer(X,hop) -% X: sequences of [[N]] frames of signal data -% hop: Determines how much overlap there is between neighbouring frames - - - if isa(hop,'data') - Y=zipaccum(@olap2,[],{hop,X}); - else - if isscalar(hop) - N=max(size(X)); - ol=N-hop; - if ol<=hop - I=1:hop; J=1:ol; K=hop+1:N; - Y=sfndata(@olap1,zeros(ol,1),X); - else - I=1:hop; J=hop+1:ol; K=ol+1:N; - Y=sfndata(@olap3,zeros(ol,1),X); - end - else - Y=zipaccum(@olap2,[],{windowdata(repeat(hop)),X}); - end - 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 - - function [y,s1]=olap2(hop,x,s) - ls=length(s); - lx=length(x); - if lx>=hop - if ls>=hop - % NB: this will fail if ls>lx, but this shouldn't happen since ls<=lx-hop - y=(x(1:hop)+s(1:hop))'; - s1=[s(hop+1:ls)+x(hop+1:ls);x(ls+1:end)]; - else - y=[x(1:ls)+s;x(ls+1:hop)]'; - s1=x(hop+1:end); - end - else - if ls>=hop - y=[s(1:lx)+x;s(lx+1:hop)]'; - s1=s(hop+1:end); - else - y=zeros(1,hop); - y(1:ls)=y(1:ls)+s'; - y(1:lx)=y(1:lx)+x'; - end - end - - % y=x(1:hop)'; - % ch=min(hop,ls); - % J=(1:ch)'; - % y(J)=y(J)+s(J)'; - % s1=x(hop+1:end)+[s(ch+1:end);zeros(lx-max(hop,ls),1)]; - end -end -
--- a/sequences/@data/unzip.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function xx=unzip(y) -% unzip - Separate sequence of tuples into several sequences -% -% unzip :: -% seq {I:[D]->A(I)}. -% -> {I:[D]->seq A(I)}. -% -% Note: input MUST be a sequence of constant size cell arrays. -% Output is a cell array of sequences of the same size and shape. - -xx=cell(size(y)); -for i=1:numel(xx) - xx{i}=fndata(@(a)a{i},y); -end
--- a/sequences/@data/vecop.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -function Z=vecop(F,X,Y) -% vecop - apply binary function to different sized array sequences -% -% vecop :: -% ([[D]],[[D]]->[[D]]) ~'some function requiring equal size args', -% seq [[DX]] ~'first arg of size DX', -% seq [[DY]] ~'second arg of size DY' -% -> seq [[DZ]] ~'result of size DZ' :- DZ=max(DX,DY). -% -% The input sequences must maintain the same size throughout. - -DX=size(X); DY=size(Y); -E=max(length(DX),length(DY)); -EDX=pad1s(E,DX); -EDY=pad1s(E,DY); -if all(EDX>=EDY) - S=EDX./EDY; - Z=binop(X,Y,@(x,y)F(x,repmat(y,S)),['<' tostring(F) '>']); -elseif all(EDY>=EDX) - S=EDY./EDX; - Z=binop(X,Y,@(x,y)F(repmat(x,S),y),['<' tostring(F) '>']); -else - DZ=max(EDX,EDY); - Z=binop(X,Y,@(x,y)F(repmat(x,DZ./EDX),repmat(y,DZ./EDY)),['<' tostring(F) '>']); -end - -
--- a/sequences/@data/vertcat.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function o=vertcat(varargin) -% vertcat - horizontal array concatenation for data sequences -% -% vertcat :: -% seq [[N1,M]], -% seq [[N2,M]] -% -> seq [[N1+N2,M]]. - - -if length(varargin)==2 - o=binfun(varargin{1},varargin{2},@vertcat,'[,]'); -else - o=zipdata(@vertcat,length(varargin),varargin{:}); -end
--- a/sequences/@data/wienerfilt.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function Y=wienerfilt(T,S,X,varargin) - -Y=zipdata(bind(@worker,varargin),3,T,S,X); - -function Y=worker(opts,T,S,X) - Y=unbuffer(wiener(X,T,S),opts{:});
--- a/sequences/@data/zip.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -function x=zip(varargin) -% zip - combine several sequences into one -% -% zip :: -% seq A, seq B, ... -% -> seq {A,B,...}. - -%sz=size(args); -%if sz(1)==1 && length(sz)<=2 - x=zipdata(@tuple,varargin); -%else -% x=zipdata(@rtuple,args) -%end - -function z=rtuple(varargin), z=reshape(varargin,sz); end - -end
--- a/sequences/@data/zipwith.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function x=zipwith(fn,varargin) -% zipwith - map function over data sequences -% -% zipwith :: -% (A,B,...->X), -% seq A, seq B, ... -% -> seq X. - -x=zipdata(fn,varargin);
--- a/sequences/@ddata/ddata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function o=ddata(source,b,varargin) -% DDATA - Base class for all derived data sources - -if nargin==1 && isa(source,'ddata'), o=source; -else - ft=prefs('stringfn','*','nextfn',@nfn,'charfn',@cfn,varargin{:}); - o.source=source; - o.stringfn=ft.stringfn; - o=class(o,'ddata',data(b,ft)); -end - -function o=nfn(o), o=next_nc(o); -function s=cfn(o), s=sprintf('%s >> %s',tostring(o.source),feval(o.stringfn,o)); -
--- a/sequences/@ddata/headsource.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function x=headsource(o), x=head(o.source); -% headsource - Convenience function to get head of current source
--- a/sequences/@ddata/next_c.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function o=next_c(o) -% NEXT_C - Next with size adjustment - -o.source=next(o.source); -if isempty(o.source), o=[]; -else - oldsize=size(o); - newsize=size(o.source); - if any(newsize~=oldsize) -% fprintf('-- ddata: size changed to %s\n',mat2str(newsize)); - o=setsize(o,newsize); - end -end -
--- a/sequences/@ddata/next_nc.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function o=next_nc(o) -% NEXT_NC - Next with no check on size of next source. - -o.source=next(o.source); -if isempty(o.source), o=[]; end -
--- a/sequences/@ddata/nextsource.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function o=nextsource(o) -% NEXTSOURCE - Returned derived data using next source object - -o.source=next(o.source); -
--- a/sequences/@ddata/setsource.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function o=setsource(o,s), o.source=s; -% setsource - set source of derived data sequence.
--- a/sequences/@ddata/source.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function s=source(o) -s=o.source;
--- a/sequences/@extractdata/extractdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,17 +0,0 @@ -function o=extractdata(source,dim,range) -% extractdata - Sequence of extracts from source sequence -% -% extractdata :: seq [[Size]], D:natural, [[2]->[Size(D)]] -> seq [[Size2]]. -% -% extractdata is basically the same as fndata extract but more efficient. - - sz=size(source); - sz(dim)=range(2)-range(1)+1; - o.dim=dim; - o.range=range; - o=class(o,'extractdata',ddata(source,sz,'datafn',@dfn,'stringfn',@sfn,'nextfn',@next_c)); - - -function x=dfn(o), x=extract(source(o),o.dim,o.range); -function s=sfn(o) - s=sprintf('[%d/%d:%d]', o.dim, o.range(1), o.range(2));
--- a/sequences/@filterdata/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array -% -% extract :: seq [[D]], natural, [[2]->natural]] -> [[D2]]. - -y=extract(source(o),dim,range);
--- a/sequences/@filterdata/filterdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -function d=fndata(a,b,varargin) -% filterdata - Use arbitrary function to test and filter elements of another sequence -% -% filterdata :: -% ((A->bool) ~ test function, -% data(A), ~ source data, -% ... ~ options) -% -> data(A). -% -% Options -% 'datafn':: Data A->A ~ override function to get data -% 'stringfn':: Data A->String ~ override conversion to string -% 'nextfn':: Data A->(Data A | []) ~ override next function -% -% Methods -% -% testfn :: filterdata(A) -> (A->bool). -% source :: filterdata(A) -> data(A). - -if nargin==0, a=filterdata(@(t)true,singleton(0)); end -if isa(a,'filterdata'), d=a; -else - d.fn=a; % function to apply - - - - opts=prefs('datafn',@datafn,'stringfn',@stringfn,'sizecheck',0,varargin{:}); - opts.nextfn=@nextfn; - d=class(d,'filterdata',ddata(b,size(b),opts)); - - if ~d.fn(head(d)), d=next(d); end -end - - -function x=datafn(d), x=head(source(d)); -function s=stringfn(d), s=sprintf('%s?',tostring(d.fn)); -function o=nextfn(o) - while 1 - o=next_c(o); - if isempty(o) || o.fn(head(source(o))), break; end - end - - -
--- a/sequences/@filterdata/testfn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function f=testfn(o) -% testfn - Get filter function from filterdata -f=o.fn;
--- a/sequences/@fndata/fn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,3 +0,0 @@ -function f=fn(o) -% FN - Get function from fndata -f=o.fn;
--- a/sequences/@fndata/fndata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,51 +0,0 @@ -function d=fndata(a,b,varargin) -% FNDATA - Data source where data is a stateless function of another data source -% -% fndata :: -% ((A->B) ~ function to apply to each buffer, -% Data A, ~ source data, -% ... ~ options) -% -> Data B -% -% Options -% 'size':: [[1,D]] ~ size of array returned by function -% If not specified, FNDATA applies the function once to work -% out what size data is going to be returning. -% 'datafn':: Data A->A ~ override function to get data -% 'stringfn':: Data A->String ~ override conversion to string -% 'nextfn':: Data A->(Data A | []) ~ override next function -% -% Methods -% -% fn :: fndata(A,B) -> (A->B). -% source :: fnddata(A,B) -> data(A). - -if nargin==0, a=fndata(@(t)t,singleton(0)); end -if isa(a,'fndata'), d=a; -else - opts=prefs('datafn',@datafn,'stringfn',@stringfn, ... - 'sizecheck',0,'compose',0,varargin{:}); - - if opts.compose && isa(b,'fndata') - % if b is a fndata, we could do an optimisation where we - d=fndata(compose(a,fn(b)),source(b),varargin{:}); - % !! source will be wrong!! - else - d.fn=a; % function to apply - - if opts.sizecheck, opts.nextfn=@next_sizecheck; - else opts.nextfn=@next_nc; end - if ~isfield(opts,'size'), opts.size=size(d.fn(head(b))); end - d=class(d,'fndata',ddata(b,opts.size,opts)); - end -end - - -function x=datafn(d), x=d.fn(head(source(d))); -function s=stringfn(d), s=tostring(d.fn); -function d=next_sizecheck(d) - d=next_nc(d); - if ~isempty(d), - d=setsize(d,size(d.fn(head(source(d))))); - end -
--- a/sequences/@iterdata/iterdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -function x=iterdata(f,s0,varargin) -% iterdata - Construct sequence by recursive application of arbitrary function -% -% iterdata :: (A->A), A, options {} -> seq A. - - if nargin==1 && isa(s0,'iterdata'), x=s0; - elseif nargin==0 - x=iterdata(0,@id); - else - x.s=s0; - opts.datafn=@(t)t.s; - opts.nextfn=@(t)nfn(f,t); - opts.charfn=@(t)cfn(f,t); - x=class(x,'iterdata',data(size(s0),prefs(opts,varargin{:}))); - end -end - - -function x=nfn(f,x) - s1=f(x.s); - if isempty(s1), x=[]; else x.s=s1; end -end - -function c=cfn(f,t) - c=['iter(' tostring(f) ')']; -end - -
--- a/sequences/@mergedata/mergedata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -function d=mergedata(c,sources,varargin) -% mergedata - Combine several data sources using a given function -% -% mergedata :: -% ( (A1,...,An)->natural ~ chooser function, -% n:natural ~ number of sources to combine, -% data A1,...,data An ~ n data sources, -% ... ~ options -% ) -> seq B -% -% Options: -% 'size'::[[1 E]] ~ size of result if known - -if nargin==0, d=mergedata(@(x)1,1,[0]); -elseif isa(c,'mergedata'), d=c; -else - d.fn=c; - d.head=[]; - d.sources=sources; - - opts=prefs('datafn',@datafn,'nextfn',@nextfn,'charfn',@charfn,varargin{:}); - if ~isfield(opts,'size'), opts.size=size(datafn(d)); end - d=nextfn(class(d,'mergedata',data(opts.size,opts))); -end - - -function x=datafn(d) - x=d.head; - -function d=nextfn(d) - data=cellmap(@head,d.sources); - if isempty(data), d=[]; - else - k=d.fn(data); - d.head=data{k}; - nk=next(d.sources{k}); - if isempty(nk), d.sources(k)=[]; - else d.sources{k}=nk; end - end - - - -function s=charfn(d) - s=char(d.sources{1}); - for i=2:length(d.sources) - s=[s ', ' char(d.sources{i})]; - end - s=sprintf('{ %s } >> merge(%s)',s,tostring(d.fn));
--- a/sequences/@mergedata/sources.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function s=sources(o,i) -% SOURCES - Cell array of sources for zipdata - -if nargin==1, s=o.sources; -else s=o.sources{i}; end;
--- a/sequences/@mp3data/channels.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function c=channels(o) -c=o.channels;
--- a/sequences/@mp3data/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(a,dim,range) -% EXTRACT - Extract a sub-array from wavefile - -if dim~=2, error('Can only subrange times, not channels'); end -% fprintf('-- partial read %s %s\n',mat2str(range),a.file); -y=mp3read(a.file,range,a.args{:})';
--- a/sequences/@mp3data/file.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function fn=file(o) -fn=o.file;
--- a/sequences/@mp3data/length.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function l=length(o) -% LENGTH - Length of wave file in samples - -l=o.length;
--- a/sequences/@mp3data/mp3data.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -function a=mp3data(fn,varargin) -% MP3DATA - abstract data object for reading an MPEG-1 layer III audio file -% -% mp3data :: -% text ~'file name', -% options { -% 'rate':real ~'attempt to return signal at this sampling rate', -% 'mono':{0,1}/0 ~'if 1, then return a single channel signal' -% } -% -> data [Ch,l:-1--1]. ~'Data object for n by l arrays of bounded reals - - -if isa(fn,'mp3data'), D=fn; -else - fprintf('reading MP3 header...'); - [sz,fs] = mp3read(fn,'size'); - opts=prefs('rate',fs,'mono',0,varargin{:}); - - % first extra argument is whether or not we want mono - mp3args={opts.mono}; - - % downsample as nearest power of 2, maximum of 4 - ds=min(pow2(round(log2(fs/opts.rate))),4); - if ds>1, - mp3args=[mp3args {ds}]; - [sz,fs] = mp3read(fn,'size',mp3args{:}); - end - - a.file = fn; - a.rate = fs; - a.length = floor(sz(1)); - a.channels = sz(2); - a.args = mp3args; - - % sort out function table (default nextfn=id) - ft.datafn=@datafn; - ft.charfn=@charfn; - ft.nextfn=@nextfn; - - a=class(a,'mp3data',data([a.channels a.length],ft)); - fprintf('done.\n'); -end - - -function o=nextfn(o), o=[]; - -function X=datafn(a), - fprintf('-- reading %s\n',a.file); - X=mp3read(a.file,0,a.args{:})'; - -function s=charfn(a) - k=strfind(a.file,filesep); - if isempty(k), fn=a.file; else fn=a.file(k(end)+1:end); end - s=sprintf('%s(%d Hz)', fn,a.rate); -
--- a/sequences/@mp3data/play.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -function play(w,prog) -% PLAY - Play wavedata object using external player -% -% play :: wavedata, maybe text~'optional player command' -> unit. -% -% This plays the audio in a wave file without loading it all into -% MATLAB's workspace, by using a system dependent external player, -% which can be overridden (second parameter). - -if nargin<2, % got to find a player application - switch computer, - case 'LNX86', - if system('which mpg123')==0, prog='mpg123'; - elseif system('which mpg321')==0, prog='mpg321'; - else error('No player application found'); - end - - case 'PCWIN', - prog='mplayer2'; - - case 'MAC', - if system('which mpg123')==0, prog='mpg123'; - elseif system('which mpg321')==0, prog='mpg321'; - elseif system('which qtplay')==0, prog='qtplay'; - else prog='open'; % NOTE: open returns immediately - end - end -end -% have to check if file begins with ~ -if w.file(1)=='~' - slash=strfind(w.file,filesep); - arg=[w.file(1:slash(1)) '"' w.file(slash(1)+1:end) '"']; -else - arg=['"' w.file '"']; -end -system( [prog ' ' arg]); - -system([prog ' "' w.file '"']); -
--- a/sequences/@mp3data/rate.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function r=rate(o) -r=o.rate;
--- a/sequences/@mp3data/subsref.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,42 +0,0 @@ -function y=subsref(a,S) -% subsref - subsref for mp3data class - -subs=S(1).subs; -switch S(1).type -case '()', y=lparen(a,S(1)); -%case '.' -% switch subs -% case 'data', y=head(a); -% case 'next', y=next(a); -% otherwise, -% if ispublic(subs), y=a.(subs); -% else y=subsref(a.data,S); end -% end -end -if length(S)>1, y=subsref(y,S(2:end)); end - - -%function f=ispublic(f) -% f=ismember(f,{'file', 'rate','channels','length'}); - - - -function y=lparen(a,S) - - subs=S.subs; - if length(subs)==1, - if subs{1}(1)==':' || a.channels>1, y=paren(a,S); - else - range=[min(subs{1}) max(subs{1})]; - y=extractdata(a,2,range); - y=y(1+subs{1}-range(1)); - end - else - if subs{2}(1)==':', y=paren(a,S); - else - range=[min(subs{2}) max(subs{2})]; - y=extractdata(a,2,range); - y=y(subs{1},1+subs{2}-range(1)); - end - end -
--- a/sequences/@oggdata/channels.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function c=channels(o) -c=o.channels;
--- a/sequences/@oggdata/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(a,dim,range) -% EXTRACT - Extract a sub-array from wavefile - -if dim~=2, error('Can only subrange times, not channels'); end -% fprintf('-- partial read %s %s\n',mat2str(range),a.file); -y=oggread(a.file,range,a.args{:})';
--- a/sequences/@oggdata/file.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function fn=file(o) -fn=o.file;
--- a/sequences/@oggdata/length.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function l=length(o) -% LENGTH - Length of wave file in samples - -l=o.length;
--- a/sequences/@oggdata/oggdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,24 +0,0 @@ -function a=oggdata(fn) -% OGGDATA - abstract data object for reading an MPEG-1 layer III audio file -% -% oggdata :: -% text ~'file name', -% options { -% 'rate':real ~'attempt to return signal at this sampling rate', -% 'mono':{0,1}/0 ~'if 1, then return a single channel signal' -% } -% -> data [Ch,l:-1--1]. ~'Data object for n by l arrays of bounded reals - - -if isa(fn,'oggdata'), D=fn; -else - fs=ogginfo(fn); - Y=oggread(fn)'; - - a.file = fn; - a.rate = fs; - a.length = size(Y,2); - a.channels = size(Y,1); - - a=class(a,'oggdata',cons(Y,[])); -end
--- a/sequences/@oggdata/play.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -function play(w,prog) -% PLAY - Play wavedata object using external player -% -% play :: wavedata, maybe text~'optional player command' -> unit. -% -% This plays the audio in a wave file without loading it all into -% MATLAB's workspace, by using a system dependent external player, -% which can be overridden (second parameter). - -if nargin<2, % got to find a player application - switch computer, - case 'LNX86', - if system('which ogg123')==0, prog='ogg123'; - if system('which mplayer')==0, prog='mplayer'; - if system('which xmms')==0, prog='xmms'; - else error('No player application found'); - end - - case 'PCWIN', - prog='mplayer2'; - - case 'MAC', - if system('which ogg123')==0, prog='ogg123'; - elseif system('which qtplay')==0, prog='qtplay'; - else prog='open'; % NOTE: open returns immediately - end - end -end -% have to check if file begins with ~ -if w.file(1)=='~' - slash=strfind(w.file,filesep); - arg=[w.file(1:slash(1)) '"' w.file(slash(1)+1:end) '"']; -else - arg=['"' w.file '"']; -end -system( [prog ' ' arg]); - -system([prog ' "' w.file '"']); -
--- a/sequences/@oggdata/rate.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function r=rate(o) -r=o.rate;
--- a/sequences/@oggdata/subsref.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -function y=subsref(a,S) -% subsref - subsref for oggdata class - -subs=S(1).subs; -switch S(1).type -case '()', y=lparen(a,S(1)); -end -if length(S)>1, y=subsref(y,S(2:end)); end - - -%function f=ispublic(f) -% f=ismember(f,{'file', 'rate','channels','length'}); - - - -function y=lparen(a,S) - - subs=S.subs; - if length(subs)==1, - if subs{1}(1)==':' || a.channels>1, y=paren(a,S); - else - range=[min(subs{1}) max(subs{1})]; - y=extractdata(a,2,range); - y=y(1+subs{1}-range(1)); - end - else - if subs{2}(1)==':', y=paren(a,S); - else - range=[min(subs{2}) max(subs{2})]; - y=extractdata(a,2,range); - y=y(subs{1},1+subs{2}-range(1)); - end - end -
--- a/sequences/@rnddata/model.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function X=model(a), X=a.model; -% model - extract random variable model from rnddata -% -% model :: rnddata(M,SZ) -> M.
--- a/sequences/@rnddata/rnddata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,64 +0,0 @@ -function d=rnddata(model,sdom,k) -% RNDDATA - Sequence of values sampled from a random variable model -% -% rnddata :: -% model xdom:[[1,XD]] ~ random variable model, data size is xdom, -% sdom:[[1,SD]], ~ size of sample, -% -> rnddata [[xdom sdom]] ~ size of rnddata is product of xdom and sdom -% -% rnddata :: -% model xdom:[[1,XD]] ~ random variable model, data size is xdom, -% sdom:[[1,SD]], ~ size of sample, -% rndstate ~ initial state of generators -% -> rnddata [[xdom sdom]] ~ size of rnddata is product of xdom and sdom -% -% If an initial rndstate is supplied, rnddata is purely functional -% and referentially transparent. Otherwise, the initial construction -% uses the current state of the random generators. After this, the -% entire sequence is fully determined. -% -% EXAMPLE -% -% rnddata(gaussian,[2,200]) :: seq [[2,200]] -% rnddata(dirichlet(3,0.5),6) :: seq [[3,6]] - -if isa(model,'rnddata'), d=model; -else - if nargin<2, sdom=1; end - if isa(model,'struct') - if model.nparams>0, - error('Model has unbound parameters'); - end - gen=sampler(model.sample,sdom); - % gen=rndwrap(model.sample,'vu',[0,1],sdom); - elseif iscell(model) - gen=sampler(model{1},sdom); - % gen=rndwrap(model{1},'vu',[0,1],sdom); - end - d.model=model; - - if nargin>2, - if ~iscell(k), s={k,k}; else s=k; end - else - s=getrndstate; - end - - d=class(d,'rnddata',unfold(gen,s,'charfn',@(o)char(gen))); -end - -end - - -% this creates a rand-state-managed version of g applied to args, -% ie, -% sampler :: -% ((A1,A2,....) -> random B) ~'an action which generates a value' -% -> (rndstata -> B, rndstate) ~'a deterministic random state transformer'. - -function f=sampler(g,varargin) - f=@ufn; - function [x,s]=ufn(s) - setrndstate(s); x=g(varargin{:}); - s=getrndstate; - end -end
--- a/sequences/@rnddata/rndstate.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function s=rndstate(X) -% rndstate - Get rndstate for rnddata sequence - -s=X.nextstate;
--- a/sequences/@scandata/scandata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,41 +0,0 @@ -function d=scandata(a,b,c,varargin) -% SCANDATA - Data source where data is accumulated while scanning through a source sequence -% -% This works like scanl in a functional language (see eg, Haskell) -% -% scandata:: -% (S,A)->S) ~ function to apply to each buffer, -% S ~ initial state, -% data A, ~ source data, -% options {} ~ options -%-> scandata(S,A) < data S ~ ie result is a sequence of S. -% -% Options -% datafn :: data A->A ~ override function to get data -% stringfn :: data A->String ~ override conversion to string -% nextfn :: data A->(Data A | []) ~ override next function -% -% Methods -% scanfn::scandata(S,A) -> ((S,A)->S) - -if nargin==0, d=scandata(@(a,b)a,[],singleton(0)); -elseif isa(a,'scandata'), d=a; -elseif isempty(c), d=[]; -else - opts=prefs('datafn',@datafn,'stringfn',@stringfn,'nextfn',@nextfn,varargin{:}); - - d.scanfn=a; % function to apply - d.x=d.scanfn(b,head(c)); - d=class(d,'scandata',ddata(c,size(d.x),opts)); -end - - -function x=datafn(d), x=d.x; -function s=stringfn(d), s=[ 'scan(' tostring(d.scanfn) ')']; -function d=nextfn(d), - d=next_nc(d); - if ~isempty(d) - d.x=d.scanfn(d.x,head(source(d))); - d=setsize(d,size(d.x)); - end -
--- a/sequences/@scandata/scanfn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function f=scanfn(o) -% scanfn - Get scanning function -% -% sfndata(A,B) -> ((A,B)->B) -f=o.scanfn;
--- a/sequences/@sfndata/sfn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function f=fn(o) -% SFN - Get state-transformer function from sfndata data -% -% sfndata S A B -> ((A,S)->(B,S)) -f=o.sfn;
--- a/sequences/@sfndata/sfndata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -function d=sfndata(a,b,c,varargin) -% SFNDATA - Data source where data is a stateful function of another data source -% -% sfndata:: -% (((A,S)->(B,S)) ~ function to apply to each buffer, -% S ~ initial state, -% data A, ~ source data, -% ... ~ options) -% -> sfndata S A B < data B -% -% Options -% 'datafn':: Data A->A ~ override function to get data -% 'stringfn':: Data A->String ~ override conversion to string -% 'nextfn':: Data A->(Data A | []) ~ override next function -% -% Methods -% sfn :: sfndata(S,A,B) -> ((A,S)->(B,S)). -% state :: sfndata(S,A,B) -> S. -% -% state returns the state after the current value but but before the next - -if nargin==0, d=sfndata(@deal,[],singleton(0)); -elseif isa(a,'sfndata'), d=a; -elseif isempty(c), d=[]; -else - opts=prefs('datafn',@datafn,'stringfn',@stringfn,'nextfn',@nextfn,varargin{:}); - - d.sfn=a; % function to apply - [d.x,d.state]=d.sfn(head(c),b); - d=class(d,'sfndata',ddata(c,size(d.x),opts)); -end - - -function x=datafn(d), x=d.x; -function s=stringfn(d), s=tostring(d.sfn); -function d=nextfn(d), - d=next_nc(d); - if ~isempty(d) - [d.x,d.state]=feval(d.sfn,head(source(d)),d.state); - % !! might like to allow sfn to terminate sequence by returning something special - d=setsize(d,size(d.x)); - end -
--- a/sequences/@sfndata/state.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function f=state(o) -% state - Get state of sfndata object -% -% state :: sfndata(S,A,B) -> S. -f=o.state;
--- a/sequences/@subsampdata/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array -% -% extract :: seq [[D]], natural, [[2]->natural]] -> [[D2]]. - -y=extract(source(o),dim,range);
--- a/sequences/@subsampdata/subsampdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +0,0 @@ -function d=subsampdata(a,b,varargin) -% subsampdata - Use arbitrary function to test and filter elements of another sequence -% -% subsampdata :: -% natural ~ sample rate, -% data(A), ~ source data, -% ... ~ options) -% -> data(A). -% -% Options -% 'datafn':: Data A->A ~ override function to get data -% 'stringfn':: Data A->String ~ override conversion to string -% 'nextfn':: Data A->(Data A | []) ~ override next function -% -% Methods -% -% source :: filterdata(A) -> data(A). - -if nargin==0, a=subsampdata(1,singleton(0)); end -if isa(a,'subsampdata'), d=a; -else - d.n=a; - - opts=prefs('datafn',@datafn,'stringfn',@stringfn,'sizecheck',0,varargin{:}); - opts.nextfn=@nextfn; - d=class(d,'subsampdata',ddata(b,size(b),opts)); -end - -function x=datafn(d), x=head(source(d)); -function s=stringfn(d), s=sprintf('subsamp(%d)',tostring(d.n)); -function o=nextfn(o) - for i=1:o.n - o=next_c(o); - if isempty(o), break; end - end - - -
--- a/sequences/@take/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array -% -% extract :: seq [[D]], natural, [[2]->natural]] -> [[D2]]. - -y=extract(source(o),dim,range);
--- a/sequences/@take/take.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -function o=take(n,source) -% TAKE - Take first n alements of sequence then stop -% -% take :: natural, seq A -> seq A - -if nargin==0, o=take(1,0); -elseif n==0, o=[]; -elseif isa(source,'take'), - o=source; - o.n=min(o.n,n); -else - ft.datafn=@datafn; - ft.stringfn=@stringfn; - ft.nextfn=@nextfn; - o.n=n; - o=class(o,'take',ddata(source,size(source),ft)); -end - -function x=datafn(o), x=head(source(o)); -function s=stringfn(o), s=sprintf('take(%d)',o.n); -function o=nextfn(o) - if o.n==1, o=[]; - else - o=next_c(o); - if ~isempty(o), o.n=o.n-1; end - end - - -
--- a/sequences/@takewhile/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(o,dim,range) -% EXTRACT - Extract a sub-array -% -% extract :: seq [[D]], natural, [[2]->natural]] -> [[D2]]. - -y=extract(source(o),dim,range);
--- a/sequences/@takewhile/takewhile.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -function o=takewhile(f,source) -% takewhile - Take elements of seq while a condition is met. -% -% takewhile :: (A->bool), seq A -> seq A - -if nargin==0, o=takewhile(@(e)true,0); -elseif isa(source,'takewhile'), o=source; -elseif isempty(source), o=[]; -elseif ~f(head(source)), o=[]; -else - ft.datafn=@datafn; - ft.stringfn=@stringfn; - ft.nextfn=@nextfn; - o.f=f; - o.x=head(source); - o=class(o,'takewhile',ddata(source,size(source),ft)); -end - -function x=datafn(o), x=o.x; -function s=stringfn(o), s=sprintf('takewhile(%s)',tostring(o.f)); -function o=nextfn(o) - o=next_c(o); - if ~isempty(o), - o.x=headsource(o); - if ~o.f(o.x), o=[]; end - end - - -
--- a/sequences/@uidata/eventadder.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -function f=eventadder(o) - - global UIDATA UITIMER - - idx=o.index; - f=@addevent; - - function addevent(type,varargin) - ev.time=now; - ev.type=type; - ev.args=varargin; - UIDATA{idx} = [ UIDATA{idx} {ev} ]; - - % hiccough the timer to notify waiters -% stop(UITIMER); -% start(UITIMER); - end -end -
--- a/sequences/@uidata/ready.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function b=ready(o) - -global UIDATA - -b = length(UIDATA{o.index})>=o.evnum;
--- a/sequences/@uidata/uidata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,30 +0,0 @@ -function o=uidata(a) - -global UIDATA UITIMER - -if nargin>0 && isa(a,'uidata'), X=a; -else - UIDATA=[UIDATA {{}}]; - if isempty(UITIMER) - % this is good for 23 days... - UITIMER=timer('startdelay',2e6,'TimerFcn',@nop); -% start(UITIMER); - end - - d.index=length(UIDATA); - d.evnum=1; - - ft.stringfn=@stringfn; - ft.datafn=@datafn; - ft.nextfn=@nextfn; - o=class(d,'uidata',data([1,1],ft)); -end - -function x=datafn(o), - global UIDATA - x=UIDATA{o.index}{o.evnum}; - -function s=stringfn(o), s='uidata'; -function o=nextfn(o), - o.evnum=o.evnum+1; -
--- a/sequences/@uidata/wait.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function wait(o) - - global UIDATA UITIMER - - wait(UITIMER);
--- a/sequences/@unfold/fn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function f=fn(o) -% FN - Get unfolding function -% -% fn :: unfolddata(S,A) -> (S->A,S) -f=o.fn;
--- a/sequences/@unfold/state.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function f=state(o) -% state - Get state of unfolddata object -% -% state :: unfolddata(S,A) -> S. -f=o.state;
--- a/sequences/@unfold/unfold.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ -function d=unfold(a,b,varargin) -% unfold - Data source where data is a stateful function of another data source -% -% unfold:: -% ((S->(A,S)) ~ function to apply to each buffer, -% S ~ initial state, -% ... ~ options) -% -> unfold(S,A) < seq A -% -% Options -% 'datafn':: seq A->A ~ override function to get data -% 'stringfn':: seq A->string ~ override conversion to string -% 'nextfn':: seq A->(seq A | []) ~ override next function - -if nargin==0, d=unfold(@(s)deal(0,s),0); -elseif isa(a,'unfold'), d=a; -else - opts=prefs('datafn',@datafn,'charfn',@stringfn,'inf_constsize',0,varargin{:}); - if opts.inf_constsize && ~isfield(opts,'nextfn') - opts.nextfn=@nextfn_infnc; - else - opts.nextfn=@nextfn; - end - - [x,s]=a(b); - if ~isempty(x), - d.value=x; - d.state=s; - d.fn=a; % function to apply - d=class(d,'unfold',data(size(x),opts)); - end -end - - -function x=datafn(d), x=d.value; -function s=stringfn(d), s=sprintf('unfold(%s)',tostring(d.fn)); -function d=nextfn(d), - [x,s]=d.fn(d.state); - if isempty(x), d=[]; - else - d=setsize(d,size(x)); - d.value=x; d.state=s; - end - -% optimised version for infinite sequences with no size check -function d=nextfn_infnc(d), - [d.value,d.state]=d.fn(d.state); -
--- a/sequences/@wavedata/channels.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function c=channels(o) -c=o.channels;
--- a/sequences/@wavedata/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function y=extract(a,dim,range) -% EXTRACT - Extract a sub-array from wavefile - -if dim~=2, error('Can only subrange times, not channels'); end -% fprintf('-- partial read %s %s\n',mat2str(range),a.file); -y=mywavread(a.file,range)';
--- a/sequences/@wavedata/file.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function fn=file(o) -fn=o.file;
--- a/sequences/@wavedata/length.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function l=length(o) -% LENGTH - Length of wave file in samples - -l=o.length;
--- a/sequences/@wavedata/play.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,39 +0,0 @@ -function play(w,prog) -% PLAY - Play wavedata object using external player -% -% play :: wavedata, maybe text~'optional player command' -> unit. -% -% This plays the audio in a wave file without loading it all into -% MATLAB's workspace, by using a system dependent external player, -% which can be overridden (second parameter). - -if nargin<2, % got to find a player application - switch computer, - case 'LNX86', % Linux: assume alsa sound aplay is present! - if system('which aplay')==0, prog='aplay'; - elseif system('which play')==0, prog='play'; - elseif system('which xmms')==0, prog='xmms'; - else error('No player application found'); - end - - case 'PCWIN', - prog='mplayer2'; - - case 'MAC', - if system('which qtplay')==0, prog='qtplay'; - elseif system('which play')==0, prog='play'; - else prog='open'; % NOTE: open returns immediately - end - end -end -% have to check if file begins with ~ -if w.file(1)=='~' - slash=strfind(w.file,filesep); - arg=[w.file(1:slash(1)) '"' w.file(slash(1)+1:end) '"']; -else - arg=['"' w.file '"']; -end -system( [prog ' ' arg]); - -system([prog ' "' w.file '"']); -
--- a/sequences/@wavedata/rate.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,2 +0,0 @@ -function r=rate(o) -r=o.rate;
--- a/sequences/@wavedata/subsref.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -function y=subsref(a,S) -% subsref - subsref for wavedata - -subs=S(1).subs; -switch S(1).type -case '()', y=lparen(a,S(1)); -end -if length(S)>1, y=subsref(y,S(2:end)); end - - -%function f=ispublic(f) -% f=ismember(f,{'file', 'rate','channels','length'}); - - - -function y=lparen(a,S) - - subs=S.subs; - if length(subs)==1, - if subs{1}(1)==':' || a.channels>1, y=paren(a,S); - else - range=[min(subs{1}) max(subs{1})]; - y=extractdata(a,2,range); - y=y(1+subs{1}-range(1)); - end - else - if subs{2}(1)==':', y=paren(a,S); - else - range=[min(subs{2}) max(subs{2})]; - y=extractdata(a,2,range); - y=y(subs{1},1+subs{2}-range(1)); - end - end -
--- a/sequences/@wavedata/wavedata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -function a=wavdata(fn) -% WAVDATA - abstract data object for reading a wavefile as seq of arrays -% -% wavdata :: -% string ~'file name', -% -> Data [ch,l:-1--1]. ~'Data object for n by l arrays of bounded reals - - -if nargin==0, - a=struct('file','','rate',0,'length',0,'channels',0); - ft.datafn=@datafn; - ft.charfn=@charfn; - ft.nextfn=@nextfn; - a=class(a,'wavedata',data([a.channels a.length],ft)); -elseif isa(fn,'wavedata'), D=fn; -else - fprintf('reading wave header...'); - sz = mywavread(fn,'size'); - [y,fs] = mywavread(fn,[1 1]); - - a.file = fn; - a.rate = fs; - a.length = floor(sz(1)); - a.channels = sz(2); - - % sort out function table (default nextfn=id) - ft.datafn=@datafn; - ft.charfn=@charfn; - ft.nextfn=@nextfn; - - a=class(a,'wavedata',data([a.channels a.length],ft)); - fprintf('done.\n'); -end - - -function o=nextfn(o), o=[]; - -function X=datafn(a), - fprintf('-- reading %s\n',a.file); - X=mywavread(a.file)'; - -function s=charfn(a) - k=strfind(a.file,filesep); - if isempty(k), fn=a.file; else fn=a.file(k(end)+1:end); end - s=sprintf('%s(%d Hz)', fn,a.rate); -
--- a/sequences/@windowdata/hop.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function h=hop(o) -% HOP - Return hop size for windowed data object -h=o.hop; -
--- a/sequences/@windowdata/length.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function h=length(o) -% LENGTH - Return length of window for windowed data object -h=o.span; -
--- a/sequences/@windowdata/options.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function h=options(o) -% options - Get options used to create window datat -h=o.opts; -
--- a/sequences/@windowdata/position.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function p=position(o) -% POSITION - Current position of window in main signal (1 based) - -p=o.pos+1;
--- a/sequences/@windowdata/subsref.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -function y=subsref(a,S) -% subsref - subsref for windowdata - -switch S(1).type -case '()', y=paren(a,S(1)); -%case '.' -% field=S(1).subs; -% switch field -% case 'hop', y=a.m; -% case 'frame', y=a.n; -% case 'source', y=a.source; -% case 'data', y=double(a); -% case 'next', y=next(a); -% otherwise, y=subsref(a.data,S); end -end - -if length(S)>1, y=subsref(y,S(2:end)); end - -
--- a/sequences/@windowdata/windowdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ -function a=windowdata(src,span,hop,varargin) -% windowdata - abstract data object for extracting window from another data -% -% windowdata :: -% X:data[C,_] ~'source signal', -% N:natural ~'window size', -% natural ~'hop size', -% options { -% dim :: natural/ndims(X) ~'dimension to window along (default is last)'; -% wrap:: bool /1 ~ if 1, then source is treated as a contiguous stream in -% the dimth dimension; otherwise, each buffer is windowed -% independently.' -% } -% -> data [C,N]. ~'data object for n by l'. - - - if nargin==1 && isa(src,'windowdata'), a=src; - elseif nargin==0, a=windowdata([],0,0); - else -% if nargin<4, -% l = []; - if nargin<3, - if nargin<2, span=1; end - hop=span; - end -% end - sz=size(src); - opts=prefs('wrap',1,'truncate',0,'random',[],'dim',length(sz),'strict',1,varargin{:}); - - dim=opts.dim; wrap=opts.wrap; trunc=opts.truncate; - a.hop=hop; a.span=span; - - % mutable state - a.length=sz(dim); - a.pos = 0; - a.opts =opts; - a.curr =[]; - - - % this trucates any remaining samples that don't fit the - % buffering structure so that the rewind always goes back to - % the first sample. - if trunc, - if wrap, error('ERROR: setting both truncate and wrap no longer supported'); - else disp('WARNING: truncate option no longer has any effect'); - end - end - - if ~isempty(opts.random), - error('Random option is deprecated, use rndwindow instead'); - end - - % sort out function table - ft.stringfn=@stringfn; - - if wrap - ft.datafn=@(a)a.curr; - ft.nextfn=@next_caching; - - [a.curr,src,a.pos,a.length]=itread(dim,span,src,0,a.length); - if size(a.curr,dim)<span, a=[]; return; end; % !! Strict window length? - a=class(a,'windowdata',ddata(src,arrset(sz,dim,span),ft)); - else - ft.datafn=@(a)extract(source(a),dim,a.pos+[1 span]); - ft.nextfn=@next_seq_nowrap; - - a=class(a,'windowdata',ddata(src,arrset(sz,dim,span),ft)); - if a.length<span, a=next_seq_nowrap(a); end; - end - end - - - % optimised next (assumes wrap=1) - function a=next_caching(a) - src=source(a); - if isempty(src) - a=[]; - else - [x,src,a.pos,a.length]=itread(dim,hop,src,a.pos,a.length); - if size(x,dim)<hop, - if opts.strict, - a=[]; % strict window length - else - a.curr=cat(dim,extract(a.curr,dim,[hop+1 span]),x); - a=setsize(setsource(a,src),size(a.curr)); - end - else - a.curr=cat(dim,extract(a.curr,dim,[hop+1 span]),x); - a=setsource(a,src); - end - end - end - - function a=next_seq_nowrap(a) - a.pos=a.pos+hop; % next window position - while a.pos+span>a.length % next window would overrun - a=next_nc(a); if isempty(a), break; end - a.length=size(source(a),dim); - a.pos=0; - end - end -end - - -% iterative read - read len samples starting at pos in head -% buffer of source. Returns tail source and pos for subsequent -% reads. -function [chunk,source,pos,max]=itread(dim,len,source,pos,max) - if len==0 || isempty(source), chunk=[]; return; end - - chunk=[]; - if pos+len>=max - chunk=extract(source,dim,[pos+1 max]); - len=pos+len-max; - source=next(source); - if ~isempty(source), - max=size(source,dim); - while len>=max - chunk=cat(dim,chunk,head(source)); len=len-max; - source=next(source); - if isempty(source), break; end - max=size(source,dim); - end - pos=0; - end - end - if ~isempty(source), - ex=extract(source,dim,pos+[1 len]); - if isempty(chunk), chunk=ex; else chunk=cat(dim,chunk,ex); end - pos=pos+len; - end -end - -function s=stringfn(a), s=sprintf('window(%d/%d)',a.span,a.hop); end -
--- a/sequences/@zipaccum/fn.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function f=fn(o) -% FN - Get state-transformer function from zipaccum -% -f=o.fn;
--- a/sequences/@zipaccum/sources.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function s=sources(o,i) -% SOURCES - Cell array of sources for zipdata - -if nargin==1, s=o.sources; -else s=o.sources{i}; end;
--- a/sequences/@zipaccum/state.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function f=state(o) -% state - Get state of zipaccum object -% -f=o.state;
--- a/sequences/@zipaccum/zipaccum.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -function d=zipaccum(a,b,c,varargin) -% zipaccum - Combine several sequences with stateful function -% -% zipaccum :: -% ( (A(1),...,A(N),S)->(B,S)) ~ 'zipping function with state', -% S ~ 'initial state', -% {I:[N]->seq A(I)} ~ 'cell array of N sequences', -% options { -% size::[[1,E]] ~ 'size of result if known' -% } -% -> seq B. - -if nargin==0, d=zipaccum(@deal,1,{singleton(0)}); -elseif isa(a,'zipaccum'), d=a; -elseif any(cell2mat(cellmap(@isempty,c))), d=[]; -else - opts=prefs('datafn',@datafn,'nextfn',@nextfn2,'charfn',@charfn,varargin{:}); - - d.fn=a; - d.sources=c; - heads=cellmap(@head,c); - [d.x,d.state]=d.fn(heads{:},b); - - if ~isfield(opts,'size'), opts.size=size(datafn(d)); end - d=class(d,'zipaccum',data(opts.size,opts)); -end - - -function x=datafn(d), x=d.x; - -function d=nextfn1(d) - for i=1:length(d.sources), - d.sources{i}=next(d.sources{i}); - if isempty(d.sources{i}), d=[]; break; end - end - if ~isempty(d) - args=cellmap(@head,d.sources); - [d.state,d.x]=d.fn(d.state,args{:}); - d=setsize(d,size(d.x)); - end - -function d=nextfn2(d) - for i=1:length(d.sources), - d.sources{i}=next(d.sources{i}); - if isempty(d.sources{i}), d=[]; break; end - end - if ~isempty(d) - args=cellmap(@head,d.sources); - [d.x,d.state]=d.fn(args{:},d.state); - d=setsize(d,size(d.x)); - end - -function s=charfn(d) - s=char(d.sources{1}); - for i=2:length(d.sources) - s=[s ', ' char(d.sources{i})]; - end - s=sprintf('{ %s } >> %s',s,tostring(d.fn));
--- a/sequences/@zipdata/sources.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function s=sources(o,i) -% SOURCES - Cell array of sources for zipdata - -if nargin==1, s=o.sources; -else s=o.sources{i}; end;
--- a/sequences/@zipdata/zipdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -function d=zipdata(a,n,varargin) -% ZIPDATA - Combine several data sources using a given function -% -% zipdata :: -% ( (A1,...,An)->B ~ zipping function, -% n:natural ~ number of sources to combine, -% data A1,...,data An ~ n data sources, -% ... ~ options -% ) -> data B -% -% Options: -% 'size'::[[1 E]] ~ size of result if known - -if nargin==0, d=zipdata(@id,1,singleton(0)); -elseif isa(a,'zipdata'), d=a; -else - d.fn=a; - if isnumeric(n) - d.sources=varargin(1:n); - varargin=varargin(n+1:end); - else - d.sources=n; - end - - if any(cell2mat(map(@isempty,d.sources))), d=[]; - else - opts=prefs('datafn',@datafn,'nextfn',@nextfn,'charfn',@charfn,varargin{:}); - if ~isfield(opts,'size'), opts.size=size(datafn(d)); end - d=class(d,'zipdata',data(opts.size,opts)); - end -end - - -function x=datafn(d) - data=cellmap(@head,d.sources); - x=feval(d.fn,data{:}); - -function d=nextfn(d) - for i=1:length(d.sources), - d.sources{i}=next(d.sources{i}); - if isempty(d.sources{i}), d=[]; break; end - end - -function s=charfn(d) - s=char(d.sources{1}); - for i=2:length(d.sources) - s=[s ', ' char(d.sources{i})]; - end - s=sprintf('{ %s } >> %s',s,tostring(d.fn));
--- a/sequences/append.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -function x=append(varargin), x=concat(celldata(varargin)); -% append - Append one or more sequences -% -% append :: seq A, seq A -> seq A. -% append :: seq A, seq A, ... -> seq A. -% -% etc.
--- a/sequences/chunk.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function B=chunk(A,n,step) -% CHUNK: return chunk from inside matrix -% B=chunk(A,n,hop): returns nth block of rows of size hop from A -% A: source matrix -% n: index of chunk -% hop: size of chunk - -i=n*step+1; -B=A(i:i+step-1,:); - -
--- a/sequences/cumsum_reset.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function y=cumsum_reset(n,x,dim) -% cumsum with periodic reset - -y=bindcat(take(n,cumsum(x,dim)),@(z)cumsum_reset(n,next(source(source(z))),dim));
--- a/sequences/diffwith.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -function Y=diffwith(F,X) -% diffwith - Generalised diff using argbitrary binary function -% -% diffwith :: (A,A->B), seq A -> seq B. -% -% The given function gets called with the current value as the -% first arguments and the previous value as the second. - -Y=sfndata(@diffst,head(X),next(X)); - -function [y,s]=diffst(x,s) - y=F(x,s); - s=x; -end -end -
--- a/sequences/drop.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function s=drop(n,s) -% drop - Drop the first n alements of sequence -% -% drop :: natural, seq A -> seq A - -for i=1:n, s=next(s); end - - -
--- a/sequences/dropwhile.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ -function s=dropwhile(f,s) -% drop - Drop elements of sequence that satisfy condition -% -% drop :: (A->bool), seq A -> seq A - -% if isempty(s) return s; end -x=head(s); -while f(x), - s=next(s); - if isempty(s), break; end - x=head(s); -end - -
--- a/sequences/extract.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,25 +0,0 @@ -function y=extract(x,dim,range) -% EXTRACT - Extract a sub-array -% -% extract :: -% [[size:[E]]], -% n:1..E, -% [[2]->natural]~'start and end indices' -% -> [[size1:[E]]. -% -% Examples (assuming A is 3D): -% extract(A,2,[4 20]) = A(:,4:20,:) -% extract(A,3,[2 10]) = A(:,:,2:10) - -persistent colons - -n=ndims(x); -if length(colons)<n, - colons=repmat({':'},1,n); -end - -s=colons(1:n); %cell(1,n); s(:)={':'}; -s{dim}=range(1):range(2); -S.type='()'; -S.subs=s; -y=subsref(x,S);
--- a/sequences/folddata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -function x=folddata(fn,e,y,varargin) -% folddata - Fold combinator for data sequences -% -% This function applies an associative operator to a list of arguments, -% starting from the left using the given starting element. -% -% folddata :: -% (X,Y->X) ~'associative binary operator', -% X ~'initial element', -% seq Y ~'a lazy data sequence' -% -> X. - -if nargin<4, - x=e; - while ~isempty(y) - x=fn(x,head(y)); - y=next(y); - end -else - opts=prefs('quiet',1,varargin{:}); - x=e; - while ~isempty(y) - x=fn(x,head(y)); - y=next(y); - if ~opts.quiet, fprintf('.'); end - optpause(opts); - end -end
--- a/sequences/gathern.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -function [z,zx]=gathern(dim,n,x) -% gathern - Gather first n elements of sequence -% -% gathern :: natural, natural, seq X -> [Size]. bah. -[z,zx]=gather(dim,take(n,x)); -if nargout==2, zx=next(source(zx)); end -
--- a/sequences/head.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function y=head(x), y=x{1}; % if iscell(x), y=x{1}; else y=x; end; -% head - Head for cell arrays (first element) -% -% head :: {[Size]->A} -> A. - -% old header -% head - Head for non-sequences objects (shouldn'y be used) -% -% head :: A -> A. - -% disp('*** WARNING: head called for non-sequence');
--- a/sequences/isdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -function f=isdata(d), f=isa(d,'data');
--- a/sequences/last.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function z=last(y) -% last - get the last array in a sequence (there must be at least one element) -% -% last :: seq(A) -> A. - -while ~isempty(y) - x=y; - y=next(x); -end - -z=head(x);
--- a/sequences/meandata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -function m=meandata(x,dim,varargin) -% MEANDATA - Mean of a sequence of arrays -% -% meandata :: -% seq [D] ~ sequence of E dimensional arrays of size D, ie D::[[E]] -% I:[[N]->[E]] ~ array of dimension numbers (between 1 and E) to do mean over -% options { -% check_nans :: {0,1}/0 ~'whether to check for (and ignore) nans' -% } -% -> [R] ~ array of size R, where R=set(D,I,1). -% -% if X is a sequence of 5 x 12 x 50 arrays, then -% M=meandata(X,[1,3]) -% returns a 1 x 12 array. -% -% Options: See ITERATE for applicable options - - opts=prefs('check_nans',0,varargin{:}); - - S.total=0; - S.count=0; - - if opts.check_nans, % world of pain - if isempty(dim) - S=folddata(@mean0_nan_st,S,x,varargin{:}); - elseif isscalar(dim) - S=folddata(@mean_nan_st,S,x,varargin{:}); - else - S=folddata(@meandims_nan_st,S,x,varargin{:}); - end - m=S.total./S.count; - else - if isempty(dim) - S=folddata(@mean0_st,S,x,varargin{:}); - elseif isscalar(dim) - S=folddata(@mean_st,S,x,varargin{:}); - else - S=folddata(@meandims_st,S,x,varargin{:}); - end - m=S.total/S.count; - end - - - % non-nan checking accumulators - function S=meandims_st(S,X) - S.total=S.total+sumdims(X,dim); - S.count=S.count+prod(sizedims(X,dim)); - end - - function S=mean_st(S,X) - S.total=S.total+sum(X,dim); - S.count=S.count+size(X,dim); - end - - function S=mean0_st(S,X) - S.total=S.total+X; - S.count=S.count+1; - end - - % nan checking accumulators - function S=meandims_nan_st(S,X) - I=isnan(X); X(I)=0; - S.total=S.total+sumdims(X,dim); - S.count=S.count+sumdims(~I,dim); - end - - function S=mean_nan_st(S,X) - I=isnan(X); X(I)=0; - S.total=S.total+sum(X,dim); - S.count=S.count+sum(~I,dim); - end - - function S=mean0_nan_st(S,X) - I=isnan(X); X(I)=0; - S.total=S.total+X; - S.count=S.count+(~I); - end -end - -
--- a/sequences/next.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,6 +0,0 @@ -function b=next(a) -% NEXT - Default next function for ordinary arrays -just returns the same array - -if isempty(a), error('NEXT called for empty array'); end -b=[]; -
--- a/sequences/nth1.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,8 +0,0 @@ -function [x,tail]=nth1(n,X) -% nth1 - Get nth element of a sequence starting at 1 -% -% nth1 :: natural, seq X -> X, seq X ~'tail of sequence'. - -z=drop(n-1,X); -x=head(z); -if nargout>=2, tail=next(z); end
--- a/sequences/once.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,5 +0,0 @@ -function Y=once(X), Y=take(1,X); -% once - read data once, next is null -% -% once :: seq A -> seq A. -
--- a/sequences/phasedata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -function a=phasedata(source,windowfn) -% PHASEDATA - Spectral data from buffered frames -% -% phasedata :: ( -% source: data[n,l], ~ source data -% windowfn: (n:natural->[n]) ~ function to compute window, eg hanning -% ) -> data[m,l] - -H=spdiag(feval(windowfn,size(source,1))); -a=fndata(@(x)phasespec(H*x),source,'charfn',@charfn); - -function s=charfn(o) - s=sprintf('%s >> phase(%s)',char(source(o)),tostring(windowfn)); -end -end -
--- a/sequences/scandatacols.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -function Y=scandatacols(Fn,Y0,X) -% scandatacols - Scan over columns of array sequence - -Y=scandata(@(y,x)scancols(Fn,y(:,end),x),Y0,X);
--- a/sequences/skip.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -function s=skip(n,s) -% SKIP - Skip the first n alements of sequence -% -% skip :: natural, seq A -> seq A - -disp('*** DEPRECATED: use drop instead'); -for i=1:n, s=next(s); end - - -
--- a/sequences/span.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -function [h,x]=span(f,x) -% span - divide sequence using a test function -% -% span :: (A->bool), seq A -> seq A, seq A. -% -% span f x = (takeWhile f x,dropWhile f x) -% Will not terminate if head segments turns out to be infinite. -[Y,x]=spanc(f,x); -h=celldata(Y);
--- a/sequences/spanc.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ -function [Y,x]=spanc(f,x) -% spanc - divide sequence using a test function -% -% spanc :: (A->bool), seq A -> {[N]->A}, seq A. -% -% spanc f x = (seq2cell (takeWhile f x),dropWhile f x) -% Will not terminate if head segments turns out to be infinite. -% -% Note: this is like span but returns a cell array for the head sequence - -if isempty(x), Y={}; return -else - Y={}; - y=head(x); - while f(y) - Y=horzcat(Y,y); - x=next(x); - if isempty(x), break; end - y=head(x); - end -end -
--- a/sequences/spectraldata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -function a=spectraldata(source,specfn,windowfn) -% SPECTRALDATA - Spectral data from buffered frames -% -% spectraldata :: ( -% source: data[n,l], ~ source data -% specfn: [n,l]->[m,l], ~ compute spectrum from frames -% windowfn: (n:natural->[n]) ~ function to compute window, eg hanning -% ) -> data[m,l] - - H=spdiag(feval(windowfn,size(source,1))); - a=fndata(@(x)specfn(H*x),source); - %a=fndata(fn,source,'charfn',@charfn); - -% function s=charfn(o) -% s=sprintf('%s >> %s/%s',char(source(o)),tostring(specfn),tostring(windowfn)); -% end -end -
--- a/sequences/split.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,11 +0,0 @@ -function [h,t]=split(dim,n,s) -% split - gather first n elements and return with rest of sequence -% -% split :: D:natural, N:natural, seq A -> [[N]->A], seq A - -h=[]; -for i=1:n, x=head(s); h=cat(dim,h,x); s=next(s); end -t=s; - - -
--- a/sequences/squirt.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -function y=squirt(f,x,varargin) -% squirt - send buffered data sequence through a single-item data transformer -% -% squirt :: -% (seq [[N]] -> seq [[M]]) ~'data transforming function', -% seq [[N,L]] ~'buffered sequence', -% options {} ~'any options passed to windowdata' -% -> seq [[M,L]] ~'re-buffered output'. - -y=bufferdata(f(windowdata(x,1,1,varargin{:})),size(x,2));
--- a/sequences/src_cell.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function S=src_cell(D), S=@(z)next_cell(D); -% src_cell - Data source for cell array of arrays -% -% src_cell :: -% {[P]->[[N,_]]} ~'cell array containing P N-by-? arrays' -% -> source(N) ~'returns a source of N-dim data sequences'. - -function [x,F]=next_cell(D), - x=D{1}; - if length(D)==1, F=[]; - else F=@(z)next_cell(D(2:end)); end -
--- a/sequences/src_data.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function F=src_data(D), S=@(z)next_data(D); -% src_data - Data source for data objects -% -% src_data :: -% seq [[N,_]] ~'data object representing sequence of arrays' -% -> source(N) ~'returns a source of N-dim data sequences'. -F=@(z)next_data(Data); - -function [x,F]=next_data(D) - x=head(D); - F=@(z)next_data(next(D)); -
--- a/sequences/src_subseq.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -function F=src_subseq(X,T) -% src_subseq - Data source for subsequences of a big array -% -% src_subseq :: -% [[N,T]] ~'big array', -% [[2,P]] ~'subranges for each of P subsequences' -% -> source(N) ~'returns a source of N-dim data sequences'. - -if nargin<2 || isempty(T), T=[1;size(X,2)]; end; -F=@(z)next_subseq(X,T,1); - -function [x,F]=next_subseq(X,T,n), - x=X(:,T(1,n):T(2,n)); - if n==size(T,2), F=[]; - else F=@(z)next_subseq(X,T,n+1); end -
--- a/sequences/window.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function Y=window(X,varargin), Y=windowdata(X,varargin{:}); -% window - Window a sequnce of arrays in a given dimension -% -% window :: seq [[N,M]] -> seq [[N]]. -% window :: seq [[N,M]], L:natural -> seq [[N,L]]. -% window :: seq [[N,M]], L:natural, natural ~'hop size' -> seq [[N,L]]. -% -% This is just short for windowdata(...) -% Possible optimisation: -% when the span and hop are much less than the input buffer size -% and the source data does not have an efficient extract method, -% then it is worth caching the source data, ie window(cache(x),...)
--- a/sequences/window_ns.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,12 +0,0 @@ -function Y=window_ns(X,W,H), -% window_ns - Window a sequnce of arrays in a given dimension (no strict size) -% -% window_ns :: seq [[N,M]] -> seq [[N]]. -% window_ns :: seq [[N,M]], L:natural -> seq [[N,L]]. -% window_ns :: seq [[N,M]], L:natural, natural ~'hop size' -> seq [[N,L]]. - -if nargin<2, W=1; H=1; -elseif nargin<3, H=W; -end - -Y=windowdata(X,W,H,'strict',0);
--- a/sinks/sinkdata.m Sat Jan 12 19:21:22 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -% sinkdata - write sequence of arrays to sink -% -% sinkdata :: -% seq [[C,N]] ~'sequence of arrays of C channel signal', -% sigsink(C,R) ~'sink' -% natural ~'maximum size of arrays in input' -% -> action. -% -% Third argument defaults to maximum dimension of signal arrays. -% This function does not control the timing of the writes and -% so is suitable for non-real-time writes to eg audio files. - -function res=sinkdata(Y,S,maxbuf) - if nargin<3, maxbuf=max(size(Y)); end - u=construct(S); - try - W=u.writer(maxbuf); - u.start(); foreach(@write,Y); u.stop(); - catch ex - u.dispose(); - rethrow(ex); - end - u.dispose(); - - function write(x) - rem=W(x); - if rem>0, error('Sink is full'); end - end -end - -