Exemplo n.º 1
0
 /// <summary>
 ///   Applies forward Hilbert transformation to the complex signal.
 /// </summary>
 public void ForwardHilbertTransform()
 {
     if (status == ComplexSignalStatus.Normal)
     {
         for (int c = 0; c < Channels; c++)
         {
             Complex[] channel = GetChannel(c);
             HilbertTransform.FHT(channel, FourierTransform.Direction.Forward);
             SetChannel(c, channel);
         }
         status = ComplexSignalStatus.Analytic;
     }
 }
Exemplo n.º 2
0
        public void FHTTest2()
        {
            double[] original = { -1.0, -0.8, -0.2, -0.1, 0.1, 0.2, 0.8, 1.0 };

            double[] actual = (double[])original.Clone();

            HilbertTransform.FHT(actual, FourierTransform.Direction.Forward);

            HilbertTransform.FHT(actual, FourierTransform.Direction.Backward);

            Assert.AreEqual(actual[0], original[0], 0.08);
            Assert.AreEqual(actual[1], original[1], 0.08);
            Assert.AreEqual(actual[2], original[2], 0.08);
            Assert.AreEqual(actual[3], original[3], 0.08);
        }
Exemplo n.º 3
0
        public double[] hilbertTransformBaseBand(double[] input)
        {
            int lengthIn = input.Length;

            if (lengthIn > 16384)
            {
                MessageBox.Show("Error: Input Length Too large or hilbert transform. Data will not be transformed.", "Warning", MessageBoxButton.OK, MessageBoxImage.Error);//For gui, convert this to an error box.
                return(null);
            }
            else
            {
                int      power        = (int)Math.Ceiling(Math.Log10(lengthIn) / Math.Log10(2));
                int      lengthFiller = (int)Math.Pow(2, power) - (int)lengthIn;
                double[] fillerArray  = MathNet.Numerics.Generate.Step(lengthFiller, 0.0, 0);
                Array.Resize <double>(ref input, lengthIn + lengthFiller);
                Array.Copy(fillerArray, 0, input, lengthIn, lengthFiller);
                HilbertTransform.FHT(input, FourierTransform.Direction.Forward);
                return(input);
            }
        }
Exemplo n.º 4
0
        public static object FHT(double[] Data, object BackwardFlagOpt)
        {
            bool backwards = Utils.GetOptionalParameter(BackwardFlagOpt, false);

            FourierTransform.Direction direction = (backwards ? FourierTransform.Direction.Backward : FourierTransform.Direction.Forward);

            try
            {
                HilbertTransform.FHT(Data, direction);
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.ToString());
            }

            double[,] ret = new double[Data.Length, 1];
            for (int i = 0; i < Data.Length; ++i)
            {
                ret[i, 0] = Data[i];
            }

            return(ret);
        }
Exemplo n.º 5
0
        public void FHTTest()
        {
            Complex[] original = { (Complex)1, (Complex)2, (Complex)3, (Complex)4 };

            Complex[] actual = (Complex[])original.Clone();
            HilbertTransform.FHT(actual, FourierTransform.Direction.Forward);

            Assert.AreEqual(actual[0].Re, 1);
            Assert.AreEqual(actual[1].Re, 2);
            Assert.AreEqual(actual[2].Re, 3);
            Assert.AreEqual(actual[3].Re, 4);

            Assert.AreEqual(actual[0].Im, +1, 0.000000001);
            Assert.AreEqual(actual[1].Im, -1, 0.000000001);
            Assert.AreEqual(actual[2].Im, -1, 0.000000001);
            Assert.AreEqual(actual[3].Im, +1, 0.000000001);

            HilbertTransform.FHT(actual, FourierTransform.Direction.Backward);

            Assert.AreEqual(actual[0], original[0]);
            Assert.AreEqual(actual[1], original[1]);
            Assert.AreEqual(actual[2], original[2]);
            Assert.AreEqual(actual[3], original[3]);
        }
