Ejemplo n.º 1
0
        /// <summary>
        /// Constructor with necessary parameters
        /// </summary>
        /// <param name="windowSize">Size of window</param>
        /// <param name="hopSize">Hop (overlap) size</param>
        /// <param name="window">Type of the window function to apply</param>
        /// <param name="fftSize">Size of FFT</param>
        public Stft(int windowSize = 1024, int hopSize = 256, WindowTypes window = WindowTypes.Hann, int fftSize = 0)
        {
            _fftSize = fftSize >= windowSize ? fftSize : MathUtils.NextPowerOfTwo(windowSize);
            _fft     = new RealFft(_fftSize);

            _hopSize       = hopSize;
            _windowSize    = windowSize;
            _window        = window;
            _windowSamples = Window.OfType(_window, _windowSize);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs Mellin transformer.
        /// Parameter <paramref name="size"/> must be a power of 2.
        /// </summary>
        /// <param name="inputSize">Expected size of input data</param>
        /// <param name="size">Size of output data</param>
        /// <param name="beta">Beta coefficient (0.5 by default, which corresponds to Scale transform)</param>
        public MellinTransform(int inputSize, int size, double beta = 0.5)
        {
            Guard.AgainstNotPowerOfTwo(size, "Output size of Mellin Transform");

            InputSize = inputSize;
            Size      = size;

            _beta = beta;
            _fft  = new RealFft(size);

            _linScale = Enumerable.Range(0, inputSize)
                        .Select(i => (float)i / inputSize)
                        .ToArray();

            _expScale = new float[size];

            var cur  = -(float)Math.Log(size);
            var step = -cur / size;

            for (var i = 0; i < _expScale.Length; i++, cur += step)
            {
                _expScale[i] = (float)Math.Exp(cur);
            }
        }