# Best way to process this signal

I am novice in signal processing, and i have to aplogise for my english level. The problem is the next:

I work for foundries, in this sector the cast parts are manufactured pouring liquid metal in sand moulds. These moulds are formed by 2 sand semi-moulds (first figure), and these semi-moulds are mafuctured in the DISA machine.

The problem is that sometimes the DISA machine does not work properly and the alignment between semi-mould is not correct. The result of the problem is thar the cast parts lose the symmetry properties and are rejected.

To solve the problem i have been capturing data through a laser device. The laser is placed in a fixed place and is measuring the distance until the semi moulds in a production lien. The semi moulds are manufactured with a cube footprint in the bond of itselves. Like in the image (in the manufacturing chain the gap between semi mould seen in the figure does not exist).

So, the laser measures the front face of the semimould and then the footprint of the cube obtaining the next image:

The upstairs line represent the measurement in the front face of the moulds and the downwords peaks represent the measurements in the cubes footprints.

If we make a zoom in the peaks we see the next.

This image represent the footprint of the cube and the bond of semimoulds (global minimum). The problem is the next, through the procesing of the laser device signal i must try if the semimoulds are correctly aligned or not with a tolerance value uf 0.2mm over this value, the semi moulds are misaligned.

What i am looking for is for methods to process the last images signal and compute the gap between semimoulds. I need algorithms to minimize the noise of the signal in vias of build a model which approximates my signal to the real morphology of the moulds and also need a robust method to calculate the gap between semi moulds with the minimum uncertainly as possible.

Firstly A_A, thanks for your answear. I think in some way, i have not correctly explain the problem.

As you have say above. This is correct.

  | H |
| H |
| H |
=>|   |
|   |


But there is not distance between semimoulds. In the next image you can see a proptotype of the real system.

But the solution what we are looking for is to measure a gap in the cube footprint created between semimoulds. Such footprint represents the join of the semi moulds. So that, a mould is formed as (left image one semimould, right image two semimoulds forming a mould):

When the laser is measuring inside the cube footprint, we find the "valleys" in above graphics. But the gap we are trying to detect is generated by the shift of one semimould respect to the other. The threshold k is OK it is 0.2mm. The speed of the conveyor is not constant becouse it depends on the pouring machine and the wide of the mould (but we could know it). It is also important that sometimes the conveyor is stopped waiting to the pouring machine. The sample rate is 0.0025 seconds but que device can work with different sampler rates (bigger than 0.0025).

The main problem i have is to determine the gap of 0.2mm in the join of the two semimoulds, which depicts that a semimould is moved respect to the other one. [![enter image description here][6]][6]

And this one represents a mould which is NOK. So througth the laser we are tying to detect if the gap between semimoulds is bigger than 0.2mm (green slot in the image).

The last image of my first post is the laser measurement inside the cube footprint of the moulds. So, i reformulate the question. What is the best way to process this signal to detect if the gap is bigger than 0.2mm.

I hope it will be more explainatory.

[EDITED VERSION]

I list the main problem i thin what i will have once i have separate the signal into wave fronts.

First, i see 3 problems. Once separated into the sets which contains the values which belong to the cube footprints in the sand moulds (the cubes in the join of semimoulds).

• How i can remove the signal noise produced by the vibrations of the DISA machine (the variability seen in the third image). I would like to get preprocess the signal in order to get the most similar signal to the real one.

• Through which algorthm can i calculate the gap between semimoulds?

• How i can infer the angle between semimoulds?

Two more images to explain the "gap" what i want to calculate.

This image depicts the conveyor (i have not draw the cube footprints in the image to make it simpler). We assume that the conveyor is moving the moulds to the right.

Representation of the real production line.

Thanks!

• Please do not leave extra information as answers. – Peter K. Nov 17 '17 at 12:25
• To see if I understand this correctly. My answer as it is now is addressing this distance --- <-d-> ---. (Where --- is the semi-mould). But, what you really want to check is "alignment". So essentially something like this: --- --- --- --- (OK) --- ___ --- --- (Alignment of the second semi-mould is off). And therefore, what you really want is the two fronts of the "pulse" in your image-3 (above) to be more or less on the same level rather than one above or below the other. If this is correct, I will amend my response on how to do this. – A_A Nov 17 '17 at 12:52
• @PeterK. Wow, that was fast... – A_A Nov 17 '17 at 12:53
• @A_A You caught me as I was drinking my first cup of coffee for the day. :-) – Peter K. Nov 17 '17 at 13:22
• Is correct. The important thing is to detect the pulse and be able to calculate if the alignment is more or less than de threshold. Thanks. – Billy Knife Nov 17 '17 at 13:41

