How are custom channel calculations created and edited in LabChart Lightning?

Custom calculations can have multiple inputs, outputs, and function nodes.  In the following video and knowledge article, we will discuss how to created and edit them.

Starting with the custom calculation shown below, we can add a second output by dragging an Output Node from the Function Library to the canvas. The new output can be placed anywhere you like but in general, outputs should be on the right side of the canvas area.

We now drag a second SmoothSeconds Node to the canvas and connect it to the "PL Input 1" Input Node ("PL" is short for PowerLab) and the second Output Node. We set the length to 0.1 seconds for the first SmoothSeconds Node, and 0.2 seconds for the second SmoothSeconds Node. This custom calculation now produces two outputs. The preview will show three signals - the source or input signal and two smoothed signals. Custom calculations may contain as many outputs as you need. Each Output Node produces a corresponding calculated signal.



Multiple inputs and outputs

We will now make a custom calculation with two inputs and two outputs. Using the data shown below, we add a custom calculation by left mouse clicking on one of the signals in Chart View and clicking on the add calculated signal button.

The custom calculation being created will output the difference between the two signals and the sum of the two signals. Although this may not necessarily be a calculation you would create, it does illustrate the flexibility of the LabChart Lightning Custom Calculations system.

We start with a single input and output, and add an additional input and output. The signal that is the sum of the two inputs is created by dragging an Add Function Node to the canvas with the two Input Nodes as its sources. The difference between the input signals is calculated by using a Subtract Function Node with the two inputs as its sources. The Add Function Node is connected to the top output node, and the Subtract Function Node is connected to the bottom Output Node. There will now be four signals shown in the preview. We can remove some of the clutter in the preview by left mouse clicking on the eye icon in both of the input nodes.

Left mouse clicking on the "Add Calculation" button applies the calculation. The two new output signals will now be visible in Chart View. An autoscale may be required to view the signals.


Using parameters and saving calculations for reuse.

Many times, we will want to reuse Custom Channel Calculations across different recordings in a Project. LabChart Lightning allows Custom Calculations to be saved for reuse across an entire Project. Once saved, they can be used as many times as needed quickly and easily without the need to redefine them.
Calculation parameters add an extra level of flexibility to this reuse pattern by allowing saved calculations to accept inputs via Node Input Fields.

To demonstrate these two features, we’ll start with a previous example where we created a custom calculation using two outputs with differing degrees of signal smoothing.

We start by dragging a Parameter Node to the canvas. A selected Parameter Node can be configured by left mouse clicking on the "Cog" (settings) button. A parameter can have a name, a description, a type (e.g. numeric), and a range of valid values. If you specify these, they will form part of the documentation for the Custom Calculation when it is saved.


Once the parameter has had a value specified, it can be connected to the Length inputs for both of the SmoothSeconds Nodes. Note: The internal Length (the number contained in the input field) is hidden when the Parameter Nodes are connected.


With the Parameter Node connected, both SmoothSeconds Nodes are using the same value for Length. We then drag a multiply node to the canvas between the Parameter Node and the bottom SmoothSeconds Node. The parameter value is now doubled for the bottom SmoothSeconds Node.

When the value in the Parameter Node is changed, the bottom SmoothSeconds Node always uses a double of the value.

To save this calculation for reuse, left mouse click on the "Save a Copy To Function Library..." button at the bottom right of the Custom Calculation dialog. A unique name must be given to the calculation. This is how it will be found in the Function Library and the simple Calculation drop down menu. In the example below, the calculation is named 'MultiSmooth'. While the description is optional, it is often a good idea to provide one as it will be used to form documentation for the calculation. Once the "Save To Library" button is clicked, the calculation is available to be used in all recordings in the Project.

To reuse the saved calculation, select a signal and left mouse click on the "f(x) Add Calculated Signal..." button. From the simple Calculation drop down menu, look in the Saved Calculations section for the 'MultiSmooth' calculation as shown in the image below. 

Documentation available for the saved custom calculation can be viewed by clicking on the "Information" (circle with an italicized " i " in it) button at the top of the node.

Note: The saved function can be used in other custom calculations as is being demonstrated in the image below. It can be found by typing a partial or complete name into the Function Library search field.



If you have any questions about LabChart Lightning and its use, please reach out to your local ADInstruments Technical Support Representatives.