Example #1
0
        public override void Run()
        {
            OutputSignal = new Signal(new List <float>(), false, new List <float>(), new List <float>(), new List <float>());
            FastFourierTransform fft = new FastFourierTransform();

            fft.InputTimeDomainSignal = InputSignal;
            fft.Run();
            fft.OutputFreqDomainSignal.FrequenciesAmplitudes[0]  = 0;
            fft.OutputFreqDomainSignal.FrequenciesPhaseShifts[0] = 0;
            InverseFastFourierTransform ifft = new InverseFastFourierTransform();

            ifft.InputFreqDomainSignal = fft.OutputFreqDomainSignal;
            ifft.Run();
            OutputSignal = ifft.OutputTimeDomainSignal;
        }
Example #2
0
        public List <float> clculatecorrelation(Signal inputs1, Signal inputs2)
        {
            List <float> Results = new List <float>();
            // find fft l signal el 2ola w el tania

            FastFourierTransform fastfun = new FastFourierTransform();

            ///// signal 1
            ///
            fastfun.InputTimeDomainSignal  = inputs1;
            fastfun.InputSamplingFrequency = 4;
            fastfun.Run();
            Signal outoffft1 = new Signal(false, new List <float>(), new List <float>(), new List <float>()); // ناتج fft1

            outoffft1 = fastfun.OutputFreqDomainSignal;
            ///////
            ///
            //////signal 2
            ///
            fastfun.InputTimeDomainSignal  = inputs1;
            fastfun.InputSamplingFrequency = 4;
            fastfun.Run();
            Signal outoffft2 = new Signal(false, new List <float>(), new List <float>(), new List <float>());

            outoffft2 = fastfun.InputTimeDomainSignal = inputs2;
            ///////////////
            ///////
            ///هنجيب الكونجكت بتاع السيجنال الاولي  هنضرب الايمجن ف -1
            ///
            Complex result_of_multyplay2signals = new Complex();

            for (int i = 0; i < outoffft1.FrequenciesAmplitudes.Count; i++)
            {
                double Real1 = outoffft1.FrequenciesAmplitudes[i] * Math.Cos(outoffft1.FrequenciesPhaseShifts[i]);
                double Imag1 = outoffft1.FrequenciesAmplitudes[i] * Math.Sin(outoffft1.FrequenciesPhaseShifts[i]);

                double Real2 = outoffft2.FrequenciesAmplitudes[i] * Math.Cos(outoffft2.FrequenciesPhaseShifts[i]);
                double Imag2 = outoffft2.FrequenciesAmplitudes[i] * Math.Sin(outoffft2.FrequenciesPhaseShifts[i]);
                double Real  = Real1 * Real2;
                double Imag  = -1 * Imag1 * Imag2;
                inp_of_ifft.Add((float)(Real + Imag));
                Complex x = new Complex(Real, Imag);
                result_of_multyplay2signals = new Complex(x.Real, x.Imaginary);
            }
            ///////////////////// find ifft
            ///
            InverseFastFourierTransform invfastfun = new InverseFastFourierTransform();

            for (int i = 0; i < inp_of_ifft.Count; i++)
            {
                invfastfun.InputFreqDomainSignal.FrequenciesAmplitudes[i] = inp_of_ifft[i];
            }
            invfastfun.Run();



            for (int i = 0; i < invfastfun.OutputTimeDomainSignal.Samples.Count; i++)
            {
                float Result = (float)((double)(invfastfun.OutputTimeDomainSignal.Samples[i] / invfastfun.OutputTimeDomainSignal.Samples.Count));
                if (inputs1 != inputs2)
                {
                    Results.Add((float)Math.Round(Result, 8));
                }
                else
                {
                    Results.Add(Result);
                }
            }
            return(Results);
        }