%    Real-valued Noiselet Transform
% 
%    Usage: w = realnoiselet(x)
%    x must be a REAL VALUED COLUMN VECTOR or MATRIX
%    m = size(x,1) must be a POWER OF TWO
% 
%    Notes:
%    1) This implementation uses exactly m*log2(m) additions/subtractions.
%    2) This is a real-valued variation of "dragon" noiselets.
%    3) This is symmetric and orthogonal. To invert, apply again and
%       divide by m.
% 
%    Written by: Justin Romberg, Georgia Tech
%                Peter Stobbe, Caltech
%    Email: jrom@ece.gatech.edu, stobbe@acm.caltech.edu
%    Created: October 2006
%    Last Modified: December 2006
%
%    Wrapped by Hannes Nickisch

function w = realnoiselet(x)

% check for a valid executable
if exist('realnoiselet','file')~=3
  OCT = exist('OCTAVE_VERSION') ~= 0;         % check if we run Matlab or Octave
  
  me = mfilename;                                          % what is my filename
  mydir = which(me); mydir = mydir(1:end-2-numel(me));      % where am I located
  if OCT && numel(mydir)==2
    if strcmp(mydir,'./'), mydir = [pwd,mydir(2:end)]; end
  end               % OCTAVE 3.0.x relative, MATLAB and newer have absolute path

  mycd = pwd; 
  eval(['cd ',mydir])
   
  if OCT                                 % distinguish between Matlab and Octave
    mkoctfile --mex realnoiselet.c
    delete realnoiselet.o
  else
    mex -O realnoiselet.c
  end
  clear functions
  w = realnoiselet(x);
  eval(['cd ',mycd])
end