LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Curve Fitting Step Function

Hi, I am trying to model a step function using a thermocouple. I can acquire the data and display this - showing the step function using the gate and trigger vi. However, I cannot seem to get the curve fitting to work. Instead of the best fit showing a step function, it is looking more like an exponential.

 

I think it might be to do with my 'location' inputs but I thought this would just be the time channel?

 

Thanks,

 

Scot07

 

 

Download All
0 Kudos
Message 1 of 10
(4,531 Views)

I haven't (yet) looked at your code, but I'm tempted to say "Of course it looks like an Exponential, since the response I'd expect for a thermocouple to a step input would be an Exponential ..."  [Do you know about Resistor-capacitor (RC) circuits, and what the voltage across the capacitor looks like when you connect a battery?  Do you know why?]..

 

On the other hand, you should be able to (trivially!) fit a Step to the data -- before you turn on the juice, measure the voltage -- this is the "base" of your step.  Now go out 2-3 time constants and take the mean value where it "levels off" -- this is the size of your step!

 

Now I'll look at your code, and maybe make another post.  [I can not even imagine what you mean by "showing the step function using the gate and trigger vi".]

 

Bob Schor

Message 2 of 10
(4,504 Views)
  • To get better help, please strip our your DAQ function and replace it with typical data.
  • If you would make the stop button latch action, you would not need to reinit it (bad form!). Are you familiar with mechanical action settings?
  • Please don't maximize the diagram and front panel to the screen. Very annoying!
  • You don't have a step function, but a function containing at least four components. An initial delay where the value is constant (or even has a constant frequency oscillation...), a spike, and an exponential to a new value, and later a new delay to a lower value. Your model needs to reflect that with a sufficient number of parameters, or you need to truncate the data to the subset containing only the exponential starting at exactly the right t0, which might be diffcult to find.
  • You can only use "general least squares linear" if you exactly know the time constant beforehand as a constant and if the data and terms are perfectly aligned in time. Can you guarantee all that?
  • If you want to determine the exponential time constant, you need non-linear least squares.
  • Real step functions and spikes require caution, because the partial derivatives are not nice.
  • Why do you think you need to calculate the time ramp with every run? Wouldn't that belong before the while loop? And why does it contain 1k points?
  • I cannot look at your DAQ configurations, but do you really only take&process 10 samples at a time, keeping the entire trace only in the chart buffer? Seems completely wrong. Charts are NOT the right tool here. You need to collect all data in memory and only process once you have it all.

In any case, reduce the VI to something that only contains the data shown in your charts and we might be able to help. Can't be very hard.

 

Message 3 of 10
(4,491 Views)

Here's a very simple way to fit a delayed exponential using conventional code (most advanced users stay far away from express VIs and dynamic data!)

 

Maybe it can give you some hints:

 

DelayedExponential.png

Message 4 of 10
(4,480 Views)

We have been told to use the express VIs so no option to get rid of them!

 

I've removed the while loop - the reason for the intialize to default was that I was using it in a producer-consumer loop previously and you cannot use a latch mechanism for local variables!

 

The spike from the initial graph is noise picked up - I've attached a better diagram to show the 'step function' - I'm aware this is not a perfect step function but this is not possible with the hardware. 

 

I know it's possible to use the setup I have to get the output I want but I think I'm not putting the correct input into the Locations terminal of the Curve Fitting Express VI. I did have the wrong setup for this initially but I have now changed this to non-linear but still getting the same issue. 

 

I'm happy with most of the code - I just can't get the best fit to follow the 'step function'

0 Kudos
Message 5 of 10
(4,470 Views)

As we said, it's not a "Step function" but close to an exponential decay from one to another steady state value. Express VI fitting is not really usable unless you clip the data first so time zero is exactly at the start. Why sets these arbitrary restrictions to use express VIs? Makes no sense. You need to use the right tools for the job.

 

What parameters are you interested in? Just where the step is? The time constant? The difference between start and end values? Something else? Once you define the problem in detail, we can better see what needs to be done.

0 Kudos
Message 6 of 10
(4,464 Views)

Maybe I should reword my question:

 

I have a transient from a thermocouple as it goes from one steady temperature (around 20C) to another temperature (50C). I want to measure the time constant and plot a best fit curve (we have to use the curve fitting express vi). I can clip the data to wherever is best - I was looking at around 500 points before and after the threshold but I can change this to immediate if need be?

 

I am probably not wiring up (or settting up) the curve fitting express vi. There are no examples from NI that show how to do this.

 

I assume that the locations input is just the time variable? 

 

Do I need to change the equation and initial guesses in the express vi? If so - what is the best equation to use?

 

Thanks,

 

Scot07

0 Kudos
Message 7 of 10
(4,408 Views)

If you want to include the 500 before points, your nonlinear model needs to reflect that and return a constant y value for all these points.

 

(Still curious who is forcing you to use express VIs. Completely arbitrary and even dumb restriction.)

 

Message 8 of 10
(4,402 Views)

I eventually got this to work. I just changed the function in the curve fitting vi. 

 

(This is a university assignment and the lecturer wants us to use express vi's - Not what I would use either but them's the rules) 

 

Now to find the time constant...

0 Kudos
Message 9 of 10
(4,385 Views)

@Scot07 wrote:

I eventually got this to work. I just changed the function in the curve fitting vi. 

...

Now to find the time constant...


If you "got it to work" and implemented the function correctly, one of the parameters is the time (or rate) constant already, depending on how you define it. (For example, the fourth parameter here is it)

0 Kudos
Message 10 of 10
(4,377 Views)