Jump to content

Create a signal that is the greater of two signals

Guest Jon Peterson

Recommended Posts

Guest Jon Peterson

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. 

Link to comment
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.

// max:

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.

Link to comment
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.


Link to comment
Share on other sites

  • 3 months later...


This topic is now archived and is closed to further replies.

  • Create New...