Detecting Jumps in Signal Data

Introduction

We have a customer who wants to detect the position of jumps in his signal data and put that information into a worksheet for further use. While it can be done in older versions of Origin, Origin 2021b makes it easy to do- it only requires one function call in a Set Column Values formula.

The function is  idx()  and it is new in Origin 2021b. It accepts a "column conditional expression" and returns a dataset (vector) of integers containing the one-based row index of all the records that meet the condition.

Here are some examples of column formulas using the function:

As you can see, the function is able to accept other functions as part of the "column condition expression".

So, now let's apply the idx() function to a few example signals to highlight how Origin 2021b can make it easy for the customer to detect jump positions .

Getting Started

When I refer to a "jump", I mean something like what is displayed in the graph to the right. At some distinct point, the data literally jumps- it makes a clear, abrupt  transition. In the case of this graph, there are four jumps and each has a jump start and jump end.

These transitions are, of course, detectable in Origin. We can use the diff() function (documentation) to compare a value in a column (e.g. 0) to the next value (e.g. 5) and then return the difference. In the case on the right, diff() would calculate many zeros, four 5's (jump starts), and four -5's (jump ends).

With that knowledge, we can leverage diff() and idx() in combination  in a Column Values formula like: idx(diff(B)>1). The formula says "Get the row indices from column B where the difference between one record and the next is greater than 1".

In all the coming examples, the worksheet arrangement is the same for all (see below). Observe not only are there X & Y columns, there is a column jump index formula result. There are two more columns- one containing the X values for the jump indices and one containing the Y values. Only the Columns Values formula will change a little. Note: On the graph, the jumps are denoted by a red droplines.

Examples

Note: All the examples below are available in the downloadable companion project file.

Jump Detection Type Column Formula Visualization
Jump Start Only

idx(diff(B)>1)

We've seen this formula before.

Jump Start and End

idx(abs(diff(B))>1)

Observe that diff() is called within abs() which calculates the absolute value of the difference. This catches the negative difference values by converting them to positive.

Jump Start and End, Positive and Negative Jumps

idx(abs(diff(B))>0.50)

Jumps are both positive and negative. Same formula as previous one except different value to compare.

 

Exact Jump Among Many Jumps

idx(abs(diff(B))==5)

Uses exact matching of value (==) to extract the start and end for only one jump among many.

Bonus Example

There is another variation on this. What if you simply want the last jump in a series? Again we'll use idx(diff(B)>1) but with a small modification. To get the last item returned by the code, change it to this: idx(diff(B)>1)[0]. In this case, [0] mean the last value in a dataset. So that code says "Get the last row index from column B where the difference between one record and the next is greater than 1".

Such code can be used in a cell formula as illustrated below.

Conclusion

Thanks for taking the time to read this post. I hope it provided valuable information.

 

About Chris Drozdowski

Chris Drozdowski is a Product Support Engineer at OriginLab. He loves to talk to customers and educate them. He particularly relishes diagnosing and solving difficult, edge-case issues. As well, he contributes code to help solve problems or enhance user experience. In his down time at work, he likes to research and write about esoteric product features. Outside of work, he enjoys spending time with his family, having fun with C++, working on his aquarium, and exploring craft beers.

View all posts by Chris Drozdowski →

Leave a Reply

Your email address will not be published. Required fields are marked *