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

I tried to use very simple wave - one period of triangle, with some bad values and there's no good solution;/

I attached this signal, have U got any idea what to do? In my opinion solution with average should work but itsn't 😞

0 Kudos
Message 11 of 24
(1,177 Views)

edit:

I don;t undertand 2 tihings:.

1. I made this signal by myself, every value is bigger or smaller by 1 than one before and one after so my idea should work...

2. Why it's working for values bigger than neighborhood but isn't working for values smaller?


check this:

result.JPG

 

 

 

what's wrong??

 

 

to mods - please join both posts

0 Kudos
Message 12 of 24
(1,170 Views)

It is part of the simple current algorithm which takes the smallest value of the three. Maybe you want to take the average of the two values that are most similar, for example. Can you guarantee that the spikes are never more than a single point wide?

 

 

 

 

0 Kudos
Message 13 of 24
(1,164 Views)

@altenbach wrote:

It is part of the simple current algorithm which takes the smallest value of the three. Maybe you want to take the average of the two values that are most similar, for example. Can you guarantee that the spikes are never more than a single point wide?

 

 

 

 


No, I can't guarantee but I just want to create simply algorithm to eliminate single spikes. I see what's wrongs - I've checked how many times the value of cause was false and it was completely different that I expected: false was about 7 times, true - 9986 should be vice versa...

0 Kudos
Message 14 of 24
(1,160 Views)

Here's is a modification that, for each set of three, retains the value that is closest to the average. Should work with your triangle wave, but I have not tried.

Message 15 of 24
(1,142 Views)

I've got bad news - when we have a signal with less points e.g. 100 instead of 10000 it's look really bad, but I tried to fix it and I wrote it formula node but there's still not enough;/ I think that I miss one condition but which and where?

I attached my vi (converted to LV8.6)

 

It's look like this: img.JPG

The values of i1 and i2 should be 3 <- 6 bad values

And I know that the problem is the point before the bad one cause it fits the conditon  if(Y[i]<Y[i-1] && Y[i]<Y[i+1]) ... how can I fix it? And how can I convert it to G language?

0 Kudos
Message 16 of 24
(1,126 Views)

MeeHow wrote:

It's look like this: The values of i1 and i2 should be 3 <- 6 bad values


I don't know what you mean by i1 and i2 and "3 <- 6", can you explain? Is this some sort of code?

Please attach the small data file that does not work using my code.

I don't understand why you use a big sequence structure, it has no purpose.

0 Kudos
Message 17 of 24
(1,118 Views)

@altenbach wrote:

MeeHow wrote:

It's look like this: The values of i1 and i2 should be 3 <- 6 bad values


I don't know what you mean by i1 and i2 and "3 <- 6", can you explain? Is this some sort of code?

Please attach the small data file that does not work using my code.

I don't understand why you use a big sequence structure, it has no purpose.


 

i1 and i2 show how many times runs filter I mean how many times samples fits specified conditions. If there's 6 bad values i1+i2 should be 6. As you can see there'e 2 major parts of conditions, one for values bigger than expected, and the second for lower values. If there's 3 values bigger i1 should be 3, i2=3 means 3 lower values.

The image shows what I'm talking about, I've taken 600 samples from file that I attached, zoom is not so big but you can see that signals are different;/ Is it possible to fix it? I mean that the only difference between signals are bad values? Your code is working great but it replace all values, and I wanted to replace only bad values... is it possible?

img1.JPG

0 Kudos
Message 18 of 24
(1,109 Views)

edit:

same result as your code u can receive when using median filter, it won't work when signals changes really fast, this is the problem

0 Kudos
Message 19 of 24
(1,105 Views)

Of course there is a solution, but it involves more math if you don't want to touch the existing data. Currently we get some smoothing which seemed beneficial to me. It is well within the noise of your data.

 

You could re-use my last code, but replace the outlier with a linear inter of the two others for positions where the outlier is in the center of the three and ignore otherwise.

You could also do a difference of the current result and only retain the new data for points where the difference is above a certain threshold.

etc. etc.

 

Try it! 😄

0 Kudos
Message 20 of 24
(1,095 Views)