SIP Toolbox
fftderiv - Derivative of a vector using FFT
Calling Sequence
- [Dy, DY] = fftderiv(y, [n , sigma, delta, in, out])
- [Dy, DY] = fftderiv(y, <named_args>)
Input Parameters
-
y:
vector containing a periodic window of a function to be differentiated.
-
n:
the order of the derivative. It is 1 for 1st derivative, 2 for 2nd derivative, and so on.
-
sigma:
the standard deviation of the gaussian kernel used to smooth the input. If sigma is zero, fftderiv will not smooth the input. (Defaults to 5)
-
delta:
a double number. If the input is in the time domain, this is the time between samples (delta t), and defaults to 1. If the input is in the frequency domain, this is the frequency increment between samples (delta f), and defaults to 1/N, where N is the number of samples.
-
in:
indicates if the input, x, is a function of time (no FFT has
been applied) or frequency (FFT has already been applied). Can
be 'time' or 'frequency'. (Defaults to 'time')
-
out:
Can be 'time', 'frequency', or
'complex'(Defaults to 'time'). This
indicates if the desired output xsm is a function of time
(inverse FFT will be applied) or frequency (inverse FFT
will not be applied). Use the value 'complex' if
you want the output in time domain but without eliminating
the inverse FFT's complex part.
-
<named_args>:
This is a sequence of statements key1=value1, key2=value2,... where
key1, key2,... can be any of the optional arguments above,
in any order.
Output Parameters
-
Dy:
the derivative vector in "time" or "frequency" domain, or in
time domain with "complex" component.
-
FDy:
the derivative vector in "frequency" domain.
Description
Function fftderiv performs the n-th derivative of a periodic
function, stored in a vector, using FFT. The optional arguments in
and out enables the user to reuse previously done FFTs. Here are
some possible uses:
- Dy = fftderiv(y)
-
n defaults to 1, sigma defaults to 5,
in and out both defaults to 'time'.
- Dy = fftderiv(y,2,3)
-
n equals 2, sigma equals 3,
in and out both defaults to 'time'.
- Dy = fftderiv(y,sigma=3, in='frequency',out='frequency')
-
n dafaults to 1,
y in frequency domain (fft has already been done).
Dy in frequency domain (inverse fft is NOT done by gsm)
In all above examples, FDy is in the frequency domain. It
is the second output parameter, and thus it was discarded in the
above examples.
Examples
step = 2*%pi/100;
y = sin(step:step:2*%pi); // from 2pi/100 to 2pi
xbasc()
plot(y);
// 1st derivative, a sigma of 3 steps to the left and to the right
d = fftderiv(y,1,3*step,step);
xbasc()
plot(d) // a cosine period
Authors
-
Ricardo Fabbri <ricardofabbri (AT) users DOT sf DOT net>
Remarks
For a derivative without noises,
the vector y must be an exact period of a continuous periodic function,
i.e., its repetition has to be continuous. A direct way for checking
this is to plot z = [y y] and look close in the middle. If there is
not a minimal discontinuity, then fftderiv will certainly work
without need for smoothing.
y should be smoothed before using fftderiv so the
derivative is less sensitive to discontinuities and aliasing.
For an estimation of the sigma parameter, please refer to
the references below.
Bibliography
"Shape Analysis and Classification", L. da
F. Costa and R. M Cesar Jr., CRC Press,
pp. 335-347.
"1D and 2D Fourier-based approaches to numeric curvature estimation
and their comparative performance assessment", L. F. Estrozi, L.
G. R. Filho, A. G. Campos and L. da F. Costa,
Digital Signal Processing, 2002.
Availability
The latest version of the Scilab Image Processing toolbox can be found at
http://siptoolbox.sourceforge.net
See Also
follow, gsm, fftshift, curvature,