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: 

How to compare 3 values in array

Solved!
Go to solution

Hi all

This is my first post so please be tolerant:)

I need to find "bad values" in array, it will be easier to explain it using example so:

I have array like this: 0 0 0 0 0 0 0 0 5 0 0 0 0  <- so "5" is the bad value, my method is to check two of nearby values so x(i-1) = 0, x(i)=5 x(i+1)=0, and if checked value is more than 25% bigger or smaller it should be replaced by average of neighborhood.

next example: 0 1 2 3 4 9 6 7 8 <- bad value is 9, and result of my filter should be (4+6)/2 = 5

I've done it using formula node (not 20% and not average, but the point is the same) and it's working but now I want to do it without C and I had lots of problems with memory cause the size of array is 10000.

I attached vi and signal thah you can check that it's working fine

 

Thanks

Mike

0 Kudos
Message 1 of 24
(4,781 Views)

Hi,


I haven't gone through your attachement. But I think I understood what you are trying to do. Check the attached vi. This must be the solution I think.


Regards,

Nitzz

(Give Kudos to good Answers, Mark as a Solution if your problem is Solved;))

0 Kudos
Message 2 of 24
(4,759 Views)

 


@NitzZ wrote:

Check the attached vi. This must be the solution I think.


Your code will not work correctly unless there is only one bad element. You operate on the unchanged input array with every iteration so all earlier substitutions are discarded whenever a new glitch is encountered.

 

0 Kudos
Message 3 of 24
(4,746 Views)

 


MeeHow wrote:

next example: 0 1 2 3 4 9 6 7 8 <- bad value is 9, and result of my filter should be (4+6)/2 = 5


 

Shouldn't e.g. the value 4 be outside too, because the average of 3 and 9 (=5.5) is more that 25% different to 4?

 

Here is a quick draft comparing three versions (LabVIEW 8.2):

 

  1. Your formula node version
  2. the same algorithm in G
  3. Something along the lines you are proposing here.
As you can see, the new idea is not quite satisfactory. It needs more thought. Still, these drafts should give you some ideas how to do it. Modify as needed.
Also your data is similar to a square wave and has these large step functions where the value changes dramatically. These should probably be ignored. Maybe you should look at the first derivative and replace parts where a large positive slope is immediately followed by a negative slope of similar size, for example.
You should also look at absolute steps instead of percentages. If you use percentages and the value is zero, everything is outside, because even 5000% of zero is still zero, right?

 

Message 4 of 24
(4,734 Views)

 


@altenbach wrote:

 


MeeHow wrote:

next example: 0 1 2 3 4 9 6 7 8 <- bad value is 9, and result of my filter should be (4+6)/2 = 5


 

Shouldn't e.g. the value 4 be outside too, because the average of 3 and 9 (=5.5) is more that 25% different to 4?

 

Here is a quick draft comparing three versions (LabVIEW 8.2):

 

  1. Your formula node version
  2. the same algorithm in G
  3. Something along the lines you are proposing here.
As you can see, the new idea is not quite satisfactory. It needs more thought. Still, these drafts should give you some ideas how to do it. Modify as needed.
Also your data is similar to a square wave and has these large step functions where the value changes dramatically. These should probably be ignored. Maybe you should look at the first derivative and replace parts where a large positive slope is immediately followed by a negative slope of similar size, for example.
You should also look at absolute steps instead of percentages. If you use percentages and the value is zero, everything is outside, because even 5000% of zero is still zero, right?

 


 

This is what I need:)

thanks both of you! I don't know how to use Shift registers so this was my problem.

I know that it still don't work correctly, but I don't know why, there's only one element with wrong value so my algorithm should work fine...

And your last solution also sholud work.

My examples was just examples so don't care about them:)

0 Kudos
Message 5 of 24
(4,721 Views)

I've checked how it's look like in excel so for first bad value is:

 

2780 280,1460,4800   
2781 281,3480,5760   
2782 282,1460,4080   

 

 

So the average of neighborhood is 1460 and 3480 should be replaced by 1460 so should be fine, but itsn't... why? what's wrong?

0 Kudos
Message 6 of 24
(4,704 Views)
Solution
Accepted by topic author MeeHow

 


@MeeHow wrote:

... what's wrong?


 

Because the first bad value is the point 2780, because it is also off because the neighbor average is biased by the bad value at 2781.

 

You could jut blindly replace all values with the value that has the lowest absolute value among the three points we are looking at. Here's a quick draft, looks pretty good but it really depends on what you want.

 

 

 

 

 

0 Kudos
Message 7 of 24
(4,691 Views)

 


@altenbach wrote:

 


@MeeHow wrote:

... what's wrong?


 

Because the first bad value is the point 2780, because it is also off because the neighbor average is biased by the bad value at 2781.

 

You could jut blindly replace all values with the value that has the lowest absolute value among the three points we are looking at. Here's a quick draft, looks pretty good but it really depends on what you want.

 


Thanks a lot! I think it's working very well, but I'll test it with other signals!

Once again THX!

 

0 Kudos
Message 8 of 24
(4,671 Views)

One more thing - how did you made the "Data" block? this is cluster of time stamd, Y and t0 right?but how do you create it?

0 Kudos
Message 9 of 24
(4,655 Views)

You had the data saved as default in one of the graphs. All I did was right-click the terminal of the graph and "create constant". Try it. 😄

0 Kudos
Message 10 of 24
(4,636 Views)