slope for discrete data set

2 views (last 30 days)
Shawn
Shawn on 7 Mar 2012
I'm trying to find the slope of a set of Y vs X acquired data, relatively smooth, but the simple difference calculations are too sensitive to the small variations between points and it gives me garbage (ie diff(Y)./diff(X)). I also tried playing around with high order diff (which makes it worse if anything).
All I really want is dY/dX in a piecewise fashion. (note: Y is a triangular ramp through 0, which complicates things slightly, so a simple Y/X fails near the zeros generally, depending on which approaches zero more quickly, the original data was actually originally taken as X vs Y also).
Suggestions? I did see one possible suggestion, that being to do a series of piecewise fits and just differentiate those polynomials, this might work and I'll try it, but with 10's of thousands of points or more often and my aging machine I suspect that may be painful. This is also roughly equivalent to (but better than) the first idea that usually comes to mind, just manually taking a larger interval for each section, the main issue is that the smaller the interval in points then we have discrete differences blow up in the division.
I'm mostly trying to see if there is a terribly simple routine or set thereof that I'm missing here, I imagine its a typical problem!
(also note, these are not straight linear data in some regions, so simply fitting it directly doesn't cut it)
Edit- Thanks for the comments, I didn't see them at first as its set to only email me on responses, I've included below 100 points (of the roughly 10000 in this set) just as a sample as suggested. (x for the left column, y for the right)
I've toyed with a few approaches and noted the following: 1) Direct Y/X, plotted vs Y gives the best looking data but there are several discontinuities (not shown here). Smoothing after the fact can largely deal with these (particularly using a weighted smoothing).
2) Fitting the data in polynomial segments and then differentiating is much noisier. Filtering prior to the fits is less effective than a relatively large smoothing interval after fitting. Still significantly noisier than the direct division.
The difference is that the two approaches have slightly different meaning for our results in the end (particularly in the cases where dY/dX is NOT at constant).
-1.10E-06 -0.481361508
-1.09E-06 -0.480730891
-1.10E-06 -0.479786366
-1.10E-06 -0.479286551
-1.10E-06 -0.478338271
-1.09E-06 -0.47756061
-1.09E-06 -0.476789564
-1.09E-06 -0.476021975
-1.08E-06 -0.475403458
-1.08E-06 -0.474456042
-1.09E-06 -0.473825306
-1.08E-06 -0.473029017
-1.08E-06 -0.472398341
-1.08E-06 -0.471460402
-1.07E-06 -0.47082144
-1.07E-06 -0.469870895
-1.06E-06 -0.469371557
-1.07E-06 -0.468418747
-1.07E-06 -0.467614919
-1.06E-06 -0.466842145
-1.06E-06 -0.466194898
-1.06E-06 -0.465424955
-1.06E-06 -0.464635998
-1.05E-06 -0.463834733
-1.05E-06 -0.463188082
-1.05E-06 -0.462409467
-1.04E-06 -0.461637259
-1.04E-06 -0.460995466
-1.04E-06 -0.460195333
-1.04E-06 -0.45955807
-1.05E-06 -0.458625674
-1.04E-06 -0.457986921
-1.03E-06 -0.45704174
-1.03E-06 -0.456277221
-1.03E-06 -0.455652624
-1.02E-06 -0.45484817
-1.02E-06 -0.4540748
-1.02E-06 -0.453320026
-1.02E-06 -0.452527255
-1.01E-06 -0.451880902
-1.01E-06 -0.451089054
-1.01E-06 -0.450306267
-1.01E-06 -0.449679822
-1.00E-06 -0.448866904
-9.95E-07 -0.448206544
-9.98E-07 -0.447284818
-9.96E-07 -0.446647674
-9.93E-07 -0.445697248
-9.89E-07 -0.445217252
-9.87E-07 -0.444231212
-9.83E-07 -0.443440646
-9.84E-07 -0.442805558
-9.84E-07 -0.442012638
-9.81E-07 -0.441236675
-9.76E-07 -0.44045651
-9.77E-07 -0.439672261
-9.73E-07 -0.439033031
-9.72E-07 -0.438235641
-9.69E-07 -0.437435597
-9.66E-07 -0.436803222
-9.64E-07 -0.435873568
-9.65E-07 -0.435232252
-9.58E-07 -0.434272319
-9.58E-07 -0.433794916
-9.60E-07 -0.432829469
-9.56E-07 -0.432014257
-9.53E-07 -0.431235731
-9.51E-07 -0.430586189
-9.45E-07 -0.429812312
-9.41E-07 -0.429061055
-9.44E-07 -0.428266853
-9.40E-07 -0.427619725
-9.39E-07 -0.426817536
-9.35E-07 -0.426050305
-9.35E-07 -0.425403476
-9.32E-07 -0.424580961
-9.30E-07 -0.423950702
-9.23E-07 -0.423029482
-9.26E-07 -0.422385722
-9.21E-07 -0.421436965
-9.20E-07 -0.420662194
-9.20E-07 -0.419880807
-9.15E-07 -0.419231355
-5.75E-07 -0.418459505
-9.09E-07 -0.417694181
-9.05E-07 -0.41690132
-9.04E-07 -0.416252166
-9.04E-07 -0.415457159
-8.98E-07 -0.414673597
-8.96E-07 -0.41404134
-8.95E-07 -0.41324386
-8.95E-07 -0.412609458
-8.93E-07 -0.411673218
-8.91E-07 -0.411031365
-8.91E-07 -0.410095036
-8.91E-07 -0.409606814
-8.85E-07 -0.408632755
-8.84E-07 -0.407827556
-8.78E-07 -0.40719828
-8.77E-07 -0.406405121
-8.78E-07 -0.405627698
  2 Comments
the cyclist
the cyclist on 8 Mar 2012
It would be helpful if you could show a small sample of representative X and Y data, and approximately what you would expect as output.
Walter Roberson
Walter Roberson on 8 Mar 2012
Perhaps you should put the data through a low-pass filter to eliminate the high-frequency variation?

Sign in to comment.

Answers (0)

Categories

Find more on Polynomials in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!