In version 1.2.1 of ssci.js I added a gain and phase shift function to the ssci.smooth.filter() function.

In this post I’ll go through what a gain function is and give an example of it. According to the ABS:

Gain functions can be used to look at the effect of a linear filter at a given frequency on the amplitude of a cycle in a given series. In other words, it shows what happens to the amplitude of a given input cycle on the application of a moving average.

The function I have defined takes a single value, the period, and returns the factor being applied by the filter to that period.

Therefore if we have a filter defined as:

`var orp = ssci.smooth.filter()`

.filter(ssci.smooth.henderson(13));

orp();

Then we can use the following to get the gain function:

`var gout=[];`

for(var i=1; i<20; i=i+0.1){

gout.push([i, orp.gain(i)]);

}

For periods from 1 to 20. Charting this gives the following:

From the chart, you can tell that cycles of between 1.2 and 6 periods are effectively removed from the data. There is a gradual increase from 6 to 14 where the gain goes above 0.9.

You can also see that if you only want to look at the gain of a filter you can do this without specifying any data, accessor functions or anything else.

More information (including the formulae) is on the ABS website. Source code is on github.