コード例 #1
0
 public SampleAggregator(int fftLength)
 {
     if (!IsPowerOfTwo(fftLength))
     {
         throw new ArgumentException("FFT Length must be a power of two");
     }
     this.m         = (int)Math.Log(fftLength, 2.0);
     this.fftLength = fftLength;
     this.fftBuffer = new Complex[fftLength];
     this.fftArgs   = new FftEventArgs(fftBuffer);
 }
コード例 #2
0
        private void FftCalculated(object sender, FftEventArgs e)
        {
            Graphics gr       = Graphics.FromImage(bitmap);
            int      halfPlot = e.Result.Length / 2;

            for (int i = 0; i < halfPlot; i++)
            {
                double mX = e.Result[i].X;
                double mY = e.Result[i].Y;

                double magnitude = Math.Sqrt(mX * mX + mY * mY);
                float  dbs       = 20 * (float)Math.Log(magnitude, 10);

                float wM = map(i, 0, halfPlot, 0, picW);

                gr.FillRectangle(SystemBrushes.Control, wM - 1, 0, 2, picH);
                if (dbs > -90f)
                {
                    if (dbs < maxDb)
                    {
                        maxDb = dbs;
                    }
                    if (dbs > minDb)
                    {
                        minDb = dbs;
                    }

                    serial_buffer[(int)map(i, 0, halfPlot, 0, config.cols)] = (byte)map(dbs, maxDb, minDb, 0, config.rows);

                    var y      = map(dbs, minDb, maxDb, 0, picH);
                    var height = picH - y;
                    gr.FillRectangle(Brushes.Black, wM - 1, y, 2, height);
                }
            }
            pictureBox1.Image = bitmap;
        }