public static int[] Mode(int[] source)
        {
            Inputs.checkInputs(source);
            int[] sortedArray = ArrayManipulation.uniqueSortedArray(source);
            int[] countArray  = new int[sortedArray.Length];

            for (int x = 0; x < countArray.Length; x++)
            {
                countArray[x] = 1;
            }

            for (int i = 1; i < sortedArray.Length; i++)
            {
                if (sortedArray[i] == sortedArray[i - 1])
                {
                    countArray[i] = countArray[i - 1] + 1;
                }
            }

            int max = Maximum(countArray);


            List <int> modeList = new List <int>();

            for (int u = 0; u < countArray.Length; u++)
            {
                if (countArray[u] == max)
                {
                    modeList.Add(sortedArray[u]);
                }
            }

            return(modeList.ToArray());
        }
Beispiel #2
0
        public override void Fetch(ref double[,] fetchData)
        {
            double[,] data = new double[_samplesToRead, simChList.Count];
            List <double[]> Data = new List <double[]>();

            for (int i = 0; i < simChList.Count; i++)
            {
                double[] simData = new double[_samplesToRead];
                double[] noise   = new double[_samplesToRead];

                Generation.UniformWhiteNoise(ref noise, 0.03);

                if (i == 0)
                {
                    Generation.SquareWave(ref simData, 1, 50, 10);
                }
                else
                {
                    Generation.SineWave(ref simData, 1, 0, 10);
                }
                ArrayCalculation.Add(simData, noise, ref simData);
                Data.Add(simData);
            }

            for (int i = 0; i < Data.Count; i++)
            {
                ArrayManipulation.ReplaceArraySubset(Data.ElementAt(i), ref data, i, ArrayManipulation.IndexType.column);
            }


            fetchData = data;
        }
Beispiel #3
0
        /// <summary>
        /// 每隔10ms刷新用户界面
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled   = false;
            samplesToPreview = int.Parse(textBox_previewSamples.Text);
            double length     = 0;
            bool   recordDone = false;

            //步骤5:获取流盘状态,包括已流盘长度和流盘是否结束标志位
            dstask.GetRecordStatus(out length, out recordDone);
            if (recordDone)
            {
                //流盘已结束
                buttonStop_Click(null, null);
                progressBar1.Value = progressBar1.Maximum;
            }
            else
            {
                //步骤6:流盘仍在进行中,预览最新流盘数据并显示
                dstask.ReadLatestData(ref priewData);
                ArrayManipulation.Transpose(priewData, ref transposedData);
                easyChart_signal.Plot(transposedData);

                for (int i = 0; i < channelNumbers.Count; i++)
                {
                    ArrayManipulation.GetArraySubset(transposedData, i, ref singleChannelPriewData, ArrayManipulation.IndexType.row);
                    Spectrum.PowerSpectrum(singleChannelPriewData, double.Parse(textBox_sampleRate.Text), ref singleChannelSpectrumData, out spectrumInterval[i], SpectrumUnits.V2);
                    ArrayManipulation.ReplaceArraySubset(singleChannelSpectrumData, ref previewSpectrumBufferTransposed, i, ArrayManipulation.IndexType.row);
                }
                easyChart_spectrum.Plot(previewSpectrumBufferTransposed, 0, spectrumInterval[0]);
                progressBar1.Value = (int)(length / double.Parse(textBox_recordLength.Text) * progressBar1.Maximum);

                timer1.Enabled = true;
            }
        }
Beispiel #4
0
        public void SpeedTest()
        {
            Random rd = new Random(1234);

            Stopwatch sw = new Stopwatch();

            for (uint src_length = 1; src_length <= 32; src_length++)
            {
                uint dst_length = src_length * 1000000;

                AvxArray <float> vx = new float[src_length];
                AvxArray <float> vy = new float[dst_length];

                ArrayManipulation.Broadcast(src_length, vx, dst_length, vy, 1);

                sw.Restart();

                ArrayManipulation.Broadcast(src_length, vx, dst_length, vy, 1);
                ArrayManipulation.Broadcast(src_length, vx, dst_length, vy, 1);
                ArrayManipulation.Broadcast(src_length, vx, dst_length, vy, 1);
                ArrayManipulation.Broadcast(src_length, vx, dst_length, vy, 1);

                sw.Stop();

                Console.WriteLine($"{dst_length} : {sw.ElapsedMilliseconds / 4} msec");
            }
        }
