Beispiel #1
0
        static void Main(string[] args)
        {
            test1();
            CaculateTimes caculate = new CaculateTimes();

            caculate.StartTime();
            //4 3 2 6 7 8 9 0
            int[]     nums      = { 4, 3, 2, 6, 7, 8, 9, 0 };
            int[]     nums_2    = { 1, 2, 5, 4, 8, 6, 4, 5, 2, 3, 1 };
            Complex[] complices = new Complex[nums.Length];
            for (int i = 0; i < nums.Length; i++)
            {
                complices[i] = new Complex(nums[i], 0);
            }
            FourierTransform.DFT(complices, FourierTransform.Direction.Backward);
            for (int i = 0; i < nums.Length; i++)
            {
                Console.WriteLine(complices[i].Re + " " + complices[i].Im);
            }
            Console.WriteLine();
            Console.WriteLine("====================");
            Console.WriteLine();
            for (int i = 0; i < nums.Length; i++)
            {
                complices[i].Re = nums[i];
                complices[i].Im = 0;
            }
            FourierTransform.FFT(complices, FourierTransform.Direction.Backward);
            for (int i = 0; i < nums.Length; i++)
            {
                Console.WriteLine(complices[i].Re + " " + complices[i].Im);
            }
            Console.WriteLine(caculate.EndTime());
            Console.ReadKey();
        }
 protected BSDataObject ProcessUsingFourierDirection(BSDataObject iObject, FourierTransform.Direction iDir)
 {
     Complex[] complexDataArray = (from tmp in iObject.DataArray select new Complex(tmp, 0)).ToArray();
     FourierTransform.DFT(complexDataArray, iDir);
     double[] resultingArray = (from tmp in complexDataArray select Math.Sqrt(tmp.Re * tmp.Re + tmp.Im * tmp.Im)).ToArray();
     return(new BSDataObject(resultingArray, iObject.ObjName + "_Fouirer"));
 }
Beispiel #3
0
        public static double[] Transform(double[] functionPoints, string transformate)
        {
            var copyofFunctionsPoints = functionPoints;


            switch (transformate)
            {
            case "FFT":
                var complexArray = Array.ConvertAll(copyofFunctionsPoints, x => new Complex(x, 0));

                FourierTransform.DFT(complexArray, FourierTransform.Direction.Forward);

                copyofFunctionsPoints = Array.ConvertAll(complexArray, z => z.Real);
                break;

            case "IFFT":
                var complexArray2 = Array.ConvertAll(copyofFunctionsPoints, x => new Complex(x, 0));

                FourierTransform.DFT(complexArray2, FourierTransform.Direction.Backward);

                copyofFunctionsPoints = Array.ConvertAll(complexArray2, z => z.Real);
                break;


            case "DST":
                SineTransform.DST(copyofFunctionsPoints);
                break;

            case "IDST":
                SineTransform.IDST(copyofFunctionsPoints);
                break;

            case "DCT":
                CosineTransform.DCT(copyofFunctionsPoints);
                break;

            case "IDCT":
                CosineTransform.IDCT(copyofFunctionsPoints);
                break;

            case "DHT":
                HartleyTransform.DHT(copyofFunctionsPoints);
                break;

            case "FHT":
                HilbertTransform.FHT(copyofFunctionsPoints,
                                     FourierTransform.Direction.Forward);
                break;

            case "IFHT":
                HilbertTransform.FHT(copyofFunctionsPoints,
                                     FourierTransform.Direction.Backward);
                break;

            default:
                throw new ArgumentException("Unknown transformation!");
            }
            return(copyofFunctionsPoints); //athenia programuje//dididididi//di/kocham PaciA// JJKAKAKK  K
        }
Beispiel #4
0
        public (double[] real, double[] imaginary) CalculateDFT()
        {
            var data = GetComplexData().ToArray();

            FourierTransform.DFT(data, FourierTransform.Direction.Forward);

            return(data.Re(), data.Im());
        }
Beispiel #5
0
        public static void DFT(Complex[] x, int mode = 1)
        {
            var dir = FourierTransform.Direction.Forward;

            if (mode == -1)
            {
                dir = FourierTransform.Direction.Backward;
            }
            FourierTransform.DFT(x, dir);
        }
Beispiel #6
0
        public ActionResult fftC1(Data[] json)
        {
            Complex[] data = new Complex[json.Length];

            for (int i = 0; i < json.Length; i++)
            {
                var com = new Complex(json[i].Re, json[i].Im);
                data[i] = com;
            }

            FourierTransform.DFT(data, FourierTransform.Direction.Backward);

            var result = data.ToList().Select(s => new
            {
                Im        = s.Im,
                Re        = s.Re,
                Magnitude = s.Magnitude
            }).ToArray();

            return(new OkObjectResult(result));
        }