If I understood correctly, you have a laser rangefinder mounted vertically to the production line. This rangefinder is effectively measuring the profile of the moulds as they pass in front of it. So, in ascii art, something like this:

  | H |
| H |
| H |
=>|   |
|   |


Where => is the laser. So, what we see in your second figure is the profile of the moulds on the production line.

Now, if this geometry is correct (?), the actual problem we are trying to solve here is that you don't want "valleys" that are wider than some threshold $k$.

One thing that you are going to have to confirm is this $k$ because 0.2 millimetres is a very tight alignment error. Perhaps it is something like 2mm? Or even 20mm? (20mm is 2cm).

The reason you need to fix this is because, $k$ along with the velocity of the production line $u$ (in units of mm/s), will determine your Sampling Frequency and ultimately, your accuracy.

At the moment, we don't know the frequency by which you are driving your laser rangefinder and therefore, we cannot really tell what is the distance between the distance samples, both in time but more importantly, in space. That is, physical distance. This is what you are after.

So, let's assume that your conveyor belt is moving at a speed of $u=30 mm/s$. That's about 1.8 metres per minute or about 6 feet per minute. I am assuming that the moulds are heavy so the belt has to move slowly. To be able to measure something with the least accuracy of $k$ mm, you need to make sure that the laser rangefinder is taking measurements at least once every $\frac{\frac{k}{u}}{2}$ seconds. This is your sampling period and because $Ts = \frac{1}{Fs}$, your sampling frequency should be at least $Fs = \frac{1}{\frac{\frac{k}{u}}{2}} = \frac{1}{\frac{\frac{0.2 mm}{30mm/s}}{2}} = \frac{1}{\approx 0.0033} \approx 300Hz$.

Sampling at 300Hz, a mould that is 30cm in length moving on a belt at 30mm/s speed, will be represented with a "pulse" that is 3000 samples long.

In reality, you have to drive the rangefinder at an even higher sampling frequency than that. Say for instance, a "safety margin" of $2 \times$ or $3 \times$ the nominal speed. This is because, the moulds are not going to be sitting on the belt "properly". That is, absolutely vertically to the rangefinder. If the moulds are sitting slightly slanted, then they appear "shorter" from the point of view of the rangefinder and this dilutes the desired resolution.

From this point onwards, you can go about various different ways to measure the gap between the moulds, from the easiest to the more complex.

Perhaps the easiest way to do this is with a routine that is almost exactly the same as the routine by which you would measure the duration of pulses using a microcontroller.

Given your distance measurement signal $x[n]$, threshold it at $x[n]<d_m$. This gives you a pulse sequence that goes high at the gap between the moulds. $d_m$ is a distance threshold beyond which you determine that your range finder is now sampling a gap and not a mould. You are going to have to determine this experimentally.

Once the pulse goes high, start a counter $v$. This now counts how "long" is the "gap pulse". Once the pulse goes low, that is when we are now just starting to sample the face of the next mould. Stop the counter.

The length of the gap is $v \times \frac{k}{2 \times safetyMargin}$ mm.

Where $safetyMargin$ is that multiplier you might want to raise your sampling frequency by from above.

The more complex way to do this is to fit a model on your gap pulse and then use that to estimate something like full width at half maximum but maybe this is a bit of an overkill for your application.

A final remark about that $safetyMargin$ factor. This was put there because your moulds might sit slightly slanted to the laser rangefinder. But that is not the only factor that will affect your accuracy. The other factor is the speed of the conveyor belt.

The speed of the conveyor belt is not stable for a myriad of reasons from power frequency changes to load changes to slippage to mechanical wear. If your conveyor belt's speed is not remaining stable, then each mould is not going to be 3000 samples long, but rather, this number will fluctuate. That is, some moulds might appear shorter (the belt speeding up) or longer (the belt slowing down).

The simplest way to account for this is to boost the sampling frequency and work with a "soft" threshold. That is, I expect each mould to be 3000 samples long, "give or take" 10 samples. Same goes for your gap estimate of course and in this case, because the gap is smaller, this "give or take" (and the speed of the belt) becomes even more significant.

