Ejemplo n.º 1
0
        public double[] PowerSpectralDensity(double[] d, WindowBase window, double fs, double maxSignalAmpl)
        {
            Complex[] spec = DoFFT(d, window);

            double[] y   = new double[spec.Length];
            double   max = Double.MinValue;

            for (int i = 0; i < spec.Length; i++)
            {
                y[i] = 20 * Math.Log10(spec[i].Abs);
                if (y[i] > max)
                {
                    max = y[i];
                }
            }


            if (double.NaN.CompareTo(maxSignalAmpl) == 0)
            {
                ArrayMath.Add(ref y, -max);
            }
            else
            {
                max = 20 * Math.Log10(maxSignalAmpl / 2);
                ArrayMath.Add(ref y, -max);
            }


            return(y);
        }
Ejemplo n.º 2
0
        public Complex[] DoFFT(double[] d, WindowBase window)
        {
            double M = d.Length;

            double[] dwindow = window.Calc((int)M);

            ArrayMath.Multiply(ref d, ref dwindow);
            Complex[] fft  = Run(d);
            Complex[] spec = new Complex[fft.Length / 2];

            for (int i = 1; i < fft.Length / 2 + 1; i++)
            {
                spec[i - 1].Real = fft[i].Real * 2 / M;
                spec[i - 1].Imag = fft[i].Imag * 2 / M;
            }
            return(spec);
        }
Ejemplo n.º 3
0
        public void DynamicParameters(List <double> d, WindowBase window,
                                      double fs, double f0, double fmin, double fmax, bool remove_dc, out double snr, out double sndr, out double enob)
        {
            double dc_offset = 0;

            if (remove_dc)
            {
                dc_offset = ArrayMath.Sum(d.ToArray()) / d.Count;
            }

            if (dc_offset != 0)
            {
                for (int i = 0; i < d.Count; i++)
                {
                    d[i] -= dc_offset;
                }
            }

            Complex[] spec = DoFFT(d, window);
            snr  = SignalNoise(spec, d.Count, fs, f0, 6, 3, fmin, fmax);
            sndr = SignalNoise(spec, d.Count, fs, f0, 0, 3, fmin, fmax);
            enob = (sndr - 1.76) / 6.02;
        }