From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Smoothing a curve

Hi Folks.

 

I am trying to smoothen a curve to a set of data points using Cublic Spline. The graph on the right is the actual recorded data and the image on the left is the fitted curve with a balance parameter of 20. Changing this value does not have much impact on the outcome. When I try and put values in the weight and smoothness parameters the plot is not visible. I'm not entirely what these do or how to adjust them. I would like to have one smooth curve running through all the data points. How can I accomplish this?

 

Alternatively I would like to determine the point at the arrow. It is not always the highest value (like in this case) so cannot determine it using max value. It is always followed by downward incline as shown.

 

Curve.png

 

Thanks,

 

Mark.

0 Kudos
Message 1 of 9
(4,774 Views)

I guess you mean "cubic spline". May I ask why you want to fit a polinomial curve to data points? It has only "cosmetic" purpose, it will not reveal any physical "meaning" behind measurement data...

 

About finding a point which is followed by a decreasing trend: you could derivate the signal, and look for drastic change in the derivative. Of course, you have to tune your algorithm, you need to introduce a threshold value (actually two values: one for the derivative, another for the time window size), which decides a decreasing trend starts or not.

 

Edit: for the first part some more notes:

If you wanna remove noise from your signal, you could filter it. Also, you could use a kind of "moving average" using a Pointbypoint Mean function for example. These all can smooth your curve. After filtering, you can derivate the signal to get the slope change in time, to decide when the decrease starts...

Message 2 of 9
(4,755 Views)

If I have a smooth curve the highest point would represent the point I am after. I could then find the max point of the curve. The problem I am facing is that I am not able to get the curve to be smooth.

0 Kudos
Message 3 of 9
(4,730 Views)

One way to find the inflection point, IF the decline is reasonably steady, is to take two points, known to be on the decline part, and calculate the slope and intercept of a line between them.

Then calculate where that line would cross the mean of the data before the inflection point.

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 4 of 9
(4,690 Views)

The graph on the right is the actual recorded data and the image on the left is the fitted curve with a balance parameter of 20.



Doesn't the balance parameter have to be between 0 and 1?  The 2010 LV help page indicates that.

 

Setting it lower than 1 should help smooth the fit.  Be careful though, figureing out the best balance parameter is a dangerous game of smoothness vs. accuracy. Your data doesn't look too noisy, so you probably don't need it to be very low (or even need it at all).  I'd still suggest that you look into Blokk's and Coastal's suggestions.

0 Kudos
Message 5 of 9
(4,631 Views)

I have experimented with slope change already. The problem is that there are some very drastic point to point changes even if the overall slope is gradual.

 

The inflection method would be ideal except I cannot determine exactly what points to use as this will be different for each recording. I could start at the end and get the slope of it that way. Is it possible to have two straight lines, one generated from the first few data points and the second from the last and then find the point of intersection.

0 Kudos
Message 6 of 9
(4,608 Views)

 I cannot determine exactly what points to use as this will be different for each recording.

 

I'm not surprised by that.

 

 

Is it possible to have two straight lines, one generated from the first few data points and the second from the last and then find the point of intersection?

 

Sure, that's basic geometry.  Just find the equations for Slope(m) and Intercept (b) of each line.

 

So, your first part will have an equation Y1 = m1X + b1

 

The second part will have an equation Y2 = m2X + b2

 

You know at the intersection, that Y1 must be equal to Y2

 

So,  m1X + b1 = m2X + b2.  Solve for X and that's your intersection.

 

Now, that's easy to do, whether it's PROPER is going to depend on what sort of gyrations your real curve makes in the vicinity of the inflection point, and whether the straight-line assumption is valid.

 

When finding the slope and intercept, it's best to use points as far apart as you can.

 

Steve Bird
Culverson Software - Elegant software that is a pleasure to use.
Culverson.com


Blog for (mostly LabVIEW) programmers: Tips And Tricks

0 Kudos
Message 7 of 9
(4,600 Views)

I have experimented with slope change already. The problem is that there are some very drastic point to point changes even if the overall slope is gradual.

 

That is why you have to remove the outliers with filtering. This topic is advanced, there is not a single straightforward solution. Look at the Peak Detector VIs in LabVIEW, they also use some kind of threshold and time window width parameters...maybe it can also give you a good idea...

0 Kudos
Message 8 of 9
(4,590 Views)

I have decided to use a method that waits until the array is full and then determines if the value is greater than the next and next and so on. This will craete an array or true's at this point (still need to isolate the first one). As there is a steady decrease this should suffice. As you can see in the image below (white being the raw data) it is not entirely steady and in some rare cases can increase slightly. The cubic spline takes care of this problem.

 

However the balance parameter is supposed to be between 0 and 1. 0 being a linear fit (no good) and 1 following each point exactly (no good). The red graph shown below has a balance parameter of 20 and works as I want. So my question is why is this and should I avoid using this value???

 

Curve.jpg

0 Kudos
Message 9 of 9
(4,527 Views)