The more complex way (and much more accurate) to account for this is to adjust your sampling frequency to the speed of the conveyor belt. This basically means, whatever the speed of the belt, I want it to sample 100 points per "belt movement" unit.

Hope this helps.

EDIT:

Further clarification specified that this is really a problem of detecting alignment and not the width of the gap per se. In a way, this is an easier problem to handle.

The above considerations regarding $Fs$ still hold. Through those calculations it is possible to relate the laser measurements to their physical units.

Now, inevitably, we have to split this into two problems:

1. Detect the semi-mould.
2. Confirm semi-mould alignment.

Detecting the semi-mould:

This remains a thresholding function as above. Therefore, if $x[n]$ is the distance time series as measured by the laser rangefinder, then a semi-mould starts when $x[n] < d_m$ from the point of view of the rangefinder.

If $x[n] > d_m$ then we are looking at the gap between the semi-moulds or some feature of the semi-moulds.

Let's now assume that $z[n]$ contains all those $x[n]$ measurements for which $x[n] < d_m$

Furthermore, let's assume that $z_s[n], z_{s+1}[n]$ are two sequential sets of measurements. In other words, the threshold has triggered twice, for two sequential semi-moulds and $z_s, z_{s+1}$ contain the "profile" measurements of each semi-mould as it passes in front of the lase on the belt.

Confirm Semi-mould alignment:

Your main problem is that you want to keep the averages of $z_s, z_{s+1}$ within specific limits.

In other words, if you obtain the difference of the average value of $z_s$ and the average value of $z_{s+1}$ and test if it is smaller than 0.2. Assuming of course that the laser is already giving you measurements in mm.

It is far better to work with the $x[n]$ measurements because you can be more flexible with various configurations later on. For example, maybe the semi-mould is not sitting exactly in parallel. You can do a best line fit on the individual $z_s$'s and infer the angle at which the semi-mould is sitting on the belt.

Hope this helps.

EDIT 2:

In light of more data provided:

1. I appreciate the data file, but there was no other information provided with it. What is the first column? Is it simply an indication of whether the measured object was within the range of the rangefinder? That is, does the first column tell you if the measurement of the second column is valid?

2. The following is a plot of the signal you posted. Can you please confirm that my marking is correct? Are these gaps the faces of the semi moulds and if yes, what is the reason for different "widths"?

1. The laser is mounted on a bracket on the same machine. The bracket vibrates. From what I can see in this next image, it vibrates so much that it is impossible to achieve the required accuracy of 0.2mm. If this number is accurate (0.2 mm), it is one fifth of a milimeter and it is about the same thickness that a well sharpened pencil draws.

• While you can take these oscillations away by filtering, filtering on its own will not do miracles. I would suggest that you isolate the mounting of the laser completely from the machine. Use a tripod that rests on the floor and is not attached to the machine. This will still be getting some vibration from nearby equipment but it will be far easier to deal with THAT level of vibration rather than what we see in this case. Here is an example, here is a cheaper one. They probably do similar things where you are.

1. Can you please confirm what I have marked in the following image? Red is the profile of the mould and green is what I think is the angle at which the mould is sitting on the belt. Are these accurate? What about the intervals that are much shorter? How do you judge angle there?

So, as you can see, your two steps from above are now becoming much more challenging.

Detect the presence of the face of a semi-mould:

This is still the job of a threshold but you now have to impose thresholds both in distance ($d_m$ from above) and time ($n$). Here is an example, I am using Octave:

1. T = medfilt1(Q(:,2),50)>1350);. Q is your signal (the one I downloaded from google drive), T is your threshold, medfilt1 applies a very simple median filter to get rid some of the noise. I determined 50 (the length of the filter) and 1350 (the distance threshold) experimentally. T looks like a pulse, 0: No semi mould, 1: yes there is a semi mould. If we now multiply our T with the signal, we get this waveform:

1. Now we need to reject pulses that are shorter than some level and longer than some other level. For instance:

pulseStartEnd = find(abs(diff(T))); pulseLength = diff(pulseStartEnd); validPulses = find(pulseLength>4000);

In other words, the absolute of the first derivative of the Threshold gives you one spike for each rising and falling front of the pulse. Find the locations of those spikes and call them pulseStartEnd. Now differentiate the sequence of the locations of the spikes to find their length, call that pulseLength. Finally, threshold the pulse length to find those segments you want to focus on, call that validPulses. The combination of these three variables tells you WHERE in your signal you have to look in order to find semi mould faces. In other words, these are your $z_s$ from previously. What you have to do now is determine how far away from the laser ON AVERAGE is the face of a semi-mould.

