dB() публичный статический Метод

public static dB ( double gain ) : double
gain double
Результат double
Пример #1
0
        /// <summary>
        /// Standard deviation in dB of all samples in buffer
        /// </summary>
        /// <returns></returns>
        public ISample StdDevDb()
        {
            if (_stddevdB != null)
            {
                return(_stddevdB);
            }
            ISample meandb = MeanDb();
            ushort  nc     = _input.NumChannels;

            _stddevdB = new Sample(nc);
            for (int n = 0; n < _length; n++)
            {
                if (_data[n] != null)
                {
                    for (ushort c = 0; c < nc; c++)
                    {
                        double devdb = (MathUtil.dB(_data[n][c]) - meandb[c]);
                        _stddevdB[c] += (devdb * devdb);
                    }
                }
            }
            for (ushort c = 0; c < nc; c++)
            {
                _stddevdB[c] = Math.Sqrt(_stddevdB[c] / _length);
            }
            return(_stddevdB);
        }
Пример #2
0
        /// <summary>
        /// "Average" - arithmetical mean of dB value of all samples in buffer
        /// </summary>
        /// <returns></returns>
        public ISample MeanDb()
        {
            if (_meandB != null)
            {
                return(_meandB);
            }
            ushort nc = _input.NumChannels;

            _meandB = new Sample(nc);
            for (int n = 0; n < _length; n++)
            {
                if (_data[n] != null)
                {
                    for (ushort c = 0; c < nc; c++)
                    {
                        _meandB[c] += MathUtil.dB(_data[n][c]);
                    }
                }
            }
            for (ushort c = 0; c < nc; c++)
            {
                _meandB[c] /= _length;
            }
            return(_meandB);
        }
Пример #3
0
        /// <summary>
        /// Return a list of freq/gain, only including inflection points (where the curve is flat).
        /// </summary>
        /// <param name="data"></param>
        /// <param name="sr"></param>
        /// <returns></returns>
        public static FilterProfile inflections(double[] data, uint sr)
        {
            // Differentiate
            double bins = data.Length + 1;

            double[] diff = new double[data.Length];

            double n = data[0];

            for (int j = 0; j < data.Length; j++)
            {
                double d = data[j];
                diff[j] = d - n;
                n       = d;
            }

            // Look for zero-crossings of the first derivative of data[]
            // (always include [0] and [end])
            FilterProfile pts = new FilterProfile();

            int    bin;
            double pt   = 0.1;
            int    last = -1;
            double freq;
            double lastfreq = -1;

            // Always start with points for zero and 10 Hz
            pts.Add(new FreqGain(0, MathUtil.dB(data[0])));

            freq = 10;
            bin  = (int)f2bin(freq, sr, bins);
            pts.Add(new FreqGain(freq, MathUtil.dB(data[bin])));
            pt = diff[bin];

            for (int j = bin + 1; j < data.Length; j++)
            {
                if ((pt > 0 && diff[j] <= 0) || (pt < 0 && diff[j] >= 0))
                {
                    freq = bin2f(j, sr, bins);
                    pts.Add(new FreqGain(freq, MathUtil.dB(data[j])));
                    last     = j;
                    lastfreq = freq;
                }
                pt = diff[j];
            }
            // Fill in the last few target samples
            if (lastfreq < (sr / 2) - 2050)
            {
                freq = (sr / 2) - 2050;
                bin  = (int)f2bin(freq, sr, bins);
                pts.Add(new FreqGain(freq, MathUtil.dB(data[bin])));
            }
            if (lastfreq < (sr / 2) - 1550)
            {
                freq = (sr / 2) - 1550;
                bin  = (int)f2bin(freq, sr, bins);
                pts.Add(new FreqGain(freq, MathUtil.dB(data[bin])));
            }
            if (lastfreq < sr / 2)
            {
                freq = sr / 2;
                pts.Add(new FreqGain(freq, MathUtil.dB(data[data.Length - 1])));
            }

            return(pts);
        }