Jump to content
  • 0

FIR filter on Waveforms


Alex

Question

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; 

Answers:

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;
        fir.forEach(function(v){vol+=v;});
        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.Clone(ch);
    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]);

large.FIR.png

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...