Exemple #1
0
        private void button4_Click(object sender, EventArgs e)
        {
            int       p         = (int)Math.Floor(Math.Log(_transformedSource.Count, 2));
            var       range     = _transformedSource.GetRange(0, (int)Math.Pow(2, p));
            var       signalCut = range.Select(pt => new Complex(pt.Y, 0)).ToArray();
            Stopwatch sw        = new Stopwatch();

            sw.Start();
            var transform = FourierTransformer.FFT(signalCut, false);

            sw.Stop();
            TimeSpan timeSpan = sw.Elapsed;

            label1.Text = string.Format("Time: {0}m {1}s {2}ms", timeSpan.Minutes, timeSpan.Seconds, timeSpan.Milliseconds);

            var fft = FourierTransformer.CalculateSpecs(transform);

            sourceChart.DataSource = range;
            sourceChart.DataBind();

            ampSpec.DataSource                = fft.amplitudeSpec.GetRange(0, fft.amplitudeSpec.Count / 2);
            ampSpec.Series[0].XValueMember    = "X";
            ampSpec.Series[0].YValueMembers   = "Y";
            ampSpec.ChartAreas[0].AxisX.Title = "Гц";
            ampSpec.DataBind();


            phaseSpec.DataSource                = fft.phaseSpec.GetRange(0, fft.phaseSpec.Count / 2);
            phaseSpec.Series[0].XValueMember    = "X";
            phaseSpec.Series[0].YValueMembers   = "Y";
            phaseSpec.ChartAreas[0].AxisX.Title = "Гц";
            phaseSpec.DataBind();
        }
Exemple #2
0
        public static (double[] result, double[] simpleAFC, double[] dbAFC) CalculateAFC(double fc, int N, WindowType window)
        {
            double[] testSignal = new double[1 << 13];
            testSignal[0] = 1;
            double[] resultSignal = ApplyLowFilter(testSignal, fc, N, window);

            var fft = FourierTransformer.FFT(resultSignal.Select(d => new Complex(d, 0)).ToArray(), false);

            var afc = FourierTransformer.CalculateSpecs(fft);

            var db = afc.amplitudeSpec.Select(d => 20 * Log10(d.Y)).ToArray();

            return(resultSignal, afc.amplitudeSpec.Select(p => p.Y).ToArray(), db);
        }