Beispiel #5
0
        public void SOM_6_columns_iris_0()
        {
            InitData_dataset_iris();

            //Split last column away from _trainingData
            double[][] newTrainingData     = ArrayManipulation.RemoveLastColumn2D(_trainingData);
            string []  values              = Conversion.ConvertToStringArray(ArrayManipulation.GetLastColAs1DArray(_trainingData));
            string[]   newAttributeHeaders = ArrayManipulation.RemoveLastColumn1D(_attributeHeaders);

            BuildSelfOrganizingMap build = new BuildSelfOrganizingMap();

            build.SetParameters(4, 4);//, .1, 100, 3);
            ModelSelfOrganizingMap model =
                (ModelSelfOrganizingMap)build.BuildModel(newTrainingData, newAttributeHeaders);

            values = Conversion.ReplaceWithString1D(values, "0", "setosa");
            values = Conversion.ReplaceWithString1D(values, "1", "versicolor");
            values = Conversion.ReplaceWithString1D(values, "2", "virginica");

            string somMap = model.GetPrintedSOMMapWithNameIds(newTrainingData,
                                                              values);

            //string valueCompare = "versicolor versicolor setosa setosa \r\n" +
            //                     "virginica versicolor versicolor setosa \r\n" +
            //                     "virginica virginica virginica virginica \r\n" +
            //                     "virginica virginica virginica virginica";

            //Using Random init weights is leading to different structure
            //However the following line should always be there
            Assert.IsTrue(somMap.Contains("virginica virginica virginica virginica"));
        }
Beispiel #6
0
 public void ArrayManipulation_1D_row()
 {
     InitData_dataset_3_rows_non_symmetric();
     double[] newArray = ArrayManipulation.GetRowAs1DArray(_trainingData, 2);
     Assert.AreEqual(newArray.Length, 3);
     Assert.AreEqual(newArray[0], 3);
     Assert.AreEqual(newArray[1], 6);
     Assert.AreEqual(newArray[2], 9);
 }
Beispiel #7
0
        public void ArrayManipulation_1D_string_last_col()
        {
            string[] array    = new string[] { "a", "b", "c", "d" };
            string[] newArray = ArrayManipulation.RemoveLastColumn1D(array);
            Assert.AreEqual(newArray.Length, 3);

            Assert.AreEqual(newArray[0], "a");
            Assert.AreEqual(newArray[1], "b");
            Assert.AreEqual(newArray[2], "c");
        }
Beispiel #8
0
        public void ArrayManipulation_1D_double_0_col()
        {
            double[] array    = new double[] { 2, 3, 4, 5 };
            double[] newArray = ArrayManipulation.RemoveSpecificColumn1D(array, 0);
            Assert.AreEqual(newArray.Length, 3);

            Assert.AreEqual(newArray[0], 3);
            Assert.AreEqual(newArray[1], 4);
            Assert.AreEqual(newArray[2], 5);
        }
Beispiel #9
0
        public void ArrayManipulation_1D_double_last_col()
        {
            double[] array    = new double[] { 2, 3, 4, 5 };
            double[] newArray = ArrayManipulation.RemoveLastColumn1D(array);
            Assert.AreEqual(newArray.Length, 3);

            Assert.AreEqual(newArray[0], 2);
            Assert.AreEqual(newArray[1], 3);
            Assert.AreEqual(newArray[2], 4);
        }
