%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function [u] = unit_sample( [n[,tp[,sc]]])
%
%       Produces a unit sample (delta) sequence d[n]=1, n=0.
%           It implements the general formula: l*d(n+k)
%           where l is a scaling and k is a shifting factor
%       It can be used without any parameters, 
%       which results in using the following defaults:
%           N: -10:10 (the discrete domain)
%           TP: 0 (the sequence is not shifted)
%           SC: 1 (a scale factor)
%
%       *** Shifting with positive factors shifts to the left for
%       compatibility with the mathematical notations
%
%       Usage examples: 
%           u = unit_sample;
%           u = unit_sample( -5:5, 1);
%           n = -10:10; u = unit_sample( n-1);
%

%
% Copyright © 08-Oct-2012 George P. Pavlidis® (sepdek@sepdek.net, gpavlid@gmail.com)
%
function varargout = unit_sample( varargin)

	switch nargin
		case 0
			n = -10:1:10;
			transition_point = 0;
			scale_factor = 1;
		case 1
			n = varargin{1};
			transition_point = 0;
			scale_factor = 1;
		case 2
			n = varargin{1};
			transition_point = varargin{2};
			scale_factor = 1;
		otherwise
			n = varargin{1};
			transition_point = varargin{2};
			scale_factor = varargin{3};
	end
	
	u = zeros( 1, length( n));
	u(n==-transition_point) = scale_factor;
	
	if nargout==0,
		disp( u);
        stem(n,u,'LineWidth',2);
        grid on;
        title(sprintf('ÊñïõóôéêÞ áêïëïõèßá %sä[n%s]',...
            iif(scale_factor==1,'',sprintf('%d*',scale_factor)),...
            iif(transition_point==0,'',...
                iif(transition_point>0,sprintf('+%d',transition_point),sprintf('%d',transition_point)))),...
            'FontSize',12); 
	else
		varargout{1} = u;
	end;