chr
2026-04-05 fe750b791d5b517cc4e9bc8e99a9a75139a0cfba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//Copyright 2012-2019 Keysight Technologies
//
//Licensed under the Apache License, Version 2.0 (the "License");
//you may not use this file except in compliance with the License.
//You may obtain a copy of the License at
//
//http://www.apache.org/licenses/LICENSE-2.0
//
//Unless required by applicable law or agreed to in writing, software
//distributed under the License is distributed on an "AS IS" BASIS,
//WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//See the License for the specific language governing permissions and
//limitations under the License.
using System.Collections.Generic;
using System.Linq;
using OpenTap;
 
namespace OpenTap.Plugins.ExamplePlugin
{
    // As with Test Steps, the Display attribute can also be used with Instruments.
    [Display(Groups: new[] { "Examples", "Example Plugin" }, Name: "Low Pass Filter", Description: "A simulated low pass filter.")]
    // All TAP DUTs inherit from the Dut base class.
    public class LowPassFilterDut : Dut
    {
        // LowPassFilterDut inherits two properties (Comment and Id) from DUT class.
        // Additional DUT properties can be added here.
 
        // Internal properties are not shown in the GUI.
        internal int WindowSize { get; set; }
 
        public LowPassFilterDut()
        {
            // Name defines the name that new instances of this class will use.  
            // This is how the DUT will appear in the Resource Bar and in the Step Settings of Test Steps.
            // More than one instance is made unique by automatically appending an integer suffix.
            Name = "Filter";
            // Default settings can be configured in the constructor.
            ID = "KS000000";
        }
 
        // Open procedure for the DUT.
        public override void Open()
        {
            // Add code needed for opening the resource here.
            // This will be called at the beginning of a TestPlan.
            base.Open();
 
            // DUTs also have access to a Log object.
            Log.Info(string.Format("The DUT ID is {0}", ID));
        }
 
        // Close procedure for the DUT.
        public override void Close()
        {
            // Add code needed for closing the resource here.
            // This will be called at the end of a TestPlan execution.
            base.Close();
        }
 
        // Since this is a simulation of a low pass filter (LPF) the processing is inside the DUT.
        // The LPF is implemented by a moving average.
        internal double[] CalcMovingAverage(double[] inputData)
        {
            int size = inputData.Length;
            List<double> windowValues = new List<double>();
 
            double[] movingAverage = new double[size];
            for (int i = 0; i < size; i++)
            {
                // Add the newest one.
                windowValues.Add(inputData[i]);
 
                if (i < WindowSize)
                {
                    movingAverage[i] = 0;
                }
                else
                {
                    movingAverage[i] = windowValues.Average();
                    // Take off the oldest.
                    windowValues.RemoveAt(0);
                }
            }
            return movingAverage;
        }
    }
}