private void ExecuteVibrateAnalysis(string param, out string retValue)
        {
            retValue = "Res=Fail";

            string[] parameters = param.Split(' ');
            string   filename   = parameters[0];
            int      start      = Int32.Parse(parameters[1]);
            int      len        = Int32.Parse(parameters[2]);
            int      divider    = Int32.Parse(parameters[3]);

            int freqCount = (parameters.Length - 4) / 2;

            try
            {
                using (WaveFile waveFile = new WaveFile(filename))
                {
                    int       n     = CalcFFTPoints(waveFile.SamplesPerSecond, len);
                    double[]  lData = new double[n];
                    Complex[] cData;

                    if (waveFile.Channels == 2)
                    {
                        int sampleStartIndex = start * waveFile.SamplesPerSecond / 1000;
                        int offset           = sampleStartIndex * waveFile.BlockAlign;
                        int count            = n * waveFile.BlockAlign;

                        byte[] data = waveFile.GetData(offset, count);

                        using (MemoryStream memStream = new MemoryStream(data))
                        {
                            using (BinaryReader reader = new BinaryReader(memStream))
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    lData[i] = (double)reader.ReadInt16();
                                    reader.ReadInt16();
                                }
                            }
                        }
                    }
                    else
                    {
                        int sampleStartIndex = start * waveFile.SamplesPerSecond / 1000;
                        int offset           = sampleStartIndex * waveFile.BlockAlign;
                        int count            = n * waveFile.BlockAlign;

                        byte[] data = waveFile.GetData(offset, count);

                        using (MemoryStream memStream = new MemoryStream(data))
                        {
                            using (BinaryReader reader = new BinaryReader(memStream))
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    lData[i] = (double)reader.ReadInt16();
                                }
                            }
                        }
                    }

                    fft_r2c(lData, out cData);

                    double[] ddata = new double[cData.Length];

                    ddata[0] = cData[0].Magnitude / n;
                    for (int i = 1; i < cData.Length; i++)
                    {
                        ddata[i] = cData[i].Magnitude * 2 / n;
                    }

                    double freqInterval = (double)waveFile.SamplesPerSecond / n;
                    double total        = 0;
                    double valid        = 0;

                    for (int i = 0; i < ddata.Length; i++)
                    {
                        double freq    = i * freqInterval;
                        bool   inRange = false;
                        for (int j = 0; j < freqCount; j++)
                        {
                            int freqOrigin = Int32.Parse(parameters[4 + 2 * j]);
                            int freqShift  = Int32.Parse(parameters[4 + 2 * j + 1]);

                            double freqLower = freqOrigin - freqShift;
                            double freqUpper = freqOrigin + freqShift;



                            if (freqLower <= freq && freq <= freqUpper)
                            {
                                inRange = true;
                                break;
                            }
                        }

                        if (inRange)
                        {
                            valid += ddata[i];
                        }
                        total += ddata[i];
                    }

                    double validRate = valid / total * 100;
                    double ampl      = total / divider / 32.7;

                    retValue = "Ampl=" + ampl.ToString("F") + ";Noise=" + validRate.ToString("F");
                }
            }
            catch (Exception e)
            {
                Log.Debug(e.Message, e);
            }
        }
        private void ExecuteAnalysis(string param, out string retValue)
        {
            string[] parameters = param.Split(' ');
            string   filename   = parameters[0];
            int      start      = Int32.Parse(parameters[1]);
            int      len        = Int32.Parse(parameters[2]);
            int      baseFreq   = Int32.Parse(parameters[3]);
            int      freqShift  = Int32.Parse(parameters[4]);

            retValue = "Res=Fail";
            try
            {
                using (WaveFile waveFile = new WaveFile(filename))
                {
                    int n = CalcFFTPoints(waveFile.SamplesPerSecond, len);

                    if (waveFile.Channels == 2)
                    {
                        int sampleStartIndex = start * waveFile.SamplesPerSecond / 1000;
                        int offset           = sampleStartIndex * waveFile.BlockAlign;
                        int count            = n * waveFile.BlockAlign;

                        byte[] data = waveFile.GetData(offset, count);

                        using (MemoryStream memStream = new MemoryStream(data))
                        {
                            using (BinaryReader reader = new BinaryReader(memStream))
                            {
                                double[] lData = new double[n];
                                double[] rData = new double[n];

                                for (int i = 0; i < n; i++)
                                {
                                    lData[i] = (double)reader.ReadInt16();
                                    rData[i] = (double)reader.ReadInt16();
                                }

                                Complex[] lcData;
                                Complex[] rcData;
                                fft_r2c(lData, out lcData);
                                fft_r2c(rData, out rcData);

                                double freq1, freq2;
                                double ampl1, ampl2;
                                double thd1, thd2;
                                double noise1, noise2;

                                CalcFreqAndAmpl(n, waveFile.SamplesPerSecond, lcData, out freq1, out ampl1);
                                CalcFreqAndAmpl(n, waveFile.SamplesPerSecond, rcData, out freq2, out ampl2);

                                CalcThd(n, waveFile.SamplesPerSecond, baseFreq, lcData, out thd1);
                                CalcThd(n, waveFile.SamplesPerSecond, baseFreq, rcData, out thd2);

                                CalcNoise(n, waveFile.SamplesPerSecond, baseFreq, freqShift, lcData, out noise1);
                                CalcNoise(n, waveFile.SamplesPerSecond, baseFreq, freqShift, rcData, out noise2);

                                retValue  = "Freq1=" + freq1.ToString("F") + ";Ampl1=" + ampl1.ToString("F") + ";Thd1=" + thd1.ToString("F") + ";Noise1=" + noise1.ToString("F");
                                retValue += ";Freq2=" + freq2.ToString("F") + ";Ampl2=" + ampl2.ToString("F") + ";Thd2=" + thd2.ToString("F") + ";Noise2=" + noise2.ToString("F");
                            }
                        }
                    }
                    else
                    {
                        int sampleStartIndex = start * waveFile.SamplesPerSecond / 1000;
                        int offset           = sampleStartIndex * waveFile.BlockAlign;
                        int count            = n * waveFile.BlockAlign;

                        byte[] data = waveFile.GetData(offset, count);

                        using (MemoryStream memStream = new MemoryStream(data))
                        {
                            using (BinaryReader reader = new BinaryReader(memStream))
                            {
                                double[] lData = new double[n];

                                for (int i = 0; i < n; i++)
                                {
                                    lData[i] = (double)reader.ReadInt16();
                                }

                                Complex[] lcData;
                                fft_r2c(lData, out lcData);

                                double freq1;
                                double ampl1;
                                double thd1;
                                double noise1;

                                CalcFreqAndAmpl(n, waveFile.SamplesPerSecond, lcData, out freq1, out ampl1);

                                CalcThd(n, waveFile.SamplesPerSecond, baseFreq, lcData, out thd1);

                                CalcNoise(n, waveFile.SamplesPerSecond, baseFreq, freqShift, lcData, out noise1);

                                retValue = "Freq1=" + freq1.ToString("F") + ";Ampl1=" + ampl1.ToString("F") + ";Thd1=" + thd1.ToString("F") + ";Noise1=" + noise1.ToString("F");
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Debug(e.Message, e);
            }
        }