|
Calling Sequence
|
|
DifferentiateData( X, n, options )
|
|
Parameters
|
|
X
|
-
|
1-D rtable or list of complexcons data
|
n
|
-
|
(optional) positive integer, specifies the order of differentiation. The default is 1.
|
|
|
|
|
Options
|
|
•
|
degree: Positive integer, specifies the degree of the polynomial or spline used to extrapolate points for the finite difference and Savitzky-Golay methods. The default is 3.
|
•
|
frameradius: Positive integer, specifies the radius of the frame used for the Savitzky-Golay method. The default is 5.
|
•
|
extrapolation: One of periodic, polynomial, and spline, specifies how the data in X is extrapolated. The default is polynomial.
|
•
|
splinepoints: Positive integer other than 1 or infinity, specifies the maximum number of data points used to perform spline extrapolation. The default is 10.
|
•
|
method: One of backward, central, forward, savitzkygolay, and spectral. The default is central.
|
•
|
step: Positive numeric value, specifies the time step between successive data points. The default is 1.0.
|
|
|
Description
|
|
•
|
The DifferentiateData(X,n) command computes the derivative of order n for data container X. It is assumed that the data in X originated from a signal sampled uniformly with the time between samples being step.
|
•
|
For the discussion below, assume is indexed from to with being the size of , and let be the order of differentiation, be the size of the time interval over which the signal is sampled, , and . Moreover, we denote by the derivative of order for .
|
•
|
The three finite difference methods, namely backward, central, and forward, and the savitzkygolay method all use extrapolation on the left and right ends to lengthen so that the derivative of order is of the same size as . This extrapolation can be performed in three ways:
|
•
|
extrapolation=periodic: The data is assumed to be periodic, so that for each integer .
|
•
|
extrapolation=polynomial: Using the CurveFitting[PolynomialInterpolation] command, interpolating polynomials of degree (at most) are used to extend on the left and right.
|
•
|
extrapolation=spline: Using the CurveFitting[ArrayInterpolation] command, splines of degree (at most) are used to extend on the left and right.
|
•
|
For method=central, the size of the signal must satisfy . For the other methods, .
|
•
|
For both method=backward and method=forward, and must satisfy , whereas for method=central, they must satisfy . Moreover, must satisfy .
|
•
|
For the finite difference methods, we use the standard formulas. For method=forward:
|
•
|
When method=savitzkygolay, the Savitzky-Golay Filter is used to estimate the derivative. The frame radius should satisfy and , and the degree should satisfy . Note that the option degree serves the additional role as the degree of the fitting polynomials used in the Savitzky-Golay smoothing.
|
•
|
When method=spectral, the derivative property of the Fourier Transform is used to find the derivative of order for :
|
1.
|
Compute the FFT of .
|
2.
|
Compute the element-wise product of and , where is defined below.
|
3.
|
Compute the Inverse FFT of Z, which is the derivative of order of .
|
|
The elements of are given by the following:
|
•
|
The spectral method works best when the data represents periodic data, particularly when it is a finite linear combination of sinusoidal terms having frequency no larger than the sample rate. Note: If the original signal is periodic with period , the final data point should correspond to the final sample before , since the sample at time would be the same as time . See below for an example.
|
•
|
The DifferentiateData command is most accurate when the signal is not too noisy, the size of the signal is large, and the order of differentiation is small.
|
•
|
Maple will attempt to coerce the provided data container to a 1-D Vector of either float[8] or complex[8] datatype for the Savitzky-Golay method and any of the finite difference methods, and complex[8] for the spectral differentiation method. An error will be thrown if this is not possible. For this reason, it is most efficient for the passed input to use the appropriate datatype (float[8] or complex[8]).
|
•
|
The data container must have no indexing function, and use Fortran ordering and rectangular storage.
|
•
|
The DifferentiateData command is not thread safe.
|
|
|
Examples
|
|
>
|
|
|
Example 1
|
|
•
|
For our first example, we will differentiate data, obtained (for the convenience of comparison) from a polynomial source. First, generate the times and signal Vectors, and note the time step, all using the GenerateSignal command:
|
>
|
|
>
|
|
•
|
Since the data does not have any erratic behavior, we expect this approximation to be good:
|
>
|
|
| (2) |
>
|
|
|
|
Example 2
|
|
•
|
In this example, we consider real-valued, periodic data. First, generate a signal, along with the times Vector and time step:
|
>
|
|
•
|
Second, compute the first derivative three ways, one directly with the GenerateSignal command (for comparison), and two with the DifferentiateData using different options:
|
>
|
|
>
|
|
>
|
|
•
|
The central approximation for the first derivative is fairly accurate, and the spectral approximation is exceptionally accurate:
|
>
|
|
| (4) |
>
|
|
| (5) |
•
|
Third, compute the second derivative, again in three ways, and calculate the accuracy of the approximations:
|
>
|
|
>
|
|
>
|
|
•
|
As with the first derivative, the approximations for the second derivative are fairly accurate (but less so than for the first derivative):
|
>
|
|
| (6) |
>
|
|
| (7) |
>
|
|
•
|
When we constructed the data, we omitted the point at since it corresponds to the point at . If the final point is included, the spectral approximation for the derivative is greatly affected at the endpoints:
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
| (9) |
|
|
Example 3
|
|
•
|
First, generate a signal:
|
>
|
|
| (10) |
>
|
|
•
|
Second, compute the first and second derivatives, both directly and numerically:
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
| (11) |
>
|
|
| (12) |
•
|
Finally, plot the first and second derivatives:
|
>
|
|
>
|
|
>
|
|
|
|
Example 4
|
|
•
|
Complex data can also be differentiated:
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
>
|
|
|
|
Example 5
|
|
•
|
The Savitzky-Golay method can also be used to estimate the derivative:
|
>
|
|
| (13) |
>
|
|
>
|
|
•
|
Comparing with the actual derivative:
|
>
|
|
>
|
|
| (17) |
|
|
|
Compatibility
|
|
•
|
Starting with Maple 2023, external C code is used for the auxiliary procedures that were formerly implemented in Maple and could be compiled by passing the compiled option. The compiled option is now deprecated, but it is still accepted for backwards compatibility.
|
•
|
The SignalProcessing:-DifferentiateData command was introduced in Maple 2022.
|
•
|
The SignalProcessing:-DifferentiateData command was updated in Maple 2023.
|
•
|
The frameradius option was introduced in Maple 2023.
|
•
|
The method option was updated in Maple 2023.
|
|
|
|