• 0

FIR filter on Waveforms



Question from the customer: 

Can you add a math channel which depends on more than one sample of the input channel. For example, applying a window function to calculate the average of the last 10 samples, FIR filtering, etc. Would also be nice to see some basic support for FIR and IIR filters in the oscilloscope math channels; 


For such purpose the Scope Logging tool can be used.

The following script applies a filter to one channel data and saves it as reference channel.

function doRef(ch, ref, fir){
    var cfir = fir.length;
    {// normalize window area
        var vol = 0;
        for(var i = 0; i < cfir; i++){
            fir[i] = fir[i]/vol;
    ref.enable = true;
    // clone to have proper information (sample rate...)
    // save and restore offset value
    var voff = ref.Offset.value;
    ref.Offset.value = voff;

    // workaround to get all data not only visible one
    var sb = Scope.Time.Base.value;
    Scope.Time.Base.value = 1;
    var rg = ch.data;
    Scope.Time.Base.value = sb;

    var rgf = [];
    var crg = rg.length;
    var crg1 = crg-1;
    var cfir2 = round(cfir/2);
    for(var i = 0; i < crg; i++){
        var v = 0;
        for(var j = 0; j < cfir; j++){
            var ij = i+j-cfir2;
            if(ij<0) ij = 0;
            if(ij>=crg1) ij = crg1;
            v += rg[ij]*fir[j];
        rgf[i] = v; 
    ref.data = rgf;

//    source          store       fir window
doRef(Scope.Channel1, Scope.Ref1, [1,2,1]);

doRef(Scope.Channel1, Scope.Ref2, [1,2,4,8,4,2,1]);


Link to post
Share on other sites

3 answers to this question

Recommended Posts

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now