Code covered by the BSD License

### Highlights from der.m v1.0 (Nov, 2009)

Be the first to rate this file! 4 Downloads (last 30 days) File Size: 5.09 KB File ID: #25818 Version: 1.0

# der.m v1.0 (Nov, 2009)

### Carlos Adrian Vargas Aguilera (view profile)

Estimates first derivative of an array by using POLYFIT locally on each point ignoring NaNs!

File Information
Description

DER Estimates the derivative of an array X with respect to its argument T: dX/dT by evaluating the slope of a polynomial fit of elements "close" to each point. This "closeness" is controlled by an optional input called window width, in turn this controls the smoothness.

Syntax:
>> dXdT = der(X,DT);
where X is a time series and DT its sampling interval.
>> dXdT = der(X,T);
if T is not uniform.

Other optional inputs are:
- the window width (W)
- the polynomial fit degree (DEG)
- the padding (PAD) % to improve derivatives at edges

Besides, the error of the dXdT estimate may be obtained.

Enjoy it!
Bugs reports and comments will be very appreciated!

Acknowledgements

Movingslope and Nanderivative.M V2.1 (Jul 2009) inspired this file.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Comments and Ratings (2)
21 Dec 2011 Thomas Clark

### Thomas Clark (view profile)

*** Amendment

Sorry, I cut and pasted the wrong code above.

Code to produce error is:

F = rand(14,14,14);
h = [1 1 1];
Wn = 11;
Deg = 3;

??? Error using ==> vertcat
CAT arguments dimensions are not consistent.

Error in ==> der at 304
T = [interp1((1:2)',T(1:2,:) ,repmat((-W2+1:0)' ,1,n),[],'extrap'); T;

Error in ==> tryDer at 45

Kind regards

Tom

Comment only
21 Dec 2011 Thomas Clark

### Thomas Clark (view profile)

Hi Carlos,

This is potentially awesome!

However, I've got two concerns:

1. There may be a bug for some inputs. I tried to get derivative (in the columnar direction) of a lot of vectors in a 3D array, and get:
F = rand(10,10,10);
h = [1 1 1];
Wn = 9;
Deg = 2;

??? Error using ==> reshape
To RESHAPE the number of elements must not change.
Error in ==> polyGradient>der at 245
T = reshape(permute(DT,[DIM 1:DIM-1 DIM+1:Ndim]),m,n);

2. The mlint code analyser highlights a possibly ill-conditioned use of inv( ) at line 365. Is it justified, or is in not possible to use \ for this computation?

Thanks so far, it's looking like this will be very useful, even if only limited to 1D.

Kind regards

Tom

Comment only