Beispiel #7
0
        private Point[] Init()
        {
            WAVReader wAVReader = new WAVReader();

            wAVReader.ReadWAVFile(fileName);
            Complex[] complices = new Complex[frame];


            canvasOs.Width  = this.Width;
            canvasOs.Height = this.Height;


            int i_0 = 0;//前面为0的部分

            while (wAVReader.stereos[i_0].Left == 0 && wAVReader.stereos[i_0].Right == 0)
            {
                i_0++;
            }
            for (int i = 0; i < complices.Length; i++)
            {
                complices[i] = new Complex(wAVReader.stereos[i + i_0 + startNumber].Right * Hamming(i, frame), 0);
            }

            FourierTransform.DFT(complices, FourierTransform.Direction.Backward);
            double max = 0;

            Point[] points = new Point[frame];
            for (int i = 0; i < points.Length; i++)
            {
                double x = (i * 1.0 / 44100) * unitOfOneSecond;
                if (complices[i].Magnitude > max)
                {
                    max = complices[i].Magnitude;
                }
                double y = TranY(complices[i].Magnitude / heightZipCount);
                points[i] = new Point(x, y);
            }
            return(points);
        }
Beispiel #8
0
        public ActionResult fft1(string[] json)
        {
            Complex[] data = new Complex[json.Length];
            Complex[] fft  = new Complex[json.Length];
            for (int i = 0; i < json.Length; i++)
            {
                var com = this.ParceCom(json[i]);
                data[i] = com;
            }

            Array.Copy(data, fft, data.Length);

            FourierTransform.DFT(data, FourierTransform.Direction.Backward);

            var result = new
            {
                time = data.Select(d => new { real = d.Re, imag = d.Im }).ToArray(),
                fft  = fft.Select(d => new { real = d.Re, imag = d.Im }).ToArray()
            };


            return(Json(result));
        }
        private void CompileForm()
        {
            if (!GuideLogFilePath.Text.Contains(".log"))
            {
                MessageBox.Show("File not a log file");
                return;
            }

            PrepGraphs();

            //Acquire header object (XML)
            LogHeaderXML xH = new LogHeaderXML(GuideLogFilePath.Text);

            //Fill in basic information
            BuildBox.Text      = xH.Detail(xH.TheSkyXBuild);
            MountBox.Text      = xH.Detail(xH.Mount);
            CameraBox.Text     = xH.Detail(xH.Camera);
            DateBox.Text       = (xH.Detail(xH.LocalStartDateTime)).Split(' ')[0];
            TimeBox.Text       = (xH.Detail(xH.LocalStartDateTime)).Split(' ')[1];
            ExposureBox.Text   = (xH.Detail(xH.ExposureTime));
            BinningBox.Text    = (xH.Detail(xH.BinX) + " x " + xH.Detail(xH.BinY));
            CalDecBox.Text     = (xH.Detail(xH.Calibrationdeclination));
            CurrentDecBox.Text = (xH.Detail(xH.Declinationnow));
            CalPABox.Text      = (xH.Detail(xH.Calibrationpositionangle));
            CurrentPABox.Text  = (xH.Detail(xH.Positionanglenow));

            AxisControlBox.Text = xH.Detail(xH.XPlusAxis) +
                                  " / " +
                                  xH.Detail(xH.XMinusAxis) +
                                  " / " +
                                  xH.Detail(xH.YPlusAxis) +
                                  " / " +
                                  xH.Detail(xH.YMinusAxis);
            AxisControlBox.Text    = AxisControlBox.Text.Replace("Not Enabled", "Off");
            AxisControlBox.Text    = AxisControlBox.Text.Replace("Enabled", "On");
            MountControlGroup.Text = xH.Detail(xH.Autoguide);
            AggressivenessBox.Text = xH.Detail(xH.AggressivenessFactorXPlus) +
                                     " / " +
                                     xH.Detail(xH.AggressivenessFactorXMinus) +
                                     " / " +
                                     xH.Detail(xH.AggressivenessFactorYPlus) +
                                     " / " +
                                     xH.Detail(xH.AggressivenessFactorYMinus);
            MoveBox.Text = xH.Detail(xH.MinimumMove) + " (sec) / " + xH.Detail(xH.MaximumMove) + " (sec)";

            //if (Convert.ToInt16(xH.Detail("BinX") != 0) int binY = Convert.ToInt16(xH.Detail("BinY"));
            // int binX = if (Convert.ToInt16(xH.Detail("BinX"));
            //int binY = Convert.ToInt16(xH.Detail("BinY"));
            int binX = Convert.ToInt16(xH.Detail("BinX"));
            int binY = Convert.ToInt16(xH.Detail("BinY"));

            double scaleX; // = 1.0 / (double)binX;
            double scaleY; // = 1.0 / (double)binY;
            double scaleT;

            double xSlope = 0;
            double ySlope = 0;
            double tSlope = 0;

            string scaleXString = xH.Detail("ImageScaleXatbinning" + binX.ToString("0"));
            string scaleYString = xH.Detail("ImageScaleYatbinning" + binY.ToString("0"));

            if (scaleXString.Contains("NA"))
            {
                scaleX = enteredImageScale;
            }
            else
            {
                scaleX = Convert.ToDouble(scaleXString);
            }
            if (scaleYString.Contains("NA"))
            {
                scaleY = enteredImageScale;
            }
            else
            {
                scaleY = Convert.ToDouble(scaleYString);
            }

            scaleT = Math.Sqrt(Math.Pow(scaleX, 2) + Math.Pow(scaleY, 2));
            //double scaleT = scaleX;
            ImageScaleBox.Text = scaleXString + " / " + scaleYString;

            AOAggressivenessBox.Text = xH.Detail(xH.AOAggressiveness);
            AORelayBumpSizeBox.Text  = xH.Detail(xH.AORelayBumpSize);
            AORelayThresholdBox.Text = xH.Detail(xH.AORelayThreshold);
            AOSlewRateBox.Text       = xH.Detail(xH.AOSlewRate);
            AOTrackSizeBox.Text      = xH.Detail(xH.AOTrackBoxSize);

            //Acquire data from log
            LogReader guideLog = new LogReader(GuideLogFilePath.Text);
            //Make a complex vector of guideLog data
            int vLen = guideLog.GetLogSize() - 1;

            Complex[] errorValsTcplx   = new Complex[vLen];
            Complex[] errorValsXcplx   = new Complex[vLen];
            Complex[] errorValsYcplx   = new Complex[vLen];
            double[]  errorValsTdbl    = new double[vLen];
            double[]  errorValsXdbl    = new double[vLen];
            double[]  errorValsYdbl    = new double[vLen];
            Double[]  correctionXPlus  = new double[vLen];
            Double[]  correctionXMinus = new double[vLen];
            Double[]  correctionYPlus  = new double[vLen];
            Double[]  correctionYMinus = new double[vLen];
            double[]  wormIndexRA      = new double[vLen];
            double[]  wormIndexDec     = new double[vLen];
            double[]  guideStarSignal  = new double[vLen];

            double FFTTimeIncrement = 0; //time per sample in sec
            double nowTime          = 0;

            //time domain plot of log data, total, X and Y, mean, and guidestarsignal
            for (int i = 0; i < vLen; i++)
            {
                errorValsTdbl[i] = guideLog.GetLogValue(i, LogReader.LogVal.TotGuideErr) * scaleT;
                errorValsXdbl[i] = guideLog.GetLogValue(i, LogReader.LogVal.GuideErrX) * scaleX;
                errorValsYdbl[i] = guideLog.GetLogValue(i, LogReader.LogVal.GuideErrY) * scaleY;

                correctionXPlus[i]  = guideLog.GetLogValue(i, LogReader.LogVal.XPlusRelay);
                correctionXMinus[i] = guideLog.GetLogValue(i, LogReader.LogVal.XMinusRelay);
                correctionYPlus[i]  = guideLog.GetLogValue(i, LogReader.LogVal.XPlusRelay);
                correctionYMinus[i] = guideLog.GetLogValue(i, LogReader.LogVal.YMinusRelay);
                wormIndexRA[i]      = guideLog.GetLogValue(i, LogReader.LogVal.PECIndexRA);
                wormIndexDec[i]     = guideLog.GetLogValue(i, LogReader.LogVal.PECIndexDec);
                guideStarSignal[i]  = guideLog.GetLogValue(i, LogReader.LogVal.GuideStarSignal);
            }

            if (RemoveDriftCheckBox.Checked)
            {
                tSlope = Analysis.RemoveOffsetAndSlope(ref errorValsTdbl, false);
                xSlope = Analysis.RemoveOffsetAndSlope(ref errorValsXdbl, false);
                ySlope = Analysis.RemoveOffsetAndSlope(ref errorValsYdbl, false);
            }
            else
            {
                tSlope = Analysis.RemoveOffsetAndSlope(ref errorValsTdbl, true); //Slope only
                xSlope = Analysis.RemoveOffsetAndSlope(ref errorValsXdbl, true); //Slope only
                ySlope = Analysis.RemoveOffsetAndSlope(ref errorValsYdbl, true); //Slope only
            }

            for (int i = 0; i < vLen; i++)
            {
                errorValsTcplx[i] = new Complex(errorValsTdbl[i], 0);
                errorValsXcplx[i] = new Complex(errorValsXdbl[i], 0);
                errorValsYcplx[i] = new Complex(errorValsYdbl[i], 0);
            }


            for (int i = 0; i < vLen; i++)
            {
                nowTime = guideLog.GetLogValue(i, LogReader.LogVal.ElapsedSecs);
                if (i < (vLen - 1))
                {
                    FFTTimeIncrement += guideLog.GetLogValue(i + 1, LogReader.LogVal.ElapsedSecs) - nowTime;
                }
                tGraphT.Points.AddXY((nowTime / 60), errorValsTcplx[i].Real);
                tGraphX.Points.AddXY((nowTime / 60), errorValsXcplx[i].Real);
                tGraphY.Points.AddXY((nowTime / 60), errorValsYcplx[i].Real);
            }
            tGraphT.Color = Color.Red;
            tGraphX.Color = Color.Blue;
            tGraphY.Color = Color.Green;

            Show();
            //Determine if wormIndex data is present and post results
            double pesum = 0;

            for (int i = 0; i < vLen; i++)
            {
                pesum += (wormIndexDec[i] + wormIndexRA[i]);
            }
            if (pesum == 0)
            {
                PEIndexTextBox.Text = "No";
            }
            else
            {
                PEIndexTextBox.Text = "Yes";
            }

            //frequency domain plot of log data, long period and short period
            FourierTransform.DFT(errorValsTcplx, FourierTransform.Direction.Forward);
            FourierTransform.DFT(errorValsXcplx, FourierTransform.Direction.Forward);
            FourierTransform.DFT(errorValsYcplx, FourierTransform.Direction.Forward);
            //
            int FFTLen = errorValsTcplx.Length;

            FFTTimeIncrement /= (vLen - 1);
            double FFTSampleRate = 1 / FFTTimeIncrement; //frequency increment per sample in cycles/sec

            SampleRateBox.Text = FFTTimeIncrement.ToString("00.00") + " (sec) / " + FFTSampleRate.ToString("0.00") + " (cps)";
            double FFTmagT   = 0;
            double FFTmagX   = 0;
            double FFTmagY   = 0;
            double FFTperiod = 0;
            //double maxFreq = FFTFreqIncrement * (FFTLen / 2);
            int    maxLongPeriod  = 6;  //minutes
            double maxShortPeriod = .5; //minutes

            double[,] errorFreq = new double[FFTLen / 2, 3];

            for (int i = 1; i < (FFTLen / 2); i++)
            {
                //fGraph.Points.Add(XPlusVals[i].Real);
                //FFTmagT = Math.Pow(errorValsTcplx[i].Real, 2) + Math.Pow(errorValsTcplx[i].Imaginary, 2);
                //FFTmagX = Math.Pow(errorValsXcplx[i].Real, 2) + Math.Pow(errorValsTcplx[i].Imaginary, 2);
                //FFTmagY = Math.Pow(errorValsYcplx[i].Real, 2) + Math.Pow(errorValsTcplx[i].Imaginary, 2);

                FFTmagT = errorValsTcplx[i].Magnitude;
                FFTmagX = errorValsXcplx[i].Magnitude;
                FFTmagY = errorValsYcplx[i].Magnitude;

                errorFreq[i, 0] = FFTmagT;
                errorFreq[i, 1] = FFTmagX;
                errorFreq[i, 2] = FFTmagY;

                FFTperiod = FFTLen / (i * FFTSampleRate * 60);
                if (FFTperiod <= maxLongPeriod)
                {
                    fGraphT.Points.AddXY(FFTperiod, FFTmagT);
                    fGraphX.Points.AddXY(FFTperiod, FFTmagX);
                    fGraphY.Points.AddXY(FFTperiod, FFTmagY);
                    fGraphT.Color = Color.Red;
                    fGraphX.Color = Color.Blue;
                    fGraphY.Color = Color.Green;
                }
                if (FFTperiod <= maxShortPeriod)
                {
                    mGraphT.Points.AddXY((FFTperiod * 60), FFTmagT);
                    mGraphX.Points.AddXY((FFTperiod * 60), FFTmagX);
                    mGraphY.Points.AddXY((FFTperiod * 60), FFTmagY);
                    mGraphT.Color = Color.Red;
                    mGraphX.Color = Color.Blue;
                    mGraphY.Color = Color.Green;
                }
            }
            //Calibration Plot
            double xpAngle = guideLog.GetMountVelocityVector(LogReader.Calibration.XPlus, LogReader.Vector.Angle);
            double xmAngle = guideLog.GetMountVelocityVector(LogReader.Calibration.XMinus, LogReader.Vector.Angle);
            double ypAngle = guideLog.GetMountVelocityVector(LogReader.Calibration.YPlus, LogReader.Vector.Angle);
            double ymAngle = guideLog.GetMountVelocityVector(LogReader.Calibration.YMinus, LogReader.Vector.Angle);
            double xpSpeed = Math.Abs(guideLog.GetMountVelocityVector(LogReader.Calibration.XPlus, LogReader.Vector.XSpeed));
            double xmSpeed = Math.Abs(guideLog.GetMountVelocityVector(LogReader.Calibration.XMinus, LogReader.Vector.XSpeed));
            double ypSpeed = Math.Abs(guideLog.GetMountVelocityVector(LogReader.Calibration.YPlus, LogReader.Vector.YSpeed));
            double ymSpeed = Math.Abs(guideLog.GetMountVelocityVector(LogReader.Calibration.YMinus, LogReader.Vector.YSpeed));

            cGraphPX.Points.Add(0, 0);
            cGraphPX.Points.AddXY(xpAngle, xpSpeed);
            cGraphPX.Points[cGraphPX.Points.Count - 1].MarkerStyle = MarkerStyle.Cross;
            cGraphPX.Points.Add(0, 0);
            cGraphPX.Points.AddXY(xmAngle, xmSpeed);
            cGraphPX.Points[cGraphPX.Points.Count - 1].MarkerStyle = MarkerStyle.Circle;
            cGraphPY.Points.Add(0, 0);
            cGraphPY.Points.AddXY(ypAngle, ypSpeed);
            cGraphPY.Points[cGraphPY.Points.Count - 1].MarkerStyle = MarkerStyle.Cross;
            cGraphPY.Points.Add(0, 0);
            cGraphPY.Points.AddXY(ymAngle, ymSpeed);
            cGraphPY.Points[cGraphPY.Points.Count - 1].MarkerStyle = MarkerStyle.Circle;

            foreach (System.Windows.Forms.DataVisualization.Charting.DataPoint point in cGraphPX.Points)
            {
                if ((double)point.YValues.GetValue(0) == 0)
                {
                    point.IsValueShownAsLabel = false;
                    point.MarkerStyle         = MarkerStyle.None;
                }
                else
                {
                    point.IsValueShownAsLabel = true;
                }
            }

            foreach (System.Windows.Forms.DataVisualization.Charting.DataPoint point in cGraphPY.Points)
            {
                if ((double)point.YValues.GetValue(0) == 0)
                {
                    point.IsValueShownAsLabel = false;
                    point.MarkerStyle         = MarkerStyle.None;
                }
                else
                {
                    point.IsValueShownAsLabel = true;
                }
            }
            //Add vertical lines for Paramount
            ChartArea CA      = chart2.ChartAreas[0];
            double    hPeriod = 0;

            if (MountBox.Text.Contains("MX"))
            {
                hPeriod = 229.77;
            }
            else if (MountBox.Text.Contains("MYT"))
            {
                hPeriod = 269.26;
            }
            else if (MountBox.Text.Contains("ME"))
            {
                hPeriod = 149.99;
            }

            if (hPeriod != 0)
            {
                chart2.Annotations.Clear();

                double harmonic0 = hPeriod / 60;
                double harmonic1 = harmonic0 / 2;
                double harmonic2 = harmonic0 / 3;
                double harmonic3 = harmonic0 / 4;
                double harmonic4 = harmonic0 / 5;
                double harmonic5 = harmonic0 / 6;
                double harmonic6 = harmonic0 / 7;
                double harmonic7 = harmonic0 / 8;


                VerticalLineAnnotation VA0 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine0",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,
                    X = harmonic0
                };
                VerticalLineAnnotation VA1 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine1",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,
                    X = harmonic1
                };
                VerticalLineAnnotation VA2 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine2",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,
                    X = harmonic2
                };
                VerticalLineAnnotation VA3 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine3",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,   // use your numbers!
                    X = harmonic3
                };
                VerticalLineAnnotation VA4 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine4",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,   // use your numbers!
                    X = harmonic4
                };
                VerticalLineAnnotation VA5 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine5",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,   // use your numbers!
                    X = harmonic5
                };
                VerticalLineAnnotation VA6 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine6",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,   // use your numbers!
                    X = harmonic6
                };

                VerticalLineAnnotation VA7 = new VerticalLineAnnotation
                {
                    AxisX           = CA.AxisX,
                    AllowMoving     = false,
                    IsInfinitive    = true,
                    ClipToChartArea = CA.Name,
                    Name            = "myLine7",
                    LineColor       = Color.DarkOrange,
                    LineWidth       = 2,   // use your numbers!
                    X = harmonic7
                };

                chart2.Annotations.Add(VA0);
                chart2.Annotations.Add(VA1);
                chart2.Annotations.Add(VA2);
                chart2.Annotations.Add(VA3);
                chart2.Annotations.Add(VA4);
                chart2.Annotations.Add(VA5);
                chart2.Annotations.Add(VA6);
                chart2.Annotations.Add(VA7);
            }

            Show();

            //Determine the percentage of saturated star observations
            double percentSat  = Analysis.PercentSaturated(guideStarSignal);
            double percentLost = Analysis.PercentLost(guideStarSignal);

            SaturatedTextBox.Text = percentSat.ToString("0.0") + "% / " + percentLost.ToString("0.0") + "%";

            //Determine percentage of moves vrs non-moves in X and Y
            double movePointsXPlus  = Analysis.PercentErrorsCorrected(correctionXPlus);
            double movePointsXMinus = Analysis.PercentErrorsCorrected(correctionXMinus);
            double movePointsYPlus  = Analysis.PercentErrorsCorrected(correctionYPlus);
            double movePointsYMinus = Analysis.PercentErrorsCorrected(correctionYMinus);

            CorrectionEachPercentBox.Text = movePointsXPlus.ToString("0") + "% / " +
                                            movePointsXMinus.ToString("0") + "% / " +
                                            movePointsYPlus.ToString("0") + "% / " +
                                            movePointsYMinus.ToString("0") + "%";
            double movePointsX = Analysis.PercentErrorsCorrected(correctionXPlus, correctionXMinus);
            double movePointsY = Analysis.PercentErrorsCorrected(correctionYPlus, correctionYMinus);

            CorrectionXorYPercentBox.Text = movePointsX.ToString("0") + "% / " + movePointsY.ToString("0") + "%";
            double movePoints = Analysis.PercentErrorsCorrected(correctionXPlus, correctionXMinus, correctionYPlus, correctionYMinus);

            CorrectionXandYPercentBox.Text = movePoints.ToString("0") + "%";
            Show();

            double switchBackX = Analysis.PercentSwitchBacks(correctionXPlus, correctionXMinus);
            double switchBackY = Analysis.PercentSwitchBacks(correctionYPlus, correctionYMinus);

            SwitchBackPercentBox.Text = switchBackX.ToString("0") + "% / " + switchBackY.ToString("0") + "%";
            Show();

            double TrackingX = Analysis.PercentTracking(correctionXPlus, correctionXMinus);
            double TrackingY = Analysis.PercentTracking(correctionYPlus, correctionYMinus);

            TrackingPercentBox.Text = TrackingX.ToString("0") + "% / " + TrackingY.ToString("0") + "%";
            Show();

            double overshootX = Analysis.PercentOvershoot(errorValsXdbl);
            double overshootY = Analysis.PercentOvershoot(errorValsYdbl);

            OvershootPercentBox.Text = overshootX.ToString("0") + "% / " + overshootY.ToString("0") + "%";
            Show();

            double[] RMSStats = Analysis.RMSError(errorValsXdbl, errorValsYdbl, errorValsTdbl);
            ErrorRMSBox.Text = RMSStats[0].ToString("0.0") + " / " + RMSStats[1].ToString("0.0") + " / " + RMSStats[2].ToString("0.0");
            Show();

            double[] mdrStats = Analysis.MDRStats(errorValsXcplx, errorValsYcplx, errorValsTcplx, FFTSampleRate);
            //double sigToNoiseAvg = (mdrStats[0] - mdrStats[1]) / mdrStats[1];
            MDRBox.Text = (mdrStats[2] * 100).ToString("0") + " %";

            double[] FreqMedStats = Analysis.FrequencyMedian(errorFreq);
            double   iToF         = FFTSampleRate / FFTLen;

            FrequencyBalanceBox.Text = (1 / (iToF * FreqMedStats[0])).ToString("0") + " sec / " + (1 / (iToF * FreqMedStats[1])).ToString("0") + " sec";

            AvgDriftTextBox.Text = (xSlope * 60.0 / FFTTimeIncrement).ToString("0.0") + " / " + (ySlope * 60.0 / FFTTimeIncrement).ToString("0.0") + " / " + (tSlope * 60.0 / FFTTimeIncrement).ToString("0.0");


            Show();
        }
