Beispiel #1
0
        private void plotSin(int index, double[] parHarm)
        {
            int harmNum = gridData[index].Count;

            foreach (LineGraph sg in sinGraph)
            {
                sinPlotter.Children.Remove(sg);
            }

            foreach (List <LineGraph> a in ampGraph)
            {
                if (a != null)
                {
                    foreach (LineGraph graph in a)
                    {
                        specPlotter.Children.Remove(graph);
                    }
                }
            }

            harms[index] = new Harmonics(harmNum, parHarm);

            int [] buffer = GM.funcSin(harms, sinPlotter, sinGraph);

            analogWrite(buffer, port);

            ph  = GM.phInit(harms);
            amp = GM.ampInit(harms);

            GM.funcAmp(amp, specPlotter, ampGraph);
        }
Beispiel #2
0
        public MainWindow()
        {
            InitializeComponent();

            this.Loaded += windowLoaded;

            GM = new GraphMethods();

            br[0] = Brushes.Red;
            br[1] = Brushes.Blue;
            br[2] = Brushes.Green;

            col[0] = Colors.Red;
            col[1] = Colors.Blue;
            col[2] = Colors.Green;

            names[0] = "A";
            names[1] = "B";
            names[2] = "C";

            for (int i = 0; i < 3; i++)
            {
                harms[i] = new Harmonics(1, new double[] { i + 1, 1, i * 120 });
            }

            PortNames = SerialPort.GetPortNames();

            if (PortNames.Length > 0)
            {
                port = new SerialPort(PortNames[0], 9800, Parity.None);
                port.Open();
            }

            ph  = GM.phInit(harms);
            amp = GM.ampInit(harms);

            int[] buffer = GM.funcSin(harms, sinPlotter, sinGraph);
            GM.funcAmp(amp, specPlotter, ampGraph);

            analogWrite(buffer, port);

            tabsInit();
        }
Beispiel #3
0
        private void removeHarm(object sender, RoutedEventArgs e)
        {
            int index   = Select_Cont.SelectedIndex;
            int harmNum = gridData[index].Count;

            DataGrid grid = signals[index];

            int delInd   = grid.SelectedIndex;
            int selCount = grid.SelectedItems.Count;

            double[] parHarm = new double[3 * (harmNum - 1)];

            if (harmNum > 1 && delInd != -1)
            {
                int k = 0;

                for (int i = 0; i < harmNum; i++)
                {
                    if (i != delInd)
                    {
                        parHarm[3 * k]     = harms[index].harm[i].a;
                        parHarm[3 * k + 1] = harms[index].harm[i].f;
                        parHarm[3 * k + 2] = harms[index].harm[i].fi;

                        k++;
                    }
                }

                harmNum--;

                gridData[index].RemoveAt(delInd);

                harms[index] = new Harmonics(harmNum, parHarm);

                amp = GM.ampInit(harms);
                ph  = GM.phInit(harms);

                plotSin(index, parHarm);

                removeVector(index, delInd, selCount);
            }
        }
Beispiel #4
0
        public void Filter(Harmonics harm, double[] output, double f0)
        {
            for (int i = 0; i < output.Length; i++)
            {
                for (int j = 0; j < order - 1; j++)
                {
                    buffer[j] = buffer[j + 1];
                }

                buffer[order - 1] = harm.getSample(f0, i);

                double sum = 0;

                for (int j = 0; j < buffer.Length; j++)
                {
                    sum += buffer[j];
                }

                output[i] = sum / order;
            }
        }