Beispiel #10
0
        public void Start()
        {
            if (null == tableLayoutPanel_waveConfig.Controls[0])
            {
                return;
            }
            double    sampleRate    = (double)numericUpDown_sampleRate.Value;
            Generator waveGenerator = tableLayoutPanel_waveConfig.Controls[0] as Generator;

            AITask.AITask input  = _globalInfo.AITask;
            AOTask.AOTask output = _globalInfo.AOTask;
            output.SetUpdateRate(sampleRate);
            input.SetSampleRate(sampleRate);
            double channelRange = waveGenerator.GetAmplitude();

            output.AddChannel(comboBox_aoChannel.SelectedIndex, -1 * channelRange, channelRange);
            input.AddChannel(comboBox_refChannel.SelectedIndex, -1 * channelRange, channelRange);
            input.AddChannel(comboBox_testChannel.SelectedIndex, -1 * channelRange, channelRange);

            double[] outData = waveGenerator.Generate();

            output.SetSamplesToUpdate(outData.Length);
            double outTime = outData.Length / output.GetUpdateRate();

            input.SetSamplesToAcquire((int)(outTime * input.GetSampleRate() * GlobalInfo.ExtraReadTime));
            output.WriteData(outData, -1);

            input.Start();
            output.Start();

            double[,] readWaveform = new double[input.GetSamplesToAcquire(), 2];
            input.ReadData(ref readWaveform, readWaveform.GetLength(0), GlobalInfo.ReadTimeOut);

            double[,] plotData = new double[readWaveform.GetLength(1), readWaveform.GetLength(0)];
            ArrayManipulation.Transpose(readWaveform, ref plotData);
//            easyChart_data.Plot(plotData);

            _globalInfo.Mainform.Invoke(new Action <double[, ], double, double>(easyChart_data.Plot), plotData, 0, 1);

            _refData  = new double[plotData.GetLength(1)];
            _testData = new double[plotData.GetLength(1)];
            Buffer.BlockCopy(plotData, 0, _refData, 0, _refData.Length * sizeof(double));
            Buffer.BlockCopy(plotData, _testData.Length * sizeof(double), _testData, 0,
                             _testData.Length * sizeof(double));

            double[] spectrum = new double[_testData.Length / 2];
            double   df;

            Spectrum.PowerSpectrum(_testData, input.GetSampleRate(), ref spectrum, out df);
//            easyChart_spectrum.Plot(spectrum.Take(1000).ToArray(), 0, df);
            _globalInfo.Mainform.Invoke(new Action <double[], double, double>(easyChart_spectrum.Plot), spectrum, 0, df);
            _analyzeSize = (uint)Math.Ceiling(outTime * _globalInfo.AITask.GetSampleRate());
        }
Beispiel #11
0
        /// <summary>
        /// 定时器,每秒钟刷新一次
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer1_Tick(object sender, EventArgs e)
        {
            try
            {
                //如果本地缓冲区数据足够则读取数据并显示,如果不够,返回
                if (aitask.AvailableSamples < readValue.Length)
                {
                    return;
                }
                timer1.Enabled = false;

                aitask.ReadData(ref readValue, -1);
                toolStripStatusLabel.Text = "正在读取数据中...";
                ArrayManipulation.Transpose(readValue, ref displayValue);
                int      size = displayValue.Length / 3;
                double[] buf1 = new double[size];
                double[] buf2 = new double[size];
                double[] buf3 = new double[size];
                Buffer.BlockCopy(displayValue, 0, buf1, 0, size * sizeof(double));
                Buffer.BlockCopy(displayValue, size * sizeof(double), buf2, 0, size * sizeof(double));
                Buffer.BlockCopy(displayValue, size * sizeof(double), buf3, 0, size * sizeof(double));
                stripChart_position.Plot(_displacementsensor.Convert(buf2));
                //stripChart_position.Plot(Conversion.resistance(buf2, RMax, 10, "cm"));
                //stripChart_weight.Plot(Conversion.Weight(buf1, 12, 250, 2000, 350, 500, "kg"));

                stripChart_weight.Plot(_loadCell.Convert(buf1));
                stripChart1.Plot(_thermistor.Convert(buf3));

                timer1.Enabled = true;
            }
            catch (JYDriverException ex)
            {
                if (ex.ErrorCode == -2 || ex.ErrorCode == -4 || ex.ErrorCode == -304)
                {
                    led1.Value      = false;
                    button1.Enabled = true;
                }
                else
                {
                    MessageBox.Show(ex.Message);
                }
            }
            catch (Exception ex)
            {
                aitask?.Stop();

                Start.Enabled             = true;
                toolStripStatusLabel.Text = "读取数据失败";
                MessageBox.Show(ex.Message);
            }
        }
