% function [ y ] = reverse_signal( [n[,x]])
%
%          Reverses (flips left-right) a sequence about the origin
%          If the domain N is omitted it is defined automatically as if the
%          signal X is centered about the origin
%

%
% Copyright © 24-Oct-2012 George P. Pavlidis® (sepdek@sepdek.net, gpavlid@ceti.gr)
%
function varargout = reverse_signal( varargin)

	switch nargin
		case 1
			n = [];
			x = varargin{1};
		otherwise
			n = varargin{1};
			x = varargin{2};
	end
	
	if isempty( n)
		l = length(x);
		y = x(l:-1:1);
		n = -round(l/2)+1:round(l/2)-1;
	else
		c = find( n==0);
		y = zeros( 1, length( x));
		y(c) = x(c);
		y(1:c-1) = x(2*c-1:-1:c+1);
		y(c+1:2*c-1) = x(c-1:-1:1);
	end
	
	switch nargout
		case 0
			subplot(211); 
				stem(n,x,'LineWidth',2); 
				grid on; 
				axis equal; axis tight; 
				title('x[n]','Fontsize',14);
			subplot(212); 
				stem(n,y,'LineWidth',2); 
				grid on; 
				axis equal; axis tight; 
				title('x[-n]','Fontsize',14);
		otherwise
			varargout{1} = y;
	end