function [Dy, DY]=fftderiv(y,n,sigma,in,out)
//
// nth derivative of a vector by FFT.
// 
// AUTHOR
//    Ricardo Fabbri  <rfabbri@if.sc.usp.br>
//    Cybernetic Vision Research Group
//    Luciano da Fontoura Costa, supervisor.
//    http://cyvision.if.sc.usp.br
//
// $Revision: 1.6 $  $Date: 2002/03/26 23:48:42 $

if size(y,'c') < size(y,'r') then
  y = y.' 
end

rhs = argn(2)
if rhs<1 
   error('Invalid number of arguments.');
end

if ~exists('n','local')
   n = 1
end
if ~exists('sigma','local')
   sigma = 5
end   
if ~exists('in','local')
   in = 'time'   
end   
if ~exists('out','local')
   out = 'time' 
end   


select in 
case 'time'
   Y = fft(y,-1)
case 'frequency'
   Y = y
else
   error('''in'' must be ''time'' or frequency''')
end

sz=size(y,'c');
w=linspace(-sz/2,sz/2 -1,sz);
w=fftshift(w);

if sigma == 0 then
   G=ones(y)
else
   p= (2*%pi/sz) * w * sigma;
   G=exp(-0.5*p.^2);
end

//DY = Y .* G .* ( (%i*2*%pi*w).^n );
DY = Y .* G .* ( (%i*w).^n );

select out
case 'time'
   Dy = real(fft(DY,1)); 
case 'complex'
   Dy = fft(DY,1);
case 'frequency'
   Dy = DY
else
   error('''out'' must be ''time'' or ''frequency''');
end

//
// -------------------------------------------------------------------------
// SIP - Scilab Image Processing toolbox
// Copyright (C) 2002  Ricardo Fabbri
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
// -------------------------------------------------------------------------
//