Beispiel #12
0
        public void SubsetData(double[,] readData, int index, double samplingRate)
        {
            SampleRate = samplingRate;

            //If the size of the data length is the same, don't create new array to save the memory usage
            if (_dataLength != readData.GetLength(0))
            {
                _dataLength = readData.GetLength(0);
                tempData    = new double[100000];
            }

            ArrayManipulation.GetArraySubset(readData, index, ref tempData, ArrayManipulation.IndexType.column);
            PreData = tempData;
        }
Beispiel #13
0
        public void ArrayManipulation_2D_double_last_col()
        {
            InitData_dataset_3_rows_non_symmetric();
            double[][] newArray = ArrayManipulation.RemoveLastColumn2D(_trainingData);
            Assert.AreEqual(newArray.Length, 2);
            Assert.AreEqual(newArray[0].Length, 3);

            Assert.AreEqual(newArray[0][0], 1);
            Assert.AreEqual(newArray[0][1], 2);
            Assert.AreEqual(newArray[0][2], 3);

            Assert.AreEqual(newArray[1][0], 4);
            Assert.AreEqual(newArray[1][1], 5);
            Assert.AreEqual(newArray[1][2], 6);
        }
        static void RunProgram(ref bool programRunning)
        {
            int arrLen = InputHandling.ReadCollectionLength();

            int[] arr           = new int[arrLen];
            int   lastFailIndex = 0;

            InputHandling.ReadCollectionElements(ref arr, arrLen, ref lastFailIndex);
            int pivot = InputHandling.ReadCollectionIndex(arrLen, "Set pivot point: ");

            int[] arrRotated = ArrayManipulation.RotateArray(arr, arrLen, pivot);
            OutputHandling.PrintArray(arrRotated, arrRotated.Length, "Rotated array: ");
            OutputHandling.Question("Do you want to rotate another array? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Beispiel #15
0
        public void ArrayManipulation_2D_string_last_col()
        {
            InitData_dataset_3_rows_string();
            string[][] newArray = ArrayManipulation.RemoveLastColumn2D(_dataString);

            Assert.AreEqual(newArray.Length, 2);
            Assert.AreEqual(newArray[0].Length, 3);

            Assert.AreEqual(newArray[0][0], "a");
            Assert.AreEqual(newArray[0][1], "b");
            Assert.AreEqual(newArray[0][2], "c");

            Assert.AreEqual(newArray[1][0], "d");
            Assert.AreEqual(newArray[1][1], "e");
            Assert.AreEqual(newArray[1][2], "f");
        }
        public void SpeedTest()
        {
            int length = 10000000;

            AvxArray <float> vx = new float[length];

            Stopwatch sw = new Stopwatch();

            sw.Start();

            ArrayManipulation.Clear((uint)length, 0.5f, vx);

            sw.Stop();

            Console.WriteLine($"{sw.ElapsedMilliseconds} msec");
        }
Beispiel #17
0
        public void ArrayManipulationTestCase2()
        {
            uint specimenArrayLength = 10;

            int[][] queries = new int[3][];

            queries[0] = Array.ConvertAll("1 5 3".Split(' '), queriesTemp => Convert.ToInt32(queriesTemp));
            queries[1] = Array.ConvertAll("4 8 7".Split(' '), queriesTemp => Convert.ToInt32(queriesTemp));
            queries[2] = Array.ConvertAll("6 9 1".Split(' '), queriesTemp => Convert.ToInt32(queriesTemp));

            var expectedOutput = 10;

            long actualOutput = ArrayManipulation.Solve(specimenArrayLength, queries);

            Assert.AreEqual(expectedOutput, actualOutput);
        }
Beispiel #18
0
        public void Start()
        {
            if (null == tableLayoutPanel_waveConfig.Controls[0])
            {
                return;
            }
            double    sampleRate    = (double)numericUpDown_sampleRate.Value;
            Generator waveGenerator = tableLayoutPanel_waveConfig.Controls[0] as Generator;

            dataGridView_result.Rows.Clear();

            AITask.AITask input  = _globalInfo.AITask;
            AOTask.AOTask output = _globalInfo.AOTask;
            output.SetUpdateRate(sampleRate);
            input.SetSampleRate(sampleRate);
            double channelRange = waveGenerator.GetAmplitude();

            output.AddChannel(comboBox_aoChannel.SelectedIndex, -1 * channelRange, channelRange);
            input.AddChannel(comboBox_refChannel.SelectedIndex, -1 * channelRange, channelRange);
            input.AddChannel(comboBox_testChannel.SelectedIndex, -1 * channelRange, channelRange);

            double[] outData = waveGenerator.Generate();

            output.SetSamplesToUpdate(outData.Length);
            double outTime = outData.Length / output.GetUpdateRate();

            input.SetSamplesToAcquire((int)(outTime * input.GetSampleRate() * GlobalInfo.ExtraReadTime));
            output.WriteData(outData, -1);

            input.Start();
            output.Start();

            double[,] readWaveform = new double[input.GetSamplesToAcquire(), 2];
            input.ReadData(ref readWaveform, readWaveform.GetLength(0), GlobalInfo.ReadTimeOut);
            double[,] plotData = new double[readWaveform.GetLength(1), readWaveform.GetLength(0)];
            ArrayManipulation.Transpose(readWaveform, ref plotData);
            _globalInfo.Mainform.Invoke(new Action <double[, ], double, double>(easyChart_waveform.Plot), plotData, 0, 1);

            _testData = new double[plotData.GetLength(1)];
            Buffer.BlockCopy(plotData, 0, _testData, 0, _testData.Length * sizeof(double));
            _refWaveform = waveGenerator.GetRefWaveform() as SteppedLevelSineWaveform;
//            double[] peakToPeak, thd, nr, thdPlusNr, rms;
//            SeeSharpTools.JY.Audio.AudioAnalyzer.AnalyzeSteppedLevelSineWaveform(testWaveData, refWaveform,
//                out peakToPeak, out thd, out nr, out thdPlusNr, out rms);

            _analyzeSize = _refWaveform.GetTotalPoints();
        }
Beispiel #19
0
 private void timer_measure_Tick(object sender, EventArgs e)
 {
     timer_measure.Enabled = false;
     if (dataAvailable)
     {
         MathEngineHandler.WfmSubset(readData, device.SelectedChannels.ToList(), (double)numericUpDown_sampleRate.Value);
         ArrayManipulation.Transpose(readData, ref displayData);
         MathEngineHandler.Process();
         if (spectrumMode)
         {
             for (int i = 0; i < readData.GetLength(1); i++)
             {
                 ArrayManipulation.GetArraySubset(readData, i, ref tempData, ArrayManipulation.IndexType.column);
                 Spectrum.PowerSpectrum(tempData, _sampleRate, ref tempSpecData, out df);
                 ArrayManipulation.ReplaceArraySubset(tempSpecData, ref displayData, i, ArrayManipulation.IndexType.row);
             }
             easyChart1.Plot(displayData, 0, df);
         }
         else
         {
             if (checkBox_timeDisplay.Checked)
             {
                 easyChart1.Plot(displayData, 0, 1.0 / (double)numericUpDown_sampleRate.Value);
             }
             else
             {
                 easyChart1.Plot(displayData);
             }
         }
         easyChart1.SeriesNames = _seriesDefaultNames;
         easyChart1.SeriesNames = _chNames.ToArray();
         dgv_mathEngine.Invalidate();
         if (isSingleRun)
         {
             easyButton_stop_Click(null, null);
         }
         else
         {
             device.Stop();
             easyButton_contStart_Click(null, null);
         }
     }
     else
     {
         timer_measure.Enabled = true;
     }
 }
        private static void DoTest(StreamReader sr)
        {
            string[] nm = sr.ReadLine().Split(' ');

            int n = Convert.ToInt32(nm[0]);

            int m = Convert.ToInt32(nm[1]);

            int[][] queries = new int[m][];

            for (int i = 0; i < m; i++)
            {
                queries[i] = Array.ConvertAll(sr.ReadLine().Split(' '), queriesTemp => Convert.ToInt32(queriesTemp));
            }

            long result = ArrayManipulation.arrayManipulation(n, queries);

            Console.WriteLine(result);
        }
        public static double Median(int[] source)
        {
            Inputs.checkInputs(source);
            int[]  sortedArray = ArrayManipulation.uniqueSortedArray(source);
            double medianValue = 0;

            if (sortedArray.Length % 2 == 0)
            {
                double middleElement1 = sortedArray[(sortedArray.Length / 2) - 1];
                double middleElement2 = sortedArray[(sortedArray.Length / 2)];
                medianValue = (middleElement1 + middleElement2) / 2;
            }
            else
            {
                medianValue = sortedArray[sortedArray.Length / 2];
            }

            return(Math.Round(medianValue, 1));
        }
        public static double StandardDeviation(int[] source)
        {
            Inputs.checkInputs(source);
            int[]  sortedArray = ArrayManipulation.uniqueSortedArray(source);
            double average     = Mean(sortedArray);

            double[] powerOfDeviations = new double[sortedArray.Length];
            double   total             = 0;

            for (int i = 0; i < sortedArray.Length; i++)
            {
                powerOfDeviations[i] = Math.Pow((sortedArray[i] - average), 2);
            }
            for (int u = 0; u < powerOfDeviations.Length; u++)
            {
                total += powerOfDeviations[u];
            }
            return(Math.Round(Math.Sqrt(total / powerOfDeviations.Length), 1));
        }
Beispiel #23
0
        public void Run()
        {
            PrintProblem();
            int[] a;
            Console.WriteLine("size: operations:");
            a   = System.Array.ConvertAll(Console.ReadLine().Split(' '), aTemp => Convert.ToInt32(aTemp));
            arr = new int[a[1]][];
            Console.WriteLine("matrix:");
            for (int i = 0; i < a[1]; i++)
            {
                arr[i] = System.Array.ConvertAll(Console.ReadLine().Split(' '), arrTemp => Convert.ToInt32(arrTemp));
            }

            long result = ArrayManipulation.arrayManipulation(a[0], arr);

            Console.WriteLine();
            Console.WriteLine("Result:");
            Console.WriteLine(result);
            Console.ReadKey();
        }
Beispiel #24
0
        static void RunProgram(ref bool programRunning)
        {
            // Take string as input
            OutputHandling.Message("Type in a string to check for duplicate characters: ", ConsoleColor.Green, false);
            string s = Console.ReadLine();

            // Remove extra spaces from string and tabs
            string sClean = StringManipulation.RemoveExtraSpaces(s);

            // Convert String to char array
            char[] sToChar    = Conversion.ConvertToCharArray(sClean);
            int    sToCharLen = sToChar.Length;

            // Remove duplicate characters
            ArrayManipulation.RemoveDuplicates(ref sToChar, ref sToCharLen);

            OutputHandling.PrintArray(sToChar, sToCharLen, "The string without duplicates is: ", "", newLine: false);
            OutputHandling.Question("Do you want to remove duplicate characters in another string? Y / N");
            programRunning = InputHandling.QuestionOptions();
        }
Beispiel #25
0
        public void ExecuteTest()
        {
            Random rd = new Random(1234);

            for (uint copy_channels = 0; copy_channels <= 32; copy_channels++)
            {
                for (uint slides = 1; slides <= 100; slides++)
                {
                    float[] x = (new float[(copy_channels + 2) * slides]).Select((_) => (float)rd.NextDouble()).ToArray();
                    float[] y = (new float[(copy_channels + 4) * slides]).Select((_) => (float)rd.NextDouble()).ToArray();

                    float[] x_copy = (float[])x.Clone(), y_copy = (float[])y.Clone();

                    AvxArray <float> vx = x;
                    AvxArray <float> vy = y;

                    ArrayManipulation.PatternCopy(copy_channels + 2, 1, copy_channels + 4, 2, copy_channels, slides, vx, vy);

                    x = vx;
                    y = vy;

                    CollectionAssert.AreEqual(x_copy, x);

                    for (uint i = 0; i < slides; i++)
                    {
                        Assert.AreEqual(y_copy[i * (copy_channels + 4) + 0], y[i * (copy_channels + 4) + 0], $"slides:{slides}, copys:{copy_channels}, index:{i}");
                        Assert.AreEqual(y_copy[i * (copy_channels + 4) + 1], y[i * (copy_channels + 4) + 1], $"slides:{slides}, copys:{copy_channels}, index:{i}");

                        for (uint j = 0; j < copy_channels; j++)
                        {
                            Assert.AreEqual(x[i * (copy_channels + 2) + (j + 1)], y[i * (copy_channels + 4) + (j + 2)], $"slides:{slides}, copys:{copy_channels}, index:{i}, {j}");
                        }

                        Assert.AreEqual(y_copy[i * (copy_channels + 4) + (copy_channels + 2)], y[i * (copy_channels + 4) + (copy_channels + 2)], $"slides:{slides}, copys:{copy_channels}, index:{i}");
                        Assert.AreEqual(y_copy[i * (copy_channels + 4) + (copy_channels + 3)], y[i * (copy_channels + 4) + (copy_channels + 3)], $"slides:{slides}, copys:{copy_channels}, index:{i}");
                    }

                    Console.WriteLine($"pass:{slides}, {copy_channels}");
                }
            }
        }
Beispiel #26
0
        public static int[] ConvertBase10ToBaseX(int base10, int baseX)
        {
            int[] baseXNumberReversed       = new int[32];
            int   baseXNumberReversedLength = 0;

            while (base10 > 0)
            {
                baseXNumberReversed[baseXNumberReversedLength++] = base10 % baseX;
                base10 /= baseX;
            }

            ArrayManipulation.ReverseArray(ref baseXNumberReversed, baseXNumberReversedLength);

            int[] baseXNumber = new int[baseXNumberReversedLength];

            for (int i = 0; i < baseXNumberReversedLength; i++)
            {
                baseXNumber[baseXNumberReversedLength - 1 - i] = baseXNumberReversed[i];
            }

            return(baseXNumber);
        }
Beispiel #27
0
        /// <summary>
        /// 分析StepSine数据
        /// </summary>
        //private void StepSineAnalysis()
        //{
        //    stepSine.Excitation = TempInput;
        //    stepSine.Response = TempOutput;
        //    stepSine.Analysis();
        //    easyChartInput.Plot(TempInput);
        //    easyChartOutput.Plot(TempOutput);

        //    easyChartMagnitude.Plot(stepSine.Frequencies,stepSine.AmplitudesDB);
        //    //easyChartPhase.Plot(stepSine.Frequencies,stepSine.PhasesDeg);
        //    easyChartTHD.Plot(stepSine.Frequencies,stepSine.THDsDB);

        //}
        /// <summary>
        /// 分析WhiteNoise数据
        /// </summary>
        private void WhiteNoiseAnalysis()
        {
            double samplingRate = 200000;
            int    freqLines    = 5000; //set frequency resolution here
            double df           = samplingRate / 2 / freqLines;

            double[] analysisInWav  = new double[freqLines * 2];
            double[] analysisOutWav = new double[freqLines * 2];
            double[] bodeMag        = new double[freqLines];
            double[] bodePhase      = new double[freqLines];

            int numOfAverage = (int)Math.Floor((decimal)(TempInput.Length / 2 / freqLines));

            easyChartInput.Plot(TempInput);
            easyChartOutput.Plot(TempOutput);
            //创建FRF分析对象
            WhiteNoiseFRF FRFAnalysis = new WhiteNoiseFRF();

            FRFAnalysis.SetAveraging(WhiteNoiseFRF.AverageMode.RMS, numOfAverage, true);
            //FRF多次分析取平均
            for (int i = 0; i < numOfAverage; i++)
            {
                ArrayManipulation.GetArraySubset(TempInput, i * 2 * freqLines, ref analysisInWav);
                ArrayManipulation.GetArraySubset(TempOutput, i * 2 * freqLines, ref analysisOutWav);
                FRFAnalysis.SetInput(analysisInWav);
                FRFAnalysis.SetOutput(analysisOutWav);
                if (i == 0)
                {
                    FRFAnalysis.InitStatus();
                }
                bodeMag   = FRFAnalysis.GetMagenitude(true);
                bodePhase = FRFAnalysis.GetPhase(true);
            }
            bool averageDone = FRFAnalysis.AveragingDone();

            easyChartMagnitude.Plot(bodeMag, 0, df);
            //easyChartPhase.Plot(bodePhase, 0, df);
        }
        // 设置定时器
        private void timer1_Tick(object sender, EventArgs e)
        {
            timer1.Enabled = false;
            if (mutilAiTask.AvailableSamples >= readValue.Length)
            {
                try
                {
                    mutilAiTask.ReadData(ref readValue, -1);
                    toolStripStatusLabel.Text = "数据读取中...";
                }
                catch (JYDriverException ex)
                {
                    timer1.Enabled            = true;
                    toolStripStatusLabel.Text = "数据读取错误";
                    MessageBox.Show(ex.Message);
                }

                // 绘制图像
                ArrayManipulation.Transpose(readValue, ref displayValue);
                easyChart_wave.Plot(displayValue);
            }
            timer1.Enabled = true;
        }
Beispiel #29
0
        public void ExecuteTest()
        {
            Random rd = new Random(1234);

            for (uint src_length = 1; src_length <= 32; src_length++)
            {
                for (uint dst_length = src_length; dst_length <= src_length * 32; dst_length += src_length)
                {
                    for (uint slides = 0; slides <= 4; slides++)
                    {
                        float[] x = (new float[src_length * slides + 1]).Select((_) => (float)rd.NextDouble() * 2 - 1).ToArray();
                        float[] y = (new float[dst_length * slides + 1]).Select((_) => (float)rd.NextDouble() + 1).ToArray();

                        float v1 = y[dst_length * slides];

                        AvxArray <float> vx = x, vy = y;

                        ArrayManipulation.Broadcast(src_length, vx, dst_length, vy, slides);

                        y = vy;

                        for (int j = 0; j < slides; j++)
                        {
                            for (int i = 0; i < dst_length; i++)
                            {
                                Assert.AreEqual(x[i % src_length + j * src_length], y[i + j * dst_length]);
                            }
                        }

                        Assert.AreEqual(v1, y[dst_length * slides]);

                        Console.WriteLine($"pass: {src_length} {dst_length} {slides}");
                    }
                }
            }
        }
Beispiel #30
0
        public void MergeCloseEncounters()
        {
            var i = 0;

            while (i < Encounters.Count - 1)
            {
                var fifteenSec = new TimeSpan(0, 0, 0, 15);

                if (Encounters[i + 1].Start - Encounters[i].End < fifteenSec)
                {
                    //Merge both encounters
                    Encounters[i].End = Encounters[i + 1].End;

                    ArrayManipulation.MergeEncounterDictionaries(Encounters[i].Players, Encounters[i + 1].Players);
                    ArrayManipulation.MergeEncounterDictionaries(Encounters[i].NPC, Encounters[i + 1].NPC);
                    ArrayManipulation.MergeEncounterDictionaries(Encounters[i].Pets, Encounters[i + 1].Pets);

                    Encounters.RemoveAt(i + 1);
                    --i;
                }

                ++i;
            }
        }