Ejemplo n.º 1
0
        /// <summary>
        /// 分析多音色波形
        /// </summary>
        /// <param name="testData">测试波形</param>
        /// <param name="refWaveform">参考波形</param>
        /// <param name="sampleRate">采样率</param>
        /// <param name="peakToPeak">峰峰值</param>
        /// <param name="acRms">交流有效电平</param>
        /// <param name="dcRms">直流有效电平</param>
        /// <param name="max">最大值</param>
        /// <param name="min">最小值</param>
        /// <param name="tdPlusN">失真和噪声与信号比</param>
        /// <param name="acPart">AC部分</param>
        /// <param name="powerSpectrum">功率谱值</param>
        /// <param name="phaseSpectrum">相位谱</param>
        public static void AnalyzeMultiToneWaveform(double[] testData, MultiToneWaveform refWaveform,
                                                    double sampleRate, out double peakToPeak, out double acRms, out double dcRms,
                                                    out double max, out double min, out double tdPlusN, out double[] acPart,
                                                    out double[] powerSpectrum, out double[] phaseSpectrum)
        {
            MultiToneAnalyzer analyzer = new MultiToneAnalyzer();

            analyzer.SetReferenceWaveform((ManagedAudioLibrary.MultiToneWaveform)refWaveform.GetRawWaveform());
//            uint pathDelay = AnalyzePathDelay(testData, refWaveform.GetWaveData());
//            analyzer.SetDataDelayCounts(pathDelay);
            analyzer.SetDataSampleRate(sampleRate);
            analyzer.Analyze(testData, (uint)testData.Length);

            peakToPeak = analyzer.GetPeakToPeak();
            acRms      = analyzer.GetAcPart();
            dcRms      = analyzer.GetDcPart();
            max        = analyzer.GetMax();
            min        = analyzer.GetMin();
            tdPlusN    = analyzer.GetTdPlusN();

            acPart = new double[refWaveform.FrequencyPoints];
            for (uint i = 0; i < refWaveform.FrequencyPoints; i++)
            {
                acPart[i] = analyzer.GetAcPart((ushort)i);
            }

            uint spectrumLength = analyzer.GetSpectrumLength();

            powerSpectrum = new double[spectrumLength];
            phaseSpectrum = new double[spectrumLength];
            analyzer.GetPowerSpectrum(powerSpectrum);
            analyzer.GetPhaseSpectrum(phaseSpectrum);
        }
Ejemplo n.º 2
0
        public void ShowResult()
        {
            //            easyChart_power.Plot(frequency, powerSpectrum);
            ArrayPair <double, double> powerSpectrum = _analyzer.GetPowerSpectrum();

            easyChart_power.Plot(powerSpectrum.XData, powerSpectrum.YData);
            //            easyChart_phase.Plot(frequency, phaseSpectrum);
            ArrayPair <double, double> phaseSpectrum = _analyzer.GetPhaseSpectrum();

            easyChart_phase.Plot(phaseSpectrum.XData, phaseSpectrum.YData);

            StringBuilder dispResult = new StringBuilder();
            string        newLine    = System.Environment.NewLine;

            dispResult.Append("Amplitude(V):").Append(newLine).Append(_analyzer.GetPeakToPeak()).Append(newLine);
            dispResult.Append("AC RMS(V):").Append(newLine).Append(_analyzer.GetACRms()).Append(newLine);
            dispResult.Append("DC RMS(V):").Append(newLine).Append(_analyzer.GetDCRms()).Append(newLine);
            dispResult.Append("Max(V):").Append(newLine).Append(_analyzer.GetMax()).Append(newLine);
            dispResult.Append("Min(V):").Append(newLine).Append(_analyzer.GetMin()).Append(newLine);
            dispResult.Append("TD+N(dB):").Append(newLine).Append(_analyzer.GetTDPlusN()).Append(newLine);
            textBox_result.Text = dispResult.ToString();
        }