# Create a signal that is the greater of two signals

## Recommended Posts

This question comes up fairly often, so I thought best to put one solution in the forum. Please feel free to suggest other approaches.

Say you have two temperature signals and you want a third signal that shows always uses the larger value of the two. The logical thought is an if statement, e.g., in pseudo-code:

If temperatureA > tempertureB then temperatureA else temperatureB

So the question often hits Seeq support, as "How do you do an IF statement in Seeq".  Seeq, at this time, does not have IF statements, but we have some techniques to achieve the same thing. For this particular example, we'll do some signal math, a value search, and then a splice. The if statement is effectively done by the value search. So, here's one approach to solve this problem:

Here are the two temperatures plotted, we want to create a 3rd signal that always uses the greater of the two.

The next two steps are: Subtract the two temperatures, and do a value search on the results. The value search identifies regions where the blue trace is greater than the green trace.

There's one point of caution, and that is the maximum capsule duration. That has to be long enough to capture the periods where the 2nd temperature is less than the first.

The last step is use splice to create the 3rd signal. The logic of splice is "use the green signal, except where ever there's a 'B greater than A' capsule, splice in the blue signal". There's an option on splice to blend in the transitions, I did not use that in this example. Here's the splice and the results:

Please comment here if you have any questions or have a better way of doing this.

Edited by Jon Peterson
##### Share on other sites

• Seeq Team

For reference, there are seeq.org posts for "If" statements:

##### Share on other sites

• Seeq Team

This is a good way to show the use of splice() for replacing portions of signals.

If folks are looking for actual min/max techniques, there's a KB page with a technique using zipWith()

But my favorite way is with some math tricks. You have to try it to believe it.

```//min:
(\$a+\$b-(\$a-\$b).abs())/2
// max:
(\$a+\$b+(\$a-\$b).abs())/2```

This has the downside that it can increase the sample density of the resulting signal. But it has the advantage of not needing to pick a maximum duration for the splicing.

##### Share on other sites

• Seeq Team

This will be much easier starting with R21.0.41 by using max() and min() operators for signals and scalars.

##### Share on other sites

Thanks everyone!   In my opinion, the ranking of these solutions is:

1.  Max() and Min() is the best.  Just intuitive.

2.  Math trick.  No limit to capsule duration and no need to create extra signals.

3.  Boolean signals.  No limit to capsule duration, but extra signals are needed.

4.  Capsule & value search.   The capsule duration will run out.

##### Share on other sites

• 3 months later...
• Seeq Team

The min/max functions have been added to the latest general release, R21.0.40.05

## Create an account

Register a new account