private void buttonGetData_Click_1(object sender, EventArgs e) { try { //при нажатии на кнопку происходит вызов статического метода ReadDataFromMEMS() для считывания показаний с акселерометров DataMEMS.ReadDataFromMEMS(); } catch (Exception ex) { listBoxLog.Items.Add(DateTime.Now.ToLongTimeString() + " " + ex.Message); listBoxLog.SelectedIndex = listBoxLog.Items.Count - 1; } }
private void buttonRun_Click(object sender, EventArgs e) { //List<Complex> listComplexX = new List<Complex>(); //List<Complex> listComplexY = new List<Complex>(); //List<Complex> listComplexZ = new List<Complex>(); List <double> listX = new List <double>(); List <double> listY = new List <double>(); List <double> listZ = new List <double>(); var sensor1Signal = pictureBoxSensor1Signal.CreateGraphics(); var sensor2Signal = pictureBoxSensor2Signal.CreateGraphics(); int greenXSensor1 = 0; int greenYSensor1 = 0; int greenShiftSensor1 = 2; int blueXSensor1 = 0; int blueYSensor1 = 0; int blueShiftSensor1 = 2; int redXSensor1 = 0; int redYSensor1 = 0; int redShiftSensor1 = 2; int greenXSensor2 = 0; int greenYSensor2 = 0; int greenShiftSensor2 = 2; int blueXSensor2 = 0; int blueYSensor2 = 0; int blueShiftSensor2 = 2; int redXSensor2 = 0; int redYSensor2 = 0; int redShiftSensor2 = 2; int sensorId1 = 0; int i = 0; int[] arrayCoordinates; sensor1Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 60), new Point(800, 60)); sensor1Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 120), new Point(800, 120)); sensor1Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 180), new Point(800, 180)); sensor2Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 60), new Point(800, 60)); sensor2Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 120), new Point(800, 120)); sensor2Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 180), new Point(800, 180)); while (i < 1000) { arrayCoordinates = DataMEMS.ReadDataFromMEMS(); if (i == 0) { sensorId1 = arrayCoordinates[0]; } if (arrayCoordinates[0] == sensorId1) { sensor1Signal.DrawLine(new Pen(Color.Green, 1), greenXSensor1, greenYSensor1, greenShiftSensor1, arrayCoordinates[1] / 250); greenXSensor1 = greenShiftSensor1; greenYSensor1 = arrayCoordinates[1] / 250; greenShiftSensor1 = greenShiftSensor1 + 2; //listComplexX.Add(new Complex(arrayCoordinates[1], 0)); listX.Add((double)arrayCoordinates[1]); sensor1Signal.DrawLine(new Pen(Color.Blue, 1), blueXSensor1, blueYSensor1, blueShiftSensor1, arrayCoordinates[2] / 250); blueXSensor1 = blueShiftSensor1; blueYSensor1 = arrayCoordinates[2] / 250; blueShiftSensor1 = blueShiftSensor1 + 2; //listComplexY.Add(new Complex(arrayCoordinates[2], 0)); listY.Add((double)arrayCoordinates[2]); sensor1Signal.DrawLine(new Pen(Color.Red, 1), redXSensor1, redYSensor1, redShiftSensor1, arrayCoordinates[3] / 250); redXSensor1 = redShiftSensor1; redYSensor1 = arrayCoordinates[3] / 250; redShiftSensor1 = redShiftSensor1 + 2; //listComplexZ.Add(new Complex(arrayCoordinates[3], 0)); listZ.Add((double)arrayCoordinates[3]); } else { sensor2Signal.DrawLine(new Pen(Color.Green, 1), greenXSensor2, greenYSensor2, greenShiftSensor2, arrayCoordinates[1] / 250); greenXSensor2 = greenShiftSensor2; greenYSensor2 = arrayCoordinates[1] / 250; greenShiftSensor2 = greenShiftSensor2 + 2; sensor2Signal.DrawLine(new Pen(Color.Blue, 1), blueXSensor2, blueYSensor2, blueShiftSensor2, arrayCoordinates[2] / 250); blueXSensor2 = blueShiftSensor2; blueYSensor2 = arrayCoordinates[2] / 250; blueShiftSensor2 = blueShiftSensor2 + 2; sensor2Signal.DrawLine(new Pen(Color.Red, 1), redXSensor2, redYSensor2, redShiftSensor2, arrayCoordinates[3] / 250); redXSensor2 = redShiftSensor2; redYSensor2 = arrayCoordinates[3] / 250; redShiftSensor2 = redShiftSensor2 + 2; } //listBoxLog.Items.Add(DateTime.Now.ToLongTimeString() + " " + arrayCoordinates[0] + " " + arrayCoordinates[1] + " " + arrayCoordinates[2] + " " + arrayCoordinates[3]); //listBoxLog.SelectedIndex = listBoxLog.Items.Count - 1; if (i % 250 == 0) { sensor1Signal.Clear(Color.White); sensor2Signal.Clear(Color.White); sensor1Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 60), new Point(800, 60)); sensor1Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 120), new Point(800, 120)); sensor1Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 180), new Point(800, 180)); sensor2Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 60), new Point(800, 60)); sensor2Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 120), new Point(800, 120)); sensor2Signal.DrawLine(new Pen(Color.FromArgb(233, 233, 233)), new Point(0, 180), new Point(800, 180)); greenXSensor1 = 0; greenShiftSensor1 = 2; blueXSensor1 = 0; blueShiftSensor1 = 2; redXSensor1 = 0; redShiftSensor1 = 2; greenXSensor2 = 0; greenShiftSensor2 = 2; blueXSensor2 = 0; blueShiftSensor2 = 2; redXSensor2 = 0; redShiftSensor2 = 2; } i++; } //Complex[] samplesX = listComplexX.ToArray(); //Complex[] samplesY = listComplexY.ToArray(); //Complex[] samplesZ = listComplexZ.ToArray(); //прореживаю листы до 2^n int n = 14; while (listX.Count / Math.Pow(2, n) < 1) { n--; } int countList = listX.Count; int TwoPower = (int)Math.Pow(2, n); Random rnd = new Random(); for (int k = 0; k < (countList - TwoPower); k++) { listX.RemoveAt(rnd.Next(k)); listY.RemoveAt(rnd.Next(k)); listZ.RemoveAt(rnd.Next(k)); } double[] FourierResultX = Fourier.FFT(listX.ToArray()); double[] FourierResultY = Fourier.FFT(listY.ToArray()); double[] FourierResultZ = Fourier.FFT(listZ.ToArray()); //chart1.ChartAreas[0].AxisX.Minimum = -1000; //chart1.ChartAreas[0].AxisX.Maximum = 10; //chart1.ChartAreas[0].AxisX.Interval = 1; //chart1.ChartAreas[0].AxisY.Minimum = -1000; //chart1.ChartAreas[0].AxisY.Maximum = 100; //Fourier.Forward(samplesX, FourierOptions.Matlab); //double[] FourierResultX = Fourier.FFT(XSamples); //double[] FourierResultY = Fourier.FFT(YSamples); //double[] FourierResultZ = Fourier.FFT(ZSamples); for (int j = 0; j < FourierResultX.Length; j++) { chart1.Series["Series1"].Points.AddXY (j, FourierResultX[j]); } for (int j = 0; j < FourierResultY.Length; j++) { chart2.Series["Series1"].Points.AddXY (j, FourierResultY[j]); } for (int j = 0; j < FourierResultZ.Length; j++) { chart3.Series["Series1"].Points.AddXY (j, FourierResultZ[j]); } // Fourier.Forward(samplesY, FourierOptions.Matlab); // for (int j = 0; j < samplesY.Length / 10; j++) // { // chart2.Series["Series1"].Points.AddXY // (j, samplesY[j * 10].Magnitude); // } // Fourier.Forward(samplesZ, FourierOptions.Matlab); // for (int j = 0; j < samplesZ.Length / 10; j++) // { // chart3.Series["Series1"].Points.AddXY // (j * 10, samplesZ[j * 10].Magnitude); // } }