Ejemplo n.º 1
0
            public Bitmap Draw(double[] samples)
            {
                int width  = samples.Length / _nfft;
                int height = _nfft / 2;
                var bmp    = new FastBitmap(new Bitmap(width, height));

                bmp.LockImage();
                for (int x = 0; x < width; x++)
                {
                    // read a segment of the recorded signal
                    for (int i = 0; i < _nfft; i++)
                    {
                        _segment[i] = samples[x * _nfft + i] * _window[i];
                    }

                    // transform to the frequency domain
                    _fft.ComputeForward(_segment);

                    // compute the magnitude of the spectrum
                    MagnitudeSpectrum(_segment, _magnitude);

                    // draw
                    for (int y = 0; y < height; y++)
                    {
                        int colorIndex = _mapper.Map(_magnitude[y]);
                        bmp.SetPixel(x, height - y - 1, _palette[colorIndex]);
                    }
                }
                bmp.UnlockImage();
                return(bmp.GetBitmap());
            }
Ejemplo n.º 2
0
            public Bitmap Draw(double[] samples)
            {
                int width  = samples.Length / _nfft;
                int height = _nfft / 2;
                var bmp    = new FastBitmap(new Bitmap(width, height));

                bmp.LockImage();
                for (int x = 0; x < width; x++)
                {
                    // process 2 segments offset by -1/4 and 1/4 fft size, resulting in 1/2 fft size
                    // window spacing (the minimum overlap to avoid discarding parts of the signal)
                    ProcessSegment(samples, (x * _nfft) - (x > 0 ? _nfft / 4 : 0), _magnitude1);
                    ProcessSegment(samples, (x * _nfft) + (x < width - 1 ? _nfft / 4 : 0), _magnitude2);

                    // draw
                    for (int y = 0; y < height; y++)
                    {
                        int colorIndex = _mapper.Map((_magnitude1[y] + _magnitude2[y]) / 2.0);
                        bmp.SetPixel(x, height - y - 1, _palette[colorIndex]);
                    }
                }
                bmp.UnlockImage();
                return(bmp.GetBitmap());
            }
Ejemplo n.º 3
0
            public Bitmap Draw(double[] samples)
            {
                int width = samples.Length / _nfft;
                int height = _nfft / 2;
                var bmp = new FastBitmap(new Bitmap(width, height));
                bmp.LockImage();
                for (int x = 0; x < width; x++)
                {
                    // process 2 segments offset by -1/4 and 1/4 fft size, resulting in 1/2 fft size
                    // window spacing (the minimum overlap to avoid discarding parts of the signal)
                    ProcessSegment(samples, (x * _nfft) - (x > 0 ? _nfft / 4 : 0), _magnitude1);
                    ProcessSegment(samples, (x * _nfft) + (x < width - 1 ? _nfft / 4 : 0), _magnitude2);

                    // draw
                    for (int y = 0; y < height; y++)
                    {
                        int colorIndex = _mapper.Map((_magnitude1[y] + _magnitude2[y]) / 2.0);
                        bmp.SetPixel(x, height - y - 1, _palette[colorIndex]);
                    }
                }
                bmp.UnlockImage();
                return bmp.GetBitmap();
            }
Ejemplo n.º 4
0
            public Bitmap Draw(double[] samples)
            {
                int width = samples.Length / _nfft;
                int height = _nfft / 2;
                var bmp = new FastBitmap(new Bitmap(width, height));
                bmp.LockImage();
                for (int x = 0; x < width; x++)
                {
                    // read a segment of the recorded signal
                    for (int i = 0; i < _nfft; i++)
                    {
                        _segment[i] = samples[x * _nfft + i] * _window[i];
                    }

                    // transform to the frequency domain
                    _fft.ComputeForward(_segment);

                    // compute the magnitude of the spectrum
                    MagnitudeSpectrum(_segment, _magnitude);

                    // draw
                    for (int y = 0; y < height; y++)
                    {
                        int colorIndex = _mapper.Map(_magnitude[y]);
                        bmp.SetPixel(x, height - y - 1, _palette[colorIndex]);
                    }
                }
                bmp.UnlockImage();
                return bmp.GetBitmap();
            }