# Thread: Algorithm to identify the correct weight of a piece.

1. ## Algorithm to identify the correct weight of a piece.

I am studying the best way to identify the real weight of a product that passes over a belt.
The system receives about 20 weighings, from the moment the scale is empty until the piece leaves the belt.

I need to discard the weights I receive when the product is entering or leaving the platform, and pick up only the middle weights, which are closer to each other.

2. ## Re: Algorithm to identify the correct weight of a piece.

Let me get this right.

You are saying that for each object being weighed, 20 readings are made?

You want to make the best estimate, in some statistical sense, of the object's actual weight.

Is that correct?

3. ## Re: Algorithm to identify the correct weight of a piece.

Yes, exactly.
sorry for my english.

4. ## Re: Algorithm to identify the correct weight of a piece.

Originally Posted by serjaomendes
Yes, exactly.
sorry for my english.
Your English was fine. I just wanted to make sure I understand the problem before looking hard at it.

Do you have any information about why the weight measurements below the likely actual weight, the ones at the beginning and end of the sample, are the way they are?

Is the system warming up and down causing inaccuracy or something like that?

Looking at your graph we can't really characterize the samples in the middle with the same distribution as the samples at the ends.

5. ## Re: Algorithm to identify the correct weight of a piece.

Basically I need to find out the approximate weight, but I have an acceptable margin of error (1g up or down)

I need to eliminate the weights that are distant .... out of the center of the curve in the graph.

In this case the weight is 76 grams.

6. ## Re: Algorithm to identify the correct weight of a piece.

Originally Posted by serjaomendes
Basically I need to find out the approximate weight, but I have an acceptable margin of error (1g up or down)

I need to eliminate the weights that are distant .... out of the center of the curve in the graph.

In this case the weight is 76 grams.
Ok. In the case of this problem, where you know a priori that the weight readings will climb to the approximate actual weight and then drop back to zero, I would do the following.

1) list the weights in time sequence

2) apply a slope detection filter. I'd use 2 or 3 data points per slope estimate.

3) Apply a zero slope threshold detector, i.e. discard points corresponding to the absolute value of slope greater than some threshold. This threshold will have to be varied until the standard deviation of the selected points is small enough.

4) Find the mean of the selected points as your estimated weight.

Here's some code in mathematica that does all this.

7. ## Re: Algorithm to identify the correct weight of a piece.

Thank you very much for the help, it was very helpful.
I'm installing Wolfram Trial to try to understand the code and translate it to C #

8. ## Re: Algorithm to identify the correct weight of a piece.

Originally Posted by serjaomendes
Thank you very much for the help, it was very helpful.
I'm installing Wolfram Trial to try to understand the code and translate it to C #
there is an error in the code appearing in the image.

in the statement that assigns $tt$

there is a line {k,1, Length[weightData]-2}

that should be

{k, 1, Length[weightData]-slopeDetectorWindowLength+1}