/** Method:  Times:  return a new Complex object whose value is (this * b)
         * b -  the complex number for the operation */
        public ComplexNum Times(ComplexNum b)
        {
            ComplexNum a    = this;
            double     real = a.real * b.real - a.imag * b.imag;
            double     imag = a.real * b.imag + a.imag * b.real;

            return(new ComplexNum(real, imag));
        }
        /** Method:  Minus:  return a new Complex object whose value is (this - b)
         * b -  the complex number for the operation */
        public ComplexNum Minus(ComplexNum b)
        {
            ComplexNum a    = this;
            double     real = a.real - b.real;
            double     imag = a.imag - b.imag;

            return(new ComplexNum(real, imag));
        }
        //Static Plus
        /** Method:  Sum of two numbers a and b, static  */
        public static ComplexNum Plus(ComplexNum a, ComplexNum b)
        {
            double     real = a.real + b.real;
            double     imag = a.imag + b.imag;
            ComplexNum sum  = new ComplexNum(real, imag);

            return(sum);
        }
예제 #4
0
        /** Method:  Plus: return a new Complex object whose value is (this + b)
         * b -  the complex number for the operation */
        internal ComplexNum Plus(ComplexNum b)
        {
            ComplexNum a    = this;
            double     real = a.real + b.real;
            double     imag = a.imag + b.imag;

            return(new ComplexNum(real, imag));
        }
예제 #5
0
        private void LinearConvolve(Histogram hist, int n)
        {
            List <double> completeValues = new List <double>();

            for (int i = 0; i < maxClasses; i++)
            {
                if (hist.GetValue(i) > hist.Max)
                {
                    break;
                }
                if (hist.Freqs.ContainsKey(i))
                {
                    completeValues.Add(hist.Freqs[i]);
                }
                else
                {
                    completeValues.Add(0.0);
                }
            }
            PadRight(completeValues);

            ComplexNum[] comp = new ComplexNum[completeValues.Count];
            for (int i = 0; i < completeValues.Count; i++)
            {
                comp[i] = new ComplexNum(completeValues[i], 0);
            }
            ComplexNum[]  complexRes = fft.LinearConvolve(comp, n);
            List <double> realRes    = new List <double>();
            double        tot        = 0;
            double        val;

            for (int i = 0; i < complexRes.Length; i++)
            {
                val = complexRes[i].Real;
                if (val > 0)
                {
                    realRes.Add(val);
                    tot += val;
                }
                else
                {
                    realRes.Add(0);
                }
            }
            probs     = new List <double>();
            acumProbs = new List <double>();
            double prob;
            double acum = 0;

            for (int i = 0; i < complexRes.Length; i++)
            {
                prob = realRes[i] / tot;
                probs.Add(realRes[i] / tot);
                acum += prob;
                acumProbs.Add(acum);
            }
            lag = (int)Math.Round(hist.Mean);
        }
        /** Method:  Divides: returns a / b  */
        public ComplexNum Divides(ComplexNum b)
        {
            ComplexNum a = this;

            return(a.Times(b.Reciprocal()));
        }