Example #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();
        }
Example #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);
        }
Example #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            var cs        = _transformedSource.Select(p => new Complex(p.Y, 0)).ToList().GetRange(0, 512).ToArray();
            var transform = FourierTransformer.FFT(cs, false);
            var allHarms  = FourierTransformer.FFT(transform, true);


            chart2.DataSource = allHarms.Select((c, index) => new SignalPoint {
                X = 1.0 * index / 360, Y = c.Real
            }).ToList();
            chart2.Series[0].XValueMember  = "X";
            chart2.Series[0].YValueMembers = "Y";
            chart2.DataBind();

            for (int i = High; i < transform.Length - High; i++)
            {
                transform[i] = transform[i] = 0;
            }
            var resultHigh = FourierTransformer.FFT(transform, true);

            chart3.DataSource = resultHigh.Select((c, index) => new SignalPoint {
                X = 1.0 * index / 360, Y = c.Real
            }).ToList();;
            chart3.Series[0].XValueMember  = "X";
            chart3.Series[0].YValueMembers = "Y";
            chart3.DataBind();


            for (int i = Low; i < transform.Length - Low; i++)
            {
                transform[i] = transform[i] = 0;
            }
            var resultLow = FourierTransformer.FFT(transform, true);

            chart4.DataSource = resultLow.Select((c, index) => new SignalPoint {
                X = 1.0 * index / 360, Y = c.Real
            }).ToList();;
            chart4.Series[0].XValueMember  = "X";
            chart4.Series[0].YValueMembers = "Y";
            chart4.DataBind();
        }