%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% function [u] = sinusoidal( [n[,w[,f[,k[,l]]}]])
%
%       Produces an sinusoidal sequence cos(wn).
%           It implements the general formula: l*cos(w(n+k)+f)
%           where l is a scaling and k is a shifting factor and f a phase
%           shifting factor
%       It can be used without any parameters, 
%       which results in using the following defaults:
%           N: -10:10 (the discrete domain)
%           W: 1 (the frequency parameter w)
%           F: 0 no phase shift
%           K: 0 (no shifting of the sequence)
%           L: 1 scale factor
%
%       *** Shifting with positive factors shifts to the left for
%       compatibility with the mathematical notations
%
%       Usage examples: 
%           u = sinusoidal;
%           u = sinusoidal( -5:5, 0.8);
%           n = -10:10; x = sinusoidal( n-1, -0.8);
%

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

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