Exemplo n.º 6
0
        public static Complex[] Transform(Complex[] functionPoints, string transformate)
        {
            var copyofFunctionsPoints = functionPoints;


            var copyofFunctionsPoints2 = new Complex[functionPoints.Length];
            var multidimensialArray    = new double[functionPoints.Length, 2];

            var jaggedArray = new double[functionPoints.Length][];

            for (var i = 0; i < functionPoints.Length; i++)
            {
                jaggedArray[i] = new double[2];
            }


            for (var i = 0; i < functionPoints.Length; i++)
            {
                jaggedArray[i][0]             = multidimensialArray[i, 0] = functionPoints[i].Real;
                jaggedArray[i][1]             =
                    multidimensialArray[i, 1] = functionPoints[i].Imaginary;
                copyofFunctionsPoints2[i]     = new Complex(functionPoints[i].Real,
                                                            copyofFunctionsPoints2[i].Imaginary);
            }


            switch (transformate)
            {
            case "FFT":
                Fourier.Forward(copyofFunctionsPoints);
                break;


            case "IFFT":
                Fourier.Inverse(copyofFunctionsPoints);
                break;

            case "DST":
                SineTransform.DST(jaggedArray);
                copyofFunctionsPoints = jaggedToComplex(jaggedArray);
                break;

            case "IDST":
                SineTransform.IDST(jaggedArray);
                copyofFunctionsPoints = jaggedToComplex(jaggedArray);
                break;

            case "DCT":
                CosineTransform.DCT(multidimensialArray);
                copyofFunctionsPoints = multidimensialToComplex(multidimensialArray);
                break;

            case "IDCT":
                CosineTransform.IDCT(multidimensialArray);
                copyofFunctionsPoints = multidimensialToComplex(multidimensialArray);
                break;

            case "DHT":
                HartleyTransform.DHT(multidimensialArray);
                copyofFunctionsPoints = multidimensialToComplex(multidimensialArray);
                break;

            case "FHT":
                HilbertTransform.FHT(copyofFunctionsPoints2,
                                     FourierTransform.Direction.Forward);
                copyofFunctionsPoints = copyofFunctionsPoints2;
                break;

            case "IFHT":
                HilbertTransform.FHT(copyofFunctionsPoints2,
                                     FourierTransform.Direction.Backward);
                copyofFunctionsPoints = copyofFunctionsPoints2;
                break;

            default:
                throw new ArgumentException("Unknown transformation!");
            }
            return(copyofFunctionsPoints); //athenia programuje//dididididi//di/kocham PaciA// JJKAKAKK  K
        }
Exemplo n.º 7
0
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public HilbertTransform HilbertTransform(Data.IDataSeries input, int wMAPeriods)
        {
            if (cacheHilbertTransform != null)
                for (int idx = 0; idx < cacheHilbertTransform.Length; idx++)
                    if (cacheHilbertTransform[idx].WmaPeriods == wMAPeriods && cacheHilbertTransform[idx].EqualsInput(input))
                        return cacheHilbertTransform[idx];

            lock (checkHilbertTransform)
            {
                checkHilbertTransform.WmaPeriods = wMAPeriods;
                wMAPeriods = checkHilbertTransform.WmaPeriods;

                if (cacheHilbertTransform != null)
                    for (int idx = 0; idx < cacheHilbertTransform.Length; idx++)
                        if (cacheHilbertTransform[idx].WmaPeriods == wMAPeriods && cacheHilbertTransform[idx].EqualsInput(input))
                            return cacheHilbertTransform[idx];

                HilbertTransform indicator = new HilbertTransform();
                indicator.BarsRequired = BarsRequired;
                indicator.CalculateOnBarClose = CalculateOnBarClose;
            #if NT7
                indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
                indicator.MaximumBarsLookBack = MaximumBarsLookBack;
            #endif
                indicator.Input = input;
                indicator.WmaPeriods = wMAPeriods;
                Indicators.Add(indicator);
                indicator.SetUp();

                HilbertTransform[] tmp = new HilbertTransform[cacheHilbertTransform == null ? 1 : cacheHilbertTransform.Length + 1];
                if (cacheHilbertTransform != null)
                    cacheHilbertTransform.CopyTo(tmp, 0);
                tmp[tmp.Length - 1] = indicator;
                cacheHilbertTransform = tmp;
                return indicator;
            }
        }