LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Numeric Integration of positive and negative values in the same signal

Hello.. I need to perform an evaluation of Area Under Curve of my signal, but it contains positive and negative values. I am using the "Numeric Integration" function, but the result expressed by my VI represent: AREA OF POSITIVE VALUES - AREA OF NEGATIVE VALUES, in other words, my result represent the difference between these two areas. But I want to know the total area, the sum of positive values area and negative values area, and because both values has are "+", my final result should has "+" notation.

For example:

Area of positive values: +45.00
Area of negative values: +34.00
Total area: +79.00

How do I modify my VI to obtain the total area value?

I try to split my values in two parts:

A) only the positive and zero values
B) only the negative values

I calculated the areas of both splits and performed an sum of them, but the final result does not matches with total area (computed by another software to know the real value)

I attached an picture of my VI

Thank you

Daniel
0 Kudos
Message 1 of 8
(7,611 Views)
Daniel,

It sounds as though you want the area under the curve created by plotting the absolute value of the actual data. To implement this simply insert the absolute value primitive from the Numeric palette into the array of data before the integrator. The function is polymorphic so it will accept the array input.

Lynn
0 Kudos
Message 2 of 8
(7,584 Views)
Hello... I guess that I solved my problem.

I splitted my data into two groups:

- greater or equal than zero
- lesser than zero

Next, I calculated the area of both groups and performed a sum of the results. But now I have a new problem:

I inserted an Boolean Button to execute the Read Spreadsheet function, only when the button is pushed (mechanical action: switch until released), but the whole VI is inside a While Loop that runs continuosly, the problem is when I push the button and select an ASCII file to load (using read spredsheet), my VI calculates the are of the numbers with perfection, but after this the while loop goes to another turn, and this time the button is not pushed and the function to read spreadsheet does not run and no data feeds the circuit, resulting in a NAN result in my total area indicator.

In other words, I want to keep my while loop because I don't want to push the arrow on the top to run my VI each time that I want to load a new file, but I want to keep in the total area indicator the last value, until I push again the button to load a new ASCII file.

I attached pictures of my diagram.

Thanks

Daniel
Download All
0 Kudos
Message 3 of 8
(7,564 Views)
Use an event structure for the boolean value changed. You also did not follow Lynn's advice to insert an "absolute value". It would really simplify everything.
 
Here's how it would look in a newer version of LabVIEW (your icons look different because you have an older version. The functions are the similar).
 
 
This is just a draft and the program needs to be improved. Use a state machine with events for read file and another for value change on the sampling rate. Place the data array in a shift so you can change the sampling rate without the need to re-read the file. Modify as needed
 
Some important pointers in general:
  1. There is NO need to constantly spin the loop every nanosecond. The only time the loop needs to spin if if one of the inputs has changed.
  2. If you don't use an event structure, all UI loops need a wait to conserve CPU.
  3. Never (almost never) use "switch until released". Typically you want to use "latch when released" which makes the terminal true exactly once until the value is read and it will revert to false after that. "switch until released acts like a doorbell, so if it werent for the file dialog, you would execute the case several times in a row.
  4. You don't need to get the array size and wire N of the FOR loop if you are autoindexing. LabVIEW will spin the loop until it runs out of elements automatically.
  5. There is an atomic operation for "negate" in the numeric palette. No need to multiply with a "-1" diagram constant.
  6. There is an atomic operation for ">=0" in the comparison palette. No need to compare with a "0" diagram constant.
  7. Use a stop button on the loop termination.
  8. Everything that only needs to be done once after the file is read (e.g. you inner loop, etc. also belongs inside the case structure. Right?
  9. ...

In general, you would make things much easier for us if you would attach your actual live VI instead of dead images.



Message Edited by altenbach on 04-19-2008 12:22 PM
0 Kudos
Message 4 of 8
(7,549 Views)
Hello....

altenbach, thanks for the attention and advices....

I changed my VI based on your and Lynn's instructions.

I did not used the "negate" function because I don't want to turn positive values into negative, I want to turn negative in positive, than I used the number * -1

Now, I am using absolute values and the VI is much more simple and functional.

I don't need to change the sampling rate without re-read a file, because I just set up the frequency, load the file and get the area, it is a simple operation just to get the area value.

Attached there is my VI. Please, since that my Labview is a old version, reply me with images because I will not be able to open newer versions files.

This attached VI has a problem, after I click the boolean, the event case runs twice, asking to load a file two times, after that it stops and wait until a new push on the button, how do I fix this? I want that it runs only one time and run again only when i push boolean again.
I was not able to link the while loop to event case.

Thanks very much

Daniel



Message Edited by daniel.penteado on 04-19-2008 03:57 PM
0 Kudos
Message 5 of 8
(7,536 Views)


daniel.penteado wrote:
I did not used the "negate" function because I don't want to turn positive values into negative, I want to turn negative in positive, than I used the number * -1

Negate is exactly the same thing as multiplying with "-1". Try it! 😄


daniel.penteado wrote:
I don't need to change the sampling rate without re-read a file, because I just set up the frequency, load the file and get the area, it is a simple operation just to get the area value.

It is not good programming practice to rely that the user operates controls in a certain order.


daniel.penteado wrote:
This attached VI has a problem, after I click the boolean, the event case runs twice, asking to load a file two times, after that it stops and wait until a new push on the button, how do I fix this? I want that it runs only one time and run again only when i push boolean again.
I was not able to link the while loop to event case.

Your boolean is set to "switch until released" mechanical action. This means you get a value change when you press it and another value change when you release it, for a total of two events. Use a button (e.g. the OK button and then change the text on it to e.g. "load file") and make sure the mechanical action is set to "latch when released". Now it will trigger the event only once. Makes sense?
 
Good luck!
 
(btw, you are using an unsupported and expired beta version (7.1b7) that might have undocumented bugs. You should really use a regular version).


Message Edited by altenbach on 04-19-2008 03:26 PM
0 Kudos
Message 6 of 8
(7,523 Views)
Hello Altenbach... how are you?

Thank you very much for attention... I am an begginer user in Labview and have another problem... my english is not so good... sorry for the gramatical costruction....

I tested the negate function, you are right!

"It is not good programming practice to rely that the user operates controls in a certain order". You are right again, I will change this.

"
make sure the mechanical action is set to "latch when released". Now it will trigger the event only once. Makes sense?". Ok..... I changed this again.... for the third time, you are right!! Smiley Happy

"(btw, you are using an unsupported and expired beta version (7.1b7) that might have undocumented bugs. You should really use a regular version)."  what btw means?

Thanks for attention and patience

Daniel
 
0 Kudos
Message 7 of 8
(7,508 Views)
btw: "By the way..." 🙂
0 Kudos
Message 8 of 8
(7,495 Views)