/// <summary> /// 分析单音色波形 /// </summary> /// <param name="waveform">测试波形</param> /// <param name="targetFreq">目标频率</param> /// <param name="sampleRate">采样率</param> /// <param name="amplitudeInVol">波幅</param> /// <param name="thdInDb">谐波失真(dB)</param> /// <param name="nrInDb">噪声比(dB)</param> /// <param name="thdPlusNRatioInDb">噪声和谐波失真与信号的比(dB)</param> /// <param name="harmonicPower">谐波分量功率</param> public static void AnalyzeSingleToneWave(double[] waveform, double targetFreq, double sampleRate, out double amplitudeInVol, out double thdInDb, out double nrInDb, out double thdPlusNRatioInDb, out double[] harmonicPower) { const ushort harmonicOrder = 6; SingleToneAnalyzer analyzer = new SingleToneAnalyzer(); analyzer.SetTargetToneFrequency(targetFreq, sampleRate); analyzer.Analyze(waveform, (uint)waveform.Length); amplitudeInVol = analyzer.GetPeakToPeak(); thdInDb = analyzer.GetThd(); nrInDb = analyzer.GetNoiseRatio(); thdPlusNRatioInDb = analyzer.GetThdPlusN(); harmonicPower = new double[harmonicOrder]; for (ushort i = 0; i < harmonicOrder; i++) { harmonicPower[i] = analyzer.GetHarmonicPower(i); } }
public void ShowResult() { StringBuilder dispResult = new StringBuilder(); string newLine = Environment.NewLine; const string delim = ","; dispResult.Append("PeakToPeak(V):").Append(newLine).Append(_analyzer.GetPeakToPeak()).Append(newLine); dispResult.Append("THD(db):").Append(newLine).Append(_analyzer.GetTHDInDb()).Append(newLine); dispResult.Append("Noise Ratio(db):").Append(newLine).Append(_analyzer.GetNoiseRatioInDb()).Append(newLine); dispResult.Append("Thd Plus Noise Ratio(dB):") .Append(newLine) .Append(_analyzer.GetNoiseRatioInDb()) .Append(newLine); ArrayPair <double, double> harmonicPower = _analyzer.GetHarmonicPower(); dispResult.Append("Harmoic Power:").Append(newLine).Append(harmonicPower.YData[0]).Append(delim) .Append(harmonicPower.YData[1]).Append(delim).Append(harmonicPower.YData[2]).Append(delim). Append(harmonicPower.YData[3]).Append(delim).Append(harmonicPower.YData[4]).Append(delim). Append(harmonicPower.YData[5]); textBox_result.Text = dispResult.ToString(); }