Exemplo n.º 1
0
        /// <summary>
        /// 分析SteppedLevelSine波形
        /// </summary>
        /// <param name="testData">测试波形</param>
        /// <param name="refWaveform">参考波形</param>
        /// <param name="peakToPeak">峰峰值</param>
        /// <param name="thdInDb">谐波失真(dB)</param>
        /// <param name="nrInDb">噪声比(dB)</param>
        /// <param name="thdPlusNInDb">谐波失真和噪声与信号的比(dB)</param>
        /// <param name="rms">有效电平</param>
        public static void AnalyzeSteppedLevelSineWaveform(double[] testData, Waveform.SteppedLevelSineWaveform refWaveform,
                                                           out double[] peakToPeak, out double[] thdInDb, out double[] nrInDb, out double[] thdPlusNInDb, out double[] rms)
        {
            SteppedLevelSineAnalyzer analyzer = new SteppedLevelSineAnalyzer();

            ManagedAudioLibrary.SteppedLevelSineWaveform rawWaveform =
                refWaveform.GetRawWaveform() as ManagedAudioLibrary.SteppedLevelSineWaveform;
            analyzer.SetReferenceWaveform(rawWaveform);

            double[] refData   = refWaveform.GetWaveData();
            uint     pathDelay = AnalyzePathDelay(testData, refData);

            analyzer.SetDataDelayCounts(pathDelay);
            analyzer.Analyze(testData, (uint)testData.Length);


            peakToPeak   = new double[rawWaveform.GetNumberOfSteps()];
            thdInDb      = new double[rawWaveform.GetNumberOfSteps()];
            nrInDb       = new double[rawWaveform.GetNumberOfSteps()];
            thdPlusNInDb = new double[rawWaveform.GetNumberOfSteps()];
            rms          = new double[rawWaveform.GetNumberOfSteps()];

            for (ushort i = 0; i < rawWaveform.GetNumberOfSteps(); i++)
            {
                peakToPeak[i]   = analyzer.GetPeakToPeak(i);
                thdInDb[i]      = analyzer.GetThd(i);
                nrInDb[i]       = analyzer.GetNoiseRatio(i);
                thdPlusNInDb[i] = analyzer.GetThdPlusN(i);
                rms[i]          = analyzer.GetRMS(i);
            }
        }