%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function [u] = exponential( [n[,bs[,[tp[, sc]]]])
%
%       Produces an exponential sequence a^n.
%           It implements the general formula: l*a^(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)
%           BS: 1 (a parameter)
%           TP: 0 (no shifting of the sequence)
%           SC: 1 (a scale factor)
%
%       *** Shifting with positive factors shifts to the left for
%       compatibility with the mathematical notations
%
%       Usage examples: 
%           u = exponential;
%           u = exponential( -5:5, 0.8);
%           n = -10:10; x = exponential( n-1, -0.8);
%
%       Special case:
%           when a = e^jw => this function returns a complex sequence
%           comprising of a cos(nw) (real) and a sin(nw) part (imag)
%

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

	switch nargin
		case 0
			n = -10:1:10;
			base = 1;
			shift = 0;
			scale_factor = 1;
		case 1
			n = varargin{1};
			base = 1;
			shift = 0;
			scale_factor = 1;
		case 2
			n = varargin{1};
			base = varargin{2};
			shift = 0;
			scale_factor = 1;
		case 3
			n = varargin{1};
			base = varargin{2};
			shift = varargin{3};
			scale_factor = 1;
		otherwise
			n = varargin{1};
			base = varargin{2};
			shift = varargin{3};
			scale_factor = varargin{4};
	end
	
	x = scale_factor .* base .^ (n+shift);
	
	if nargout==0,
		disp( x);
        stem(n, x,'LineWidth',2);
        grid on;
        title(sprintf('ÅêèåôéêÞ áêïëïõèßá %.3f^{[n%s]}',...
            scale_factor*base, ...
            iif(shift==0,'',...
                iif(shift>0,sprintf('+%d',shift),sprintf('%d',shift)))),...
            'FontSize',12); 
	else
		varargout{1} = x;
	end;