コード例 #1
0
        public List <double> FastCorrelationTwoSignals(List <double> signal1, List <double> signal2, ref List <double> NormalizedSignal)
        {
            int Count;

            Complex[]     S1;
            Complex[]     S2;
            Complex[]     S11;
            Complex[]     S22;
            Complex[]     ResultSignal;
            List <double> Result = new List <double>();
            int           Size   = signal1.Count;

            if (signal1.Count != signal2.Count)
            {
                Size = (signal1.Count + signal2.Count) - 1;
                for (int j = signal1.Count; j < Size; j++)
                {
                    signal1.Add(0);
                }
                for (int j = signal2.Count; j < Size; j++)
                {
                    signal2.Add(0);
                }
            }
            S1           = new Complex[Size];
            S2           = new Complex[Size];
            ResultSignal = new Complex[Size];
            for (int j = 0; j < Size; j++)
            {
                S1[j]      = new Complex(0, 0);
                S2[j]      = new Complex(0, 0);
                S1[j].real = signal1[j];
                S2[j].real = signal2[j];
            }
            S11 = Fourier.FFT(S1);
            S22 = Fourier.FFT(S2);
            for (int j = 0; j < Size; j++)
            {
                S11[j].imag *= -1;
            }
            for (int j = 0; j < Size; j++)
            {
                ResultSignal[j] = S11[j] * S22[j];
            }
            S1 = Fourier.IFFT(ResultSignal);
            for (int i = 0; i < Size; i++)
            {
                Result.Add((S1[i].real / Size) / Size);
            }
            return(Result);
        }
コード例 #2
0
        public List <double> FastConvolve(List <double> H, List <double> X, int OrignX, int OriginH)
        {
            int           TempH, TempX;
            int           OldCount      = H.Count;
            List <double> Result        = new List <double>();
            List <double> FoldedH       = Folding(H);
            double        ComulativeSum = 0;
            int           FoldedIndex   = H.Count - (OriginH + 1);

            TempH = FoldedIndex;
            TempX = OrignX;
            double Temp = 0;

            Complex[] S1;
            Complex[] S2;
            Complex[] S11;
            Complex[] S22;
            Complex[] ResultSignal;
            int       Size = X.Count;

            S1           = new Complex[Size];
            S2           = new Complex[Size];
            ResultSignal = new Complex[Size];
            for (int j = 0; j < Size; j++)
            {
                S1[j]      = new Complex(0, 0);
                S2[j]      = new Complex(0, 0);
                S1[j].real = H[j];
                S2[j].real = X[j];
            }
            S11 = Fourier.FFT(S1);
            S22 = Fourier.FFT(S2);
            for (int j = 0; j < Size; j++)
            {
                ResultSignal[j] = S11[j] * S22[j];
            }
            S1 = Fourier.IFFT(ResultSignal);
            for (int i = 0; i < Size; i++)
            {
                Result.Add(S1[i].real / Size);
            }
            return(Result);
        }