コード例 #1
0
        private void CascadedLowPassFilter_Load(object sender, EventArgs e)
        {
            // Instantiate the DeMIMOI collection to store and easily manage all the filters and the trackbars
            lpf_cascade = new DeMIMOI_Collection("5th order LPF");

            // Instantiate the low pass filter
            lpf = new LowPassFilter[5];

            for (int i = 0; i < lpf.Length; i++)
            {
                // Create each filter
                lpf[i] = new LowPassFilter();

                // Set the sampling frequency according to the timer interval
                lpf[i].SamplingFrequency = 1000 / timer1.Interval;
                // Set the cutoff frequency to 1Hz
                lpf[i].CutoffFrequency = 1;

                // Add the filter to the collection
                lpf_cascade.Add(lpf[i]);
            }

            // Chain the filters by simply connecting them
            for (int i = 1; i < lpf.Length; i++)
            {
                // Connect the input of the i-th filter to the i-1-th filter output
                lpf[i].Inputs[0][0].ConnectTo(lpf[i - 1].Outputs[0][0]);
            }

            #region Create a DeMIMOI_Delegate for each trackBar control
            // Create the input (user handled) trackbar
            DeMIMOI_trackBar1 = new DeMIMOI_Delegate(null,                      // No inputs (the input is a in fact the trackbar value)
                                                     new DeMIMOI_Port(1),       // One input with one output delay (the trackbar value at instant t)
                                                     DeMIMOI_trackBar1_Update); // The delegate function to call to update the model output
            DeMIMOI_trackBar1.Name = "Trackbar1";

            // Create the output (low pass filter i-th order) trackbars
            DeMIMOI_trackBar_stage1 = new DeMIMOI_Delegate(new DeMIMOI_Port(1),             // One input (the trackbar value to apply)
                                                           null,                            // No output (the output is in fact the trackbar value)
                                                           DeMIMOI_trackBar_stage1_Update); // The delegate function to call to update the trackbar value using the model inputs
            DeMIMOI_trackBar_stage1.Name = "TrackBar Stage1";
            DeMIMOI_trackBar_stage2 = new DeMIMOI_Delegate(new DeMIMOI_Port(1), null, DeMIMOI_trackBar_stage2_Update);
            DeMIMOI_trackBar_stage2.Name = "TrackBar Stage2";
            DeMIMOI_trackBar_stage3 = new DeMIMOI_Delegate(new DeMIMOI_Port(1), null, DeMIMOI_trackBar_stage3_Update);
            DeMIMOI_trackBar_stage3.Name = "TrackBar Stage3";
            DeMIMOI_trackBar_stage4 = new DeMIMOI_Delegate(new DeMIMOI_Port(1), null, DeMIMOI_trackBar_stage4_Update);
            DeMIMOI_trackBar_stage4.Name = "TrackBar Stage4";
            DeMIMOI_trackBar_stage5 = new DeMIMOI_Delegate(new DeMIMOI_Port(1), null, DeMIMOI_trackBar_stage5_Update);
            DeMIMOI_trackBar_stage5.Name = "TrackBar Stage5";
            #endregion

            #region Connect each trackbar to each low pass filter input or output
            // Connect the input of the first LPF to the user handled trackbar
            DeMIMOI_trackBar1.Outputs[0][0].ConnectTo(lpf[0].Inputs[0][0]);

            // Connect each i-th order trackbar to the i-th order LPF output
            DeMIMOI_trackBar_stage1.Inputs[0][0].ConnectTo(lpf[0].Outputs[0][0]);
            DeMIMOI_trackBar_stage2.Inputs[0][0].ConnectTo(lpf[1].Outputs[0][0]);
            DeMIMOI_trackBar_stage3.Inputs[0][0].ConnectTo(lpf[2].Outputs[0][0]);
            DeMIMOI_trackBar_stage4.Inputs[0][0].ConnectTo(lpf[3].Outputs[0][0]);
            DeMIMOI_trackBar_stage5.Inputs[0][0].ConnectTo(lpf[4].Outputs[0][0]);
            #endregion

            // Add all the trackbars models to the collection
            lpf_cascade.Add(DeMIMOI_trackBar1);
            lpf_cascade.Add(DeMIMOI_trackBar_stage1);
            lpf_cascade.Add(DeMIMOI_trackBar_stage2);
            lpf_cascade.Add(DeMIMOI_trackBar_stage3);
            lpf_cascade.Add(DeMIMOI_trackBar_stage4);
            lpf_cascade.Add(DeMIMOI_trackBar_stage5);

            // Display the graphviz code result of this models combination
            textBox1.Text = lpf_cascade.GraphVizFullCode();

            // Show the DeMIMOI objects interface
            DeMIMOI.ShowVizInterface();
            // Show the DeMIMOI Collections interface
            DeMIMOI_Collection.ShowVizInterface();

            // Enable the timer to run the filter animation
            timer1.Enabled = true;
        }
コード例 #2
0
ファイル: ChartDemo.cs プロジェクト: remyzerems/DeMIMOI
        private void ChartDemo_Load(object sender, EventArgs e)
        {
            // Initialize two math operations (sine and cosine)
            sine = new MathOperation(Math.Sin);
            cosine = new MathOperation(Math.Cos);

            // Initialize the DeMIMOI chart control
            chart = new DeMIMOI_Chart(new DeMIMOI_Port(1, 1), chart1);
            // Set the timestep unit using the timer interval so that the timestep is now seconds
            chart.TimestepUnit = (double)timer1.Interval / 1000.0;

            // Create the collection that will contain all the models
            collection = new DeMIMOI_Collection();
            // Add the models to the collection
            collection.Add(sine);
            collection.Add(cosine);
            collection.Add(chart);

            // Create the connections between the math operations and the chart
            chart.Inputs[0][0].ConnectTo(sine.Outputs[0][0]);
            chart.Inputs[1][0].ConnectTo(cosine.Outputs[0][0]);

            // Generate the graphviz code if we want to give a look of the system architecture
            textBox1.Text = collection.GraphVizFullCode();

            // Show the DeMIMOI Collections interface
            DeMIMOI_Collection.ShowVizInterface();
        }