Beispiel #1
0
 public static void ArrRotate(FFT_Complex[] data, int pStart)
 {
     FFT_Complex[] temp = new FFT_Complex[pStart];
     Array.Copy(data, 0, temp, 0, pStart);
     Array.Copy(data, pStart, data, 0, data.Count() - pStart);
     Array.Copy(temp, 0, data, data.Count() - pStart, pStart);
 }
Beispiel #2
0
 extern static System.Int32 FFT_translate(out FFT_Complex p_dst, FFT_Complex[] p_src, System.Int32 num_of_points);
Beispiel #3
0
 extern static System.Int32 FFT_translateToSpectrum(out System.Double p_delte_hz, out System.Double p_amplitude, out FFT_Complex p_dst, FFT_Complex[] p_src, System.Int32 num_of_points, System.Double hz);
Beispiel #4
0
        void PaintToGrapgh()
        {
            writeLogTiming = DateTime.Now;
            filePath       = logPath + "\\" + $"{ByteConverter.ToHexString(curDevice.mac)}_{writeLogTiming.ToString("MMdd_HHmm")}.csv";

            double axisH = 0;

            FFT_Complex[] fftX, fftY, fftZ;

            fftX = new FFT_Complex[dataLen];
            fftY = new FFT_Complex[dataLen];
            fftZ = new FFT_Complex[dataLen];

            for (int i = 0; i < pList.Length; i++)
            {
                pList[i] = new PointPairList();
            }
            int count = 0;

            axisH = 0;
            double hz = 0.0f, m_hz = 2048.0;

            double[]      m_amplitude_x = new double[dataLen], m_amplitude_y = new double[dataLen], m_amplitude_z = new double[dataLen];
            FFT_Complex[] m_fft_out_x = new FFT_Complex[dataLen], m_fft_out_y = new FFT_Complex[dataLen], m_fft_out_z = new FFT_Complex[dataLen];

            zgcFftX.GraphPane.XAxis.Scale.Min = -2;
            zgcFftX.GraphPane.XAxis.Scale.Max = dataLen + 20;
            zgcFftY.GraphPane.XAxis.Scale.Min = -2;
            zgcFftY.GraphPane.XAxis.Scale.Max = dataLen + 20;
            zgcFftZ.GraphPane.XAxis.Scale.Min = -2;
            zgcFftZ.GraphPane.XAxis.Scale.Max = dataLen + 20;

            while (flgReceiving)
            {
                int fftArrayCount = 0;


                if (point.Count > 0)
                {
                    PointXYX p;
                    double   h = 0.0;
                    double   timeScale = 1000; //ms
                    double   multi = 0.001;
                    string   log = "";
                    double   x, y, z;

                    while (point.Count > 0)
                    {
                        p = point.Dequeue();
                        if (p is null)
                        {
                            continue;
                        }
                        axisH++;
                        h = axisH / timeScale;
                        x = p._x * multi; y = p._y * multi; z = p._z * multi;

                        fftX[fftArrayCount] = new FFT_Complex(x, 0.0f);
                        fftY[fftArrayCount] = new FFT_Complex(y, 0.0f);
                        fftZ[fftArrayCount] = new FFT_Complex(z, 0.0f);
                        if (++fftArrayCount >= dataLen)
                        {
                            fftArrayCount = 0;
                        }

                        pList[0].Add(h, x);
                        pList[1].Add(h, y);
                        pList[2].Add(h, z);

                        log += $"{x.ToString("F3")},{y.ToString("F3")},{z.ToString("F3")}\n";
                    }
                    if ((DateTime.Now - writeLogTiming).TotalMinutes >= writeLogInterval)
                    {
                        writeLogTiming = writeLogTiming.AddMinutes(writeLogInterval);
                        filePath       = logPath + "\\" + $"{ByteConverter.ToHexString(curDevice.mac)}_{writeLogTiming.ToString("MMdd_HHmm")}.csv";
                    }
                    AsyncWriteFile.WriteText(filePath, log);
                    FFT_Complex_Rotate.ArrRotate(fftX, fftArrayCount);
                    FFT_Complex_Rotate.ArrRotate(fftY, fftArrayCount);
                    FFT_Complex_Rotate.ArrRotate(fftZ, fftArrayCount);

                    for (int i = 0; i < pList.Length; i++)
                    {
                        if (pList[i].Count > dataLen)
                        {
                            pList[i].RemoveRange(0, pList[i].Count - dataLen);
                        }
                    }

                    double
                        max = h + 0.05,
                        min = h - dataLen / timeScale;
                    if (!flgPause)
                    {
                        dUse duse;
                        zgcAxisX.GraphPane.XAxis.Scale.Max = max;
                        zgcAxisX.GraphPane.XAxis.Scale.Min = min;
                        zgcAxisY.GraphPane.XAxis.Scale.Max = max;
                        zgcAxisY.GraphPane.XAxis.Scale.Min = min;
                        zgcAxisZ.GraphPane.XAxis.Scale.Max = max;
                        zgcAxisZ.GraphPane.XAxis.Scale.Min = min;
                        paintCurve(pList[0], zgcAxisX);
                        paintCurve(pList[1], zgcAxisY);
                        paintCurve(pList[2], zgcAxisZ);

                        if (count++ > 10)
                        {
                            if (fftX.Length % 1024 == 0)
                            {
                                FFT_translateToSpectrum(out hz, out m_amplitude_x[0], out m_fft_out_x[0], fftX, fftX.Length, m_hz);
                            }
                            if (fftY.Length % 1024 == 0)
                            {
                                FFT_translateToSpectrum(out hz, out m_amplitude_y[0], out m_fft_out_y[0], fftY, fftY.Length, m_hz);
                            }
                            if (fftZ.Length % 1024 == 0)
                            {
                                FFT_translateToSpectrum(out hz, out m_amplitude_z[0], out m_fft_out_z[0], fftZ, fftZ.Length, m_hz);
                            }
                            GraphPane       pane;
                            PointPairList[] list = new PointPairList[3];
                            list[0] = new PointPairList();
                            list[1] = new PointPairList();
                            list[2] = new PointPairList();
                            for (int i = 1; i < m_amplitude_x.Length; i++)
                            {
                                list[0].Add(hz * i, m_amplitude_x[i]);
                            }
                            for (int i = 1; i < m_amplitude_y.Length; i++)
                            {
                                list[1].Add(hz * i, m_amplitude_y[i]);
                            }
                            for (int i = 1; i < m_amplitude_z.Length; i++)
                            {
                                list[2].Add(hz * i, m_amplitude_z[i]);
                            }

                            try
                            {
                                pane = zgcFftX.GraphPane;
                                pane.GraphObjList.Clear();
                                pane.CurveList.Clear();
                                pane.AddBar("", list[0], Color.Gray);
                                zgcFftX.AxisChange();
                                Invoke(duse = () =>
                                {
                                    zgcFftX.Refresh();
                                });

                                pane = zgcFftY.GraphPane;
                                pane.GraphObjList.Clear();
                                pane.CurveList.Clear();
                                pane.AddBar("", list[1], Color.Gray);
                                zgcFftY.AxisChange();
                                Invoke(duse = () =>
                                {
                                    zgcFftY.Refresh();
                                });

                                pane = zgcFftZ.GraphPane;
                                pane.GraphObjList.Clear();
                                pane.CurveList.Clear();
                                pane.AddBar("", list[2], Color.Gray);
                                zgcFftZ.AxisChange();
                                Invoke(duse = () =>
                                {
                                    zgcFftZ.Refresh();
                                });
                            }
                            catch { }
                        }

                        Thread.Sleep(10);
                    }
                }
                else
                {
                    Thread.Sleep(10);
                }
            }
        }