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. 

chrome_2018-11-02_10-06-36.thumb.png.b6f27c9317a1cb3706268026be75a5d2.png

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.

chrome_2018-11-02_10-17-17.thumb.png.1f4f084eb7bf63fe645c48d206ac59c4.png

chrome_2018-11-02_10-17-56.thumb.png.d54ad1ad08ccf8227c1a921358cf64fa.png

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:

chrome_2018-11-02_10-23-56.thumb.png.a9acd1391ef3d3341d664cdf43c2be51.png

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.

//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.

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...

Archived

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

×
×
  • Create New...