% fsignal - Class for functional discrete time signals
%
% fsignal :: 
%    R:nonneg  ~'sampling rate',
%    C:natural ~'number of channels',
%    natural ~'signal length'
% -> fsignal(C,R).
classdef fsignal
	properties (GetAccess=private, SetAccess=immutable)
		rate_
		channels_
		length_
	end

	methods (Abstract)
		X=data(a) 
		s=tostring(a)
		y=extract(a,dim,range)
	end

	methods (Sealed)
		function a=fsignal(rate,ch,length)
			a.rate_=rate;
			a.channels_=ch;
			a.length_=length;
		end

		function l=length(a), l=a.length_; end
		function c=channels(a), c=a.channels_; end
		function r=rate(a), r=a.rate_; end

		function varargout=size(a,n), 
			z=[a.channels,a.length];
			if nargin==1 
				if nargout<=1, varargout={z};
				else varargout=num2cell(z);
				end
			else
				varargout{1}=z(n);
			end
		end

		function display(a)
			fprintf('  %s :: fsignal(%d,%g)\n',tostring(a),a.channels,a.rate);
		end

		function y=eval(a,t)
			range=[min(t),max(t)];
			y=extract(a,2,range);
			y=y(:,t-(range(1)-1));
		end
	end
end
