Guest Jon Peterson Posted November 2, 2018 Share Posted November 2, 2018 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 More sharing options...
Seeq Team Karen Webster Posted November 2, 2018 Seeq Team Share Posted November 2, 2018 For reference, there are seeq.org posts for "If" statements: Link to comment Share on other sites More sharing options...
Seeq Team Ben Johnson Posted November 2, 2018 Seeq Team Share Posted November 2, 2018 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 More sharing options...
Seeq Team Steffen Furholm Posted November 6, 2018 Seeq Team Share Posted November 6, 2018 This will be much easier starting with R21.0.41 by using max() and min() operators for signals and scalars. Link to comment Share on other sites More sharing options...
Adam Georgeson Posted November 6, 2018 Share Posted November 6, 2018 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 More sharing options...
Seeq Team Ben Johnson Posted February 14, 2019 Seeq Team Share Posted February 14, 2019 The min/max functions have been added to the latest general release, R21.0.40.05 Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.