Beispiel #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            functionXValues.Clear();
            functionYValues.Clear();

            spectrumXValues.Clear();
            spectrumYValues.Clear();

            movementXValues.Clear();
            movementYValues.Clear();

            this.MouseWheel += new MouseEventHandler(chart1_MouseWheel);

            dynamic funcScript = CSScript.Evaluator.LoadMethod(@"double func(double t)
                                                           {" + functionScript + "}");

            double func(double t)
            {
                return(4 * Math.Sin(2 * Math.PI * t) * Math.Sin(2 * Math.PI * t));
                //return 10 * Math.Sin(200 * Math.PI * t) + 10 * Math.Sin(800 * Math.PI * t) + 10 * Math.Sin(2000 * Math.PI * t);
                //return 10 * Math.Sin(100 * t) + 10 * Math.Sin(400 * t) + 10 * Math.Sin(1000 * t);

                /*
                 * if(Math.Sin(t * Math.PI * 2) > 0)
                 * {
                 *  return 1;
                 * }
                 * else
                 * {
                 *  return -1;
                 * }
                 */

                //return 10 * Math.Sin(t * Math.PI * 200);
            }

            //FOURIER

            dynamic funcPeriodScript = CSScript.Evaluator.LoadMethod(@"double period()
                                                                     {" + functionPeriod + "}");

            double       period    = funcPeriodScript.period();
            const double intervals = 2;
            const int    howMany   = 2048;


            Complex[] data = new Complex[howMany];

            for (int i = 0; i < howMany; ++i)
            {
                double functionResult = funcScript.func(period * intervals * (i / Convert.ToDouble(howMany)));
                data[i] = new Complex(functionResult, 0);
            }

            for (double i = period / 100.0; i < period * intervals; i += period / 100.0)
            {
                functionYValues.Add(funcScript.func(i));
                functionXValues.Add(i);
            }

            FourierTransform.DFT(data, FourierTransform.Direction.Forward);

            double[] bins = new double[howMany];

            double maxBin = 0;

            for (int i = 0; i < howMany; ++i)
            {
                bins[i] = Math.Sqrt(data[i].Re * data[i].Re + data[i].Im * data[i].Im);

                if (bins[i] > maxBin)
                {
                    maxBin = bins[i];
                }
            }

            double sr = howMany / (period * intervals);

            for (int i = 0; i < maxXInterval; ++i)
            {
                movementYValues.Add(Math.Atan2(data[i].Re, data[i].Im));
                movementXValues.Add((double)i * sr / howMany);

                spectrumYValues.Add(bins[i] * 2);
                spectrumXValues.Add((double)i * sr / howMany);
            }

            Spectrum.Series["Transformation"].Points.DataBindXY(spectrumXValues, spectrumYValues);
            FunctionChart.Series["Function"].Points.DataBindXY(functionXValues, functionYValues);
            chart1.Series["Movement"].Points.DataBindXY(movementXValues, movementYValues);
        }
Beispiel #11
0
        private void DoFourier(List <double> Data, out List <Wave> Waves, out double[] TimeVector)
        {
            int n = (int)Math.Floor(Data.Count * _zeroPaddingFactor);

            Complex[] timeDomainSignal    = new Complex[n];
            Complex[] freqDomainTransform = new Complex[n];

            int index     = 0;
            int dataIndex = 0;

            for (; index < Data.Count; index++, dataIndex++)
            {
                timeDomainSignal[index].Re    = Data[dataIndex] * _window.ValueAt(n, dataIndex);
                freqDomainTransform[index].Re = timeDomainSignal[index].Re;
            }

            for (; index < (n - Data.Count); index++)
            {
                timeDomainSignal[index].Re    = 0.0;
                freqDomainTransform[index].Re = 0.0;
            }

            TimeVector = new double[(int)Math.Floor(n * _zeroPaddingFactor)];
            for (int i = 0; i < n; i++)
            {
                TimeVector[i] = (double)i / (double)_zeroPaddingFactor;
            }

            switch (_fourierType)
            {
            case FourierType.DFT:
                FourierTransform.DFT(freqDomainTransform, FourierTransform.Direction.Forward);
                break;

            case FourierType.FFT:
            case FourierType.NotSet:
            default:
                FourierTransform.FFT(freqDomainTransform, FourierTransform.Direction.Forward);
                break;
            }



            // nyquist frequency
            int cutOff = (int)Math.Ceiling(n / (double)2);

            // FFT is symmetric, take first half
            Complex[] y1 = new Complex[cutOff];
            for (int i = 0; i < cutOff; i++)
            {
                y1[i] = freqDomainTransform[i];
            }

            // compensate for the energy of the other half
            for (int i = 1; i < cutOff - 1; i++)
            {
                y1[i] = y1[i] * 2;
            }

            double[] p = new double[cutOff];
            for (int i = 0; i < cutOff; i++)
            {
                double phase = Math.Atan2(y1[i].Im, y1[i].Re);
                if (i != 0)
                {
                    if (Math.Abs(p[i - 1] - phase) > Math.PI)
                    {
                        phase = (phase > p[i - 1]) ? phase - (2 * Math.PI) : phase + (2 * Math.PI);   // unwrap
                    }
                }
                p[i] = phase;
            }

            double[] f = new double[n];             // Frequency vector
            int fIndex = 0;
            for (double i = 0; fIndex < n; i += _samplingFrequency / (double)(n - 1))
            {
                f[fIndex] = i;
                fIndex++;
            }

#if DEBUG
            StringBuilder sbPlot = new StringBuilder();
            sbPlot.AppendLine(String.Format("{0},{1},{2},{3},{4}", "Time", "Amplitude", "Frequency", "Magnitude", "Phase (rad)"));

            for (int i = 0; i < n; i++)
            {
                sbPlot.AppendLine(String.Format("{0},{1},{2},{3},{4}",
                                                TimeVector[i],
                                                timeDomainSignal[i].Re,
                                                (i < cutOff) ? Convert.ToString(f[i]) : "",
                                                (i < cutOff) ? Convert.ToString(Math.Sqrt(Math.Pow(y1[i].Re, 2) + Math.Pow(y1[i].Im, 2))) : "",
                                                (i < cutOff) ? Convert.ToString(p[i]) : ""));
            }
#endif

            Waves = new List <Wave>();
            for (int i = 0; i < cutOff; i++)
            {
                Wave wave = new Wave(WaveType.Cosine);
                wave.Frequency = f[i];
                wave.Magnitude = Math.Sqrt(Math.Pow(y1[i].Re, 2) + Math.Pow(y1[i].Im, 2));
                wave.Phase     = p[i];
                Waves.Add(wave);
            }

            Waves.Sort(new WaveComparer(true));
        }
        private void btnCalculate_Click(object sender, EventArgs e)
        {
            double ka = (double)nudFWHM.Value;

            // remove all computed curves
            mDeconvolutedSpectra.Clear();
            mFourierTransforms.Clear();
            mModifiedFourierTransforms.Clear();
            mFittingCurves.Clear();



            foreach (var experimentalSpectrum in mSpectra)
            {
                // define cutoff position using narrowing factor
                int cutoffPosition = (int)(experimentalSpectrum.mAbsoluteIntensities.Value.Length / (double)nudNarrowingFactor.Value);

                // absolute intensities alias
                var spectrum = experimentalSpectrum.mAbsoluteIntensities.Value;

                // copy spectrum absolute intensities into array of complex numbers
                Complex[] cdata = new Complex[spectrum.Length];
                for (int i = 0; i < spectrum.Length; ++i)
                {
                    cdata[i] = spectrum[i];
                }

                // do inverse fourier transform to go to time domain
                FourierTransform.DFT(cdata, FourierTransform.Direction.Backward);

                // add inverse fourier transform plot to the fourier chart
                var fourierTransform = new RawSpectrum();
                for (int i = 0; i < spectrum.Length; ++i)
                {
                    fourierTransform.mAbsoluteIntensities.Add(cdata[i].Real);
                    fourierTransform.mWavelengths.Add(i);
                }
                mFourierTransforms.Add(fourierTransform);

                // deconvolve exponential decay
                for (int i = 0; i < spectrum.Length; ++i)
                {
                    cdata[i] /= ExponentialDeconvolution(cutoffPosition * ka, i);
                }

                // apply apodization function
                double constantScaler = 2.0f;
                for (int i = 0; i < spectrum.Length; ++i)
                {
                    double a = Apodization(cutoffPosition, i);
                    cdata[i] *= a * a * constantScaler;
                }

                // add modified fourier transform plot to the fourier chart
                var modifiedFourierTransform = new RawSpectrum();
                for (int i = 0; i < spectrum.Length; ++i)
                {
                    modifiedFourierTransform.mAbsoluteIntensities.Add(cdata[i].Real);
                    modifiedFourierTransform.mWavelengths.Add(i);
                }
                mModifiedFourierTransforms.Add(modifiedFourierTransform);

                // do forward fourier transform to go back to frequency domain
                FourierTransform.DFT(cdata, FourierTransform.Direction.Forward);

                // add deconvolved spectrum to the chart
                var deconvolution = new RawSpectrum();
                for (int i = 0; i < spectrum.Length; ++i)
                {
                    deconvolution.mAbsoluteIntensities.Add(cdata[i].Real);
                    deconvolution.mWavelengths.Add(experimentalSpectrum.mWaveLengths.Value[i]);
                }
                mDeconvolutedSpectra.Add(deconvolution);
            }
            UpdateChart();
        }
        public bool Run()
        {
            Report = "";
            DateTime from = new DateTime(DateTime.Now.Ticks);

            SpectrCondition cond = new SpectrCondition(Common.Dev.Tick,
                                                       SpectrCondition.GetDefaultCondition(false, false, 0.1F, 0.1F, 20));

            int[] ss = Common.Dev.Reg.GetSensorSizes();
            do
            {
                Common.Dev.Measuring(cond, null);


                for (int s = 0; s < ss.Length; s++)
                {
                    for (int sh = 0; sh < Common.Dev.LetestResult.Count; sh++)
                    {
                        float[]   dt  = Common.Dev.LetestResult[sh].GetFullData()[s];
                        Complex[] cdt = new Complex[dt.Length];
                        for (int i = 0; i < dt.Length; i++)
                        {
                            cdt[i] = new Complex(dt[i]);
                        }
                        FourierTransform.DFT(cdt, FourierTransform.Direction.Forward);
                        double max     = cdt[0].Length;
                        int    max_ind = 0;
                        for (int i = 1; i < dt.Length / 2 - 1; i++)
                        {
                            if (max < cdt[i].Length)
                            {
                                max     = cdt[i].Length;
                                max_ind = i;
                            }
                        }
                        if (max_ind > 0)
                        {
                            Report = "Found garmonic with period " + cdt.Length / max_ind +
                                     " pixels on sensor " + s + " and exposition " + sh + serv.Endl;
                        }
                    }

                    for (int p = 0; p < ss[s]; p++)
                    {
                        double[] data = new double[Common.Dev.LetestResult.Count];
                        for (int sh = 0; sh < Common.Dev.LetestResult.Count; sh++)
                        {
                            data[sh] = Common.Dev.LetestResult[sh].GetFullDataNoClone()[s][p];
                        }
                        double ever = 0;
                        for (int i = 0; i < data.Length; i++)
                        {
                            ever += data[i];
                        }
                        ever /= data.Length;
                        double dlt = 0;
                        for (int i = 0; i < data.Length; i++)
                        {
                            dlt += Math.Sqrt(Math.Abs(data[i] - ever));
                        }
                        dlt *= dlt;
                        dlt /= data.Length;
                        dlt *= (int)nmStep.Value;
                        for (int i = 0; i < data.Length && Report.Length < 4000; i++)
                        {
                            if (Math.Abs(ever - data[i]) > dlt)
                            {
                                Report += "Splash found at " + (i) + " on data [";
                                for (int j = 0; j < data.Length; j++)
                                {
                                    if (i != j)
                                    {
                                        Report += " " + data[j] + " ";
                                    }
                                    else
                                    {
                                        Report += "!" + data[j] + "!";
                                    }
                                }
                                Report += "]" + serv.Endl;
                            }
                        }
                    }
                }
            } while ((DateTime.Now.Ticks - from.Ticks) / 10000000 < nmTimeOut.Value && Report.Length == 0);

            Spectr sp = new Spectr(cond, Common.Env.DefaultDisp, Common.Env.DefaultOpticFk, "RundomSplashTest");

            for (int i = 0; i < Common.Dev.LetestResult.Count; i++)
            {
                sp.Add(Common.Dev.LetestResult[i]);
            }

            sp.SaveAs(Common.DbNameSienceSensFolder + "\\null_noise_test");
            spView.ClearSpectrList();
            spView.AddSpectr(sp, "");
            if (Report.Length == 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }//*/