Confirm alignment:

This is more or less simple now. Let's check how far away on average the first semi mould sits from the laser. Given the three variables above, our first semi-mould sits between samples 15966 and 20077 (roughly). Let's plot that:

plot(Q(pulseStartEnd(validPulses(1)):pulseStartEnd(validPulses(1))+pulseLength(validPulses(1)),2))

The plot command might look extremely complicated but it is really simple. All I do is plot my $z_1$ (validPulses(1)). This starts at pulseStartEnd(validPulses(1)) and ends at pulseStartEnd(validPulses(1))+pulseLength(validPulses(1)). I hope it is self-exaplanatory why.

Get the average of this:

averageSemiMouldDistance1 = mean(Q(pulseStartEnd(validPulses(1)):pulseStartEnd(validPulses(1))+pulseLength(validPulses(1)),2))

This gives me 1481.2. Let's get the average of the next semimould.

averageSemiMouldDistance2 = mean(Q(pulseStartEnd(validPulses(2)):pulseStartEnd(validPulses(2))+pulseLength(validPulses(2)),2))

This gives me 1479.3.

If you now subtract these two numbers, you get the gap that you are after.

Do it in realtime and you have what you are looking for. I hope this helps.

!NOTES!:

1. Please note, I write roughly throughout because all that diff does is first order differences which is really $x[n+1]-x[n]$. This means that wherever you use diff, your estimates are off by 1 sample. Use it twice, they are off by 2 samples and so on. While I was working on this, I did not take these 1,2 samples into account.

2. There are more ways than one to obtain the average distance. Here, I used the arithmetic mean. Because of your noisy signal, you might want to replace mean for median with median. Yet another thing to do which would make sense given your problem, would be to obtain the modal mean.

3. Once you isolate your $z_s$'s, you can do whatever you like with them. If you want to get an indication of the slope at which the semi-mould is sitting on the conveyor belt, fit a line through those values and look at the slope factor. For example:

semiMouldMeasurements = Q(pulseStartEnd(validPulses(1)):pulseStartEnd(validPulses(1))+pulseLength(validPulses(1)),2);

p = polyfit((1:length(semiMouldMeasurements))',semiMouldMeasurements,1)

This will fit a line to your points and within reasonable limits, if you examine the slope factor of the line (the first value in p), this will give you the angle at which the mould is sitting on the belt.

Hope this helps.

• Thanks again. I think that i have undestood ,ore or less what you said. I tell you some doubts about your explanation. First, i have understood that you asume x[n] as the vector with any measurements of the laser. Throught dm i assume you are trying to detecting if you are measureng the semimould faces or the cubes footprints (the footprint in the cube to determine the alignment). I do not understand correctly what do yo represent throught zs and zs+1. Do you refer to the cube footprint two parts (image 1)? or do you refer to 2 different footprints in 2 different moulds? – Billy Knife Nov 20 '17 at 8:16
• What do you refer with profile measurments? I want you ask you too for the methodology (filtering...) to approximate the laser measurement to the real form of the mould (and minimize the uncertainly). Finally, ask about the algorithm to calculate the gap. If you give me an email contact adress i can send you the dataset. – Billy Knife Nov 20 '17 at 8:19
• 1) Two different footprints. Two sets of "high" values, or values between the asterisks in your original second image 2) There is no filtering, you could add a median filter to smooth the fronts a little but that would depend very much on the data. Pastebin is the fastest option I think. You can do a private pastebin and post the link here. – A_A Nov 20 '17 at 9:31
• 1) ok, so zi may be the set of zs to zs+n values, where each z contains the values which belongs to the cube footprints (3 image in my original post). 2) Why do you say that it depends on the data?. I have try to do a pastebin but it says that the data is longer than the maximum allowed data size. Two new questions. Once i have smoothed the z values through a median filter, how i can calculate the gap between the semimoulds to infer the value? – Billy Knife Nov 20 '17 at 11:04
• i think the signal noise is a problem as you can see in the 3 image, because the place in where i have take the measures is a foundry and near to the laser are vibrations produced by the DISA. In the other hand, how can i infer the angle value of the misalignment of the semimoulds?. As you can see i have a lot of doubts, please, apologize me but i am really novice in the area and my english is not very good. – Billy Knife Nov 20 '17 at 11:06