When analyzing data, you may need to remove unwanted portions, such as artefacts or out-of-range data. The easiest way is to select the unwanted portion and either select Edit > Clear Selection or press Delete on your keyboard. However, this removes the data from all channels for the selected period and divides the block where the deletion occurred.
Suppose the undesired portion of the recording is of a different amplitude than the desired signal. In that case, as seen below, you can use Arithmetics to make portions of your recording zero or Not a Number (NaN).
The base arithmetic to achieve this is a combination of three functions:
-
Window(x, y, z)
-
Smoothsec
-
Threshold
These combine to form the arithmetic sequence:
-
Threshold(Smoothsec(Window(x,y1,z),seconds),y2)
In this example file, used to derive the images above and below, this is:
-
Threshold(Smoothsec(Window(ch1,- 1,0.11),0.001),1)
Working inside out, i.e. looking at the Window function first, this is:
-
Window(ch1, -1, 0.11)
This means any value in the Raw Data channel (Channel 1 or Ch1) between -1V and 0.11V is designated as 1V in the Window channel, and any value outside -1V and 0.11V is designated as 0V.
This is because the Window function, Window(x, y, z), returns 1V if y ≤ x < z. Otherwise, it returns 0V.
Often, the designated area to remove needs to be wider than the window function generates, which, in the example, is 0.0003 seconds (indicated by the marker (M) and cursor). To do this, we use the next function in the arithmetic combination:
-
Smoothsec (x, seconds)
This is applied for a specified time in seconds. In the example, this is 0.001 seconds:
-
Smoothsec(Window(ch1,- 1,0.11),0.001)
Smoothsec(x, seconds) performs smoothing, essentially a moving average, on the source data (Window(ch1,-1,0.11)) using a triangular window. In the example, this elongates the gap between the marker (M) and cursor by 0.001 seconds to 0.0013 seconds.
The final function, Threshold(x, y), is required to reintroduce the binary aspect of the signal. That is, the signal is either 1V or 0V, yet maintaining the elongated gap introduced earlier of 0.0013 seconds.
This is achieved because Threshold (x, y) - returns 1V if x ≥ y; otherwise, it returns 0V.
In summary, the Window(x, y, z) function defines the upper and lower limits for data to be designated 1V or 0V. Smoothsec(x, seconds) adjusts the width of the region to how much data you want to remove. Threshold(x, y) recreates the binary aspect of the signal, i.e. 1V for the desired portion or 0V for the undesired portion. The next step is multiplying the data with the source channel so that the desired portion remains as is because it is multiplied by 1, while the undesired portion becomes 0 as it is multiplied by 0:
Threshold(Smoothsec(Window(ch1 ;- 0,2;0,2);0,3);1)*Ch1
An alternative is to divide the source channel by the combined function, and this produces Not a Number (NaN) for the undesired range:
Ch1/Threshold(Smoothsec(Window(ch1 ,- 1,0.11),0.001),1)
It is also possible to manually select regions to remove rather than based on y-axis thresholds. The approach also uses the Window(x, y, z) function, yet regions of data to be set to 0 can be identified with start and end points, e.g. from 5s to 7s. The signal (x) is SampleTime, which plots the time in seconds from the beginning of the block. As the desired data becomes 0, this must be inverted, hence, the function has a negative sign at the beginning of each Window() function. All Window() functions for each unwanted region can be added and multiplied with the source channel. For example:
Ch1*(1+(
-Window(SampleTime,9.2025,9.4525)
-Window(SampleTime,15.5525,15.7275)
Since finding the time in seconds and then typing the arithmetic function into the Arithmetic Formula field is time-consuming, this file contains macros to ease the work. Below are instructions for how to use the macro.
-
Select the region you would like to set to zero.
-
Start Macro > CommentSelection - this places comments at the beginning and end of the selection and will be used by the second macro. You can move the comments to fine-tune the unwanted region. The macro works in every channel. Repeat these two steps for all other unwanted regions.
-
Click in any channel and start Macro > CreateArithmetics - this reselects the portion between the start and end comments, finds the time points and builds up the arithmetics formula. When the chosen block is finished, it writes the formula into a text file.
-
Repeat the procedure with other channels as needed.
-
Open the text file and copy and paste the formula into the arithmetic formula field. Note that this can be done in a separate channel or directly in the original data channel.
SampleTime is calculated new for each data block, but the arithmetics apply to the whole channel. Therefore, this approach has limited usefulness in channels with multiple blocks; for example, if there are zero values from 5s to 7s in block one, there will also be zero values from 5s to 7s in block two.
Under certain conditions, a more sophisticated approach is possible, for example, if you see stimulation artefacts, but setting these regions to zero or a NaN would impede your analysis. Again, the approach is to put the artefact portion to zero. The original waveform is filtered in a second calculation to remove the artefact. The result is the original waveform with the small zero-portions filled with a filtered waveform.
A detailed description of the steps can be found in this file.
For further technical assistance with this or any other issue, please contact ADInstruments Technical Support by clicking HERE.