/// <summary> /// SteppedSine波形生成 /// </summary> /// <param name="sampleRate">采样率</param> /// <param name="amplitude">波幅</param> /// <param name="frequencyMin">最低频率</param> /// <param name="frequencyMax">最大频率</param> /// <param name="steps">频率阶数</param> /// <param name="minCycle">最小周期数</param> /// <param name="minDuration">最小持续时间</param> /// <param name="isLog">是否对数波形</param> /// <param name="isInverse">是否反转</param> /// <returns>波形数据</returns> public static double[] SteppedSineWaveform(double sampleRate, double amplitude, double frequencyMin, double frequencyMax, ushort steps, ushort minCycle, double minDuration, bool isLog = false, bool isInverse = false) { SteppedSineWaveform steppedSineWaveform = new SteppedSineWaveform(); steppedSineWaveform.CreateData(amplitude, frequencyMin, frequencyMax, steps, isLog, isInverse, minCycle, minDuration, sampleRate); double[] waveData = new double[steppedSineWaveform.GetTotalPoints()]; steppedSineWaveform.GetCopyOfData(waveData); return(waveData); }
/// <summary> /// 分析SteppedSine波形的串扰 /// </summary> /// <param name="refWaveForm">参考波形</param> /// <param name="testWaveform">测试波形</param> /// <param name="sampleRate">采样率</param> /// <param name="maxFrequency">波形最大频率</param> /// <param name="minFrequency">波形最低频率</param> /// <param name="steps">阶数</param> /// <param name="minCycles">最小周期</param> /// <param name="minDuration">最小时间</param> /// <param name="amplitude">振幅</param> /// <param name="isLog">是否对数波形</param> /// <returns>返回串扰值,X和Y分别为各自的频率和对应的串扰值</returns> public static ArrayPair <double, double> AnalyzeSteppedSineCrosstalk(double[] refWaveForm, double[] testWaveform, double sampleRate, double maxFrequency, double minFrequency, ushort steps, ushort minCycles, double minDuration, double amplitude, bool isLog = false) { // const double refDataSampleRate = 96000.0; // const double minDuration = 40.0 / 1000.0; // const ushort minCycles = 40; // const double amplitude = 1; // SteppedSineWaveform steppedSineWaveform = new SteppedSineWaveform(); steppedSineWaveform.CreateData(1, minFrequency, maxFrequency, steps, false, false, minCycles, minDuration, sampleRate); double[] refData = new double[steppedSineWaveform.GetTotalPoints()]; steppedSineWaveform.GetCopyOfData(refData); double[] testData = new double[refWaveForm.Length + testWaveform.Length]; Buffer.BlockCopy(refWaveForm, 0, testData, 0, refWaveForm.Length * sizeof(double)); Buffer.BlockCopy(testWaveform, 0, testData, refWaveForm.Length * sizeof(double), testWaveform.Length * sizeof(double)); SteppedSineCrosstalkAnalyzer analyzer = new SteppedSineCrosstalkAnalyzer(); // pathDelay = 6000; analyzer.SetDataSampleRate(sampleRate); uint pathDelay = AnalyzePathDelay(testData, refData.Take(refWaveForm.Length).ToArray()); analyzer.SetDataDelayCounts(pathDelay); analyzer.SetReferenceData(testData); analyzer.SetReferenceWaveform(steppedSineWaveform); analyzer.Analyze(testWaveform, (uint)testWaveform.Length); double[] frequency = new double[steppedSineWaveform.GetNumberOfSteps()]; double[] crossTalk = new double[steppedSineWaveform.GetNumberOfSteps()]; for (ushort index = 0; index < steppedSineWaveform.GetNumberOfSteps(); index++) { frequency[index] = steppedSineWaveform.GetFrequencyPoint(index); crossTalk[index] = analyzer.GetCrosstalk(index); } return(new ArrayPair <double, double>(frequency, crossTalk)); }