Finding the Derivative

The following example shows how to calculate the derivative of a dataset. Note that the differentiate X-Function is used, and that it allows higer-order derivatives as well:

// Import the data
fname$ = system.path.program$ + "\Samples\Spectroscopy\HiddenPeaks.dat";

// Calculate the 1st and 2nd derivatives of the data in Column 2:

// Output defaults to the next available column, Column 3
differentiate iy:=Col(2);      
// Output goes into Column 4 by default       
differentiate iy:=Col(2) order:=2;    

// Plot the source data and the results

// Each plot uses Column 1 as its x-values
plotstack iy:=((1,2), (1,3), (1,4)) order:=top;

Finding the Derivative with Smoothing

The differentiate X-Function also allows you to obtain the derivatives using Savitsky-Golay smoothing. If you want to use this capability, set the smooth variable to 1. Then you can customize the smoothing by specifying the polynomial order and the points of window used in the Savitzky-Golay smoothing method. The example below illustrates this.

// Import a sample data with noise
fpath$ = "\Samples\Signal Processing\fftfilter1.DAT"; 
fname$ = system.path.program$ + fpath$;

// Differentiate using Savitsky-Golay smoothing
differentiate iy:=col(2) smooth:=1 poly:=1 npts:=30;

// Plot the source data and the result
newpanel row:=2;
plotxy iy:=[bkname$]1!2 plot:=200 ogl:=1;	
plotxy iy:=[bkname$]1!3 plot:=200 ogl:=2;