Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Anshuman18

Member

12-20-2022 06:42 AM

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Labels:

We are trying to measure the exit flow rate from a tank by calculating the rate of change of mass of the tank. We are continuously acquiring mass of tank using a weighing balance in LabView and trying to compute the derivative. For this purpose we are using the Savitzky Golay filter coefficient VI to provide the first order differentiation filter. We have made a VI for acquiring data and computing the flowrate based on derivative of mass. But while running the VI we are getting the value of derivative of mass equal to the mass which is completely wrong. I have tried to figure out the problem but couldn't find one in the VI. I have attached the VI please have a look at it and suggest any solution if possible. Also, please suggest any other scheme to find out derivative in LabView.

Bob_Schor

Knight of NI

12-20-2022 07:39 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

I could not find the "attached VI". Please attach it again. Also, if this is part of a LabVIEW Project, and the VI uses sub-VIs from the Project, it would be even better if you (a) clicked the folder containing the Project file and the rest of the Project "files", right-clicked "Send to:" and specified Compressed (zipped) Folder, and attached the .zip file of the entire Project.

Bob Schor

GerdW

Knight of NI

12-20-2022 08:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Hi Anshuman,

@Anshuman18 wrote:

We are continuously acquiring mass of tank using a weighing balance in LabView and trying to compute the derivative. For this purpose…

I would use a shift register to store the previous mass sample.

Then you can calculate the difference between current and previous mass.

Now all you need to do is to divide by the time between those two samples!

Why do you need a SavitzkyGolayFilter here?

Henrik_Volkers

Trusted Enthusiast

12-20-2022 09:45 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

The Savitzky Golay filter will need an additional scaling if used to derivate ...

here I posted my version https://forums.ni.com/t5/LabVIEW/Derivative-problem/m-p/2545553#M770893

usefull if you have noisy signals otherwise GerdW pointed the solution and there is a derivate x vi in the math section

Greetings from Germany

Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

12-21-2022 03:16 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Plz check now.

GerdW

Knight of NI

12-21-2022 04:29 AM - edited 12-21-2022 04:41 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Hi anshuman,

can you please provide a much smaller example which is reduced to just show your problem?

Right now the block diagram is HUGE and full of Rube-Goldberg (like FOR loops set to iterate just once)! It's hard to even find the part of code you seem to have problems with…

You also forgot to explain why you need to use the SG-Filter function here!

Why is there a 1000ms wait function when there is no loop around all the code? DON'T use RunContinuously - that is only meant for debugging!

Why do you use the BLAS-ASum function in CDB mode on a DBL array? (What's wrong with the Abs function followed by SumArray?)

Why don't you use subVIs instead of duplicating code?

See this for inspiration:

Henrik_Volkers

Trusted Enthusiast

12-21-2022 05:04 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

First:Open the serial port once at start, continously read the results in a (while) loop (producer), Timestamp the results and do a error handling/check! use a queue to feed valid results to another (while) loop (consumer) , close it when you stop the program. See examples and tutorials about producer consumer architecture.

you have no control of the time periode the scale is sending the values, you hope the dt is constant and known, but is it? (the scale has it's own clock and firmware) Did you read every value send? At the rigth time? (internal buffers in the hardware/driver)

Now you have a series of scale values and timestamps , (starting point to do error/failure handling .. and maybe start alarming)

Start calculating the massflow. The SG-filter way will give you a delay of sidepoint length measurements. is that OK?

Maybe a linear fit over the last n values (or all values within a timeslot, if timestamps are available) , how far differs the last value from the fit?

Greetings from Germany

Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'

01-15-2023 06:12 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

Hi Henrik,

I am using the SG filter coefficient VI for computing the derivative. Right now I am facing problem with respect to scaling with respect to time. I went through your approach as indicated in the link:

https://forums.ni.com/t5/LabVIEW/Derivative-problem/m-p/2545553#M770893

But the issue is that your solution is only valid for waveform, whereas the data points that I am using doesn't follow any particular trend they are just numbers collected from a machine. So please suggest me an approach that I can use for calculating derivative of random data points. I have also attached a screenshot of how I am computing the derivative from an array of data. Thanks in advance.

Bob_Schor

Knight of NI

01-15-2023 09:29 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

@Anshuman18 wrote:

But the issue is that your solution is only valid for waveform, whereas the data points that I am using doesn't follow any particular trend they are just numbers collected from a machine.

In order to (numerically) estimate a derivative of a (sampled) signal, you need to know not only the __value__ of the signal, but also the __intervals__ at which the values are obtained. If I handed you a bag of pennies and said "Heads is 1, tails is 0" and asked you to find the derivative of the pennies in the bag, you would be hard-pressed to define what that means, whereas if I opened the bag, put the pennies down in a straight line touching each other, you could define a derivative as +1 if (reading from left to right) the penny sequence is "tails, heads", -1 for the opposite arrangement, and 0 if they were the same.

So your "just numbers collected from a machine" need to have a "time of collection" associated with each one. The LabVIEW Waveform data type is one way to provide that, but an __array__ where you know the time __interval__ ("dt") between the samples, or a 2D array of "sample" and "time" could also be used (but the estimate of the derivative is much trickier in this case).

Bob Schor

altenbach

Knight of NI

01-15-2023 10:18 AM - edited 01-15-2023 10:19 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report to a Moderator

@Anshuman18 wrote:

So please suggest me an approach that I can use for calculating derivative of random data points. I have also attached a screenshot of how I am computing the derivative from an array of data. Thanks in advance.

As a first step you need to define "randomly". The methods work if the spacing is evenly, no matter what the spacing is. That's just a scaling factor. If your points are spaced unevenly, things get more complicated. Your picture shows 1D arrays which is just data vs. array index. For randomly spaced data you also need a second array that contains timing information for each data point. One possible solution might be to resample the data at fixed intervals by e.g. interpolation before filtering.

Instead of showing us a useless picture, please __attach your actual VI and actual sample data__ so we get a better idea of what you are trying to do. How noisy is the data?