예제 #1
0
        /// <summary>
        /// Создание вейвлета по масштабному множителю с указанием вейвлета из перечисления
        /// </summary>
        /// <param name="W"></param>
        /// <param name="ww"></param>
        /// <param name="k"></param>
        public Wavelet(Wavelets W = Wavelets.MHAT, double ww = 1)
        {
            this.w    = ww;
            this.Type = W;
            switch (W)
            {
            case Wavelets.WAVE:
                this.Mother  = (double t) => - t * Math.Exp(-t * t / 2);
                this.FMother = (Complex w) => Complex.I * w * sqrt2pi * Complex.Exp(-w * w / 2);
                break;

            case Wavelets.MHAT:
                this.Mother  = (double t) => { double sqr = t * t; return((1 - sqr) * Math.Exp(-sqr / 2)); };
                this.FMother = (Complex w) =>
                {
                    var sqr = -w * w;
                    return(sqr * sqrt2pi * Complex.Exp(sqr / 2));
                };
                break;

            case Wavelets.DOG:
                this.Mother  = (double t) => { double sqr = -t * t / 2; return(Math.Exp(sqr) - 0.5 * Math.Exp(sqr / 4)); };
                this.FMother = (Complex w) =>
                {
                    var sqr = -w * w;
                    return(sqrt2pi * (Complex.Exp(sqr / 2) - Complex.Exp(2 * sqr)));
                };
                break;

            case Wavelets.LP:
                this.Mother = t =>
                {
                    double pt = t * Math.PI;
                    return((2.0 * Math.Cos(pt) - 1.0) * Math.Sin(pt) / pt);
                };
                this.FMother = (Complex w) =>
                {
                    double tmp = w.Abs;
                    if (tmp <= 2 * Math.PI && tmp >= Math.PI)
                    {
                        return(frac1sqrt2pi);
                    }
                    return(0);
                };
                break;

            case Wavelets.HAAR:
                this.Mother = t =>
                {
                    if (t >= 0)
                    {
                        if (t <= 0.5)
                        {
                            return(1);
                        }
                        if (t <= 1)
                        {
                            return(-1);
                        }
                        return(0);
                    }
                    return(0);
                };
                this.FMother = (Complex w) => 4 * Complex.I * Complex.Exp(Complex.fracI2 * w) / w * Complex.Sin(w / 4).Sqr();
                break;

            case Wavelets.FHAT:
                this.Mother = t =>
                {
                    double q = t.Abs();
                    if (q <= 1.0 / 3)
                    {
                        return(1);
                    }
                    if (q <= 1)
                    {
                        return(-0.5);
                    }
                    return(0);
                };
                this.FMother = (Complex w) => 4 * Complex.Sin(w / 3).Pow(3) / w;
                break;

            case Wavelets.Morlet:
                this.Mother  = t => Math.Exp(-t.Sqr() / 2) * Complex.Exp(Complex.I * w * t);
                this.FMother = (Complex w) => sigma(w) * sqrt2pi * Complex.Exp(-(w - this.w).Sqr() / 2);
                break;

            case Wavelets.Gabor:
                const double w_0                = 2 * Math.PI;
                double       gamma              = Math.PI * Math.Sqrt(2.0 / Math.Log(2));
                double       fracw0gamma        = Math.Sqrt(2 * Math.Log(2));
                double       fracgammaw0        = 1.0 / fracw0gamma;
                double       sqrfracw0gamma     = fracw0gamma * fracw0gamma;
                double       sqrfracgammaw0     = fracgammaw0 * fracgammaw0;
                double       fracpis            = Math.Pow(Math.PI, -0.25);
                double       sqrtfracw0gammapis = fracpis * Math.Sqrt(fracw0gamma);
                double       fracs2pipis        = sqrt2pi / fracpis;
                double       Gabortmp           = -sqrfracw0gamma / 2;
                this.Mother = t => sqrtfracw0gammapis *Math.Exp(Gabortmp *t *t) * Complex.Expi(w_0 * t);

                this.FMother = (Complex w) => fracs2pipis *Math.Sqrt(fracgammaw0) * Complex.Exp(-sqrfracgammaw0 / 2 * (w - w_0).Sqr());

                break;
            }
        }
예제 #2
0
 /// <summary>
 /// Создать вейвлет
 /// </summary>
 /// <param name="W"></param>
 /// <param name="k"></param>
 /// <param name="ww"></param>
 /// <returns></returns>
 public static Wavelet Create(Wavelets W = Wavelets.MHAT, double ww = 1) => new Wavelet(W, ww);
예제 #3
0
        private void DWT()
        {
            while (start)
            {
                lock (data)
                {
                    if (!data.IsEmpty && !stop)
                    {
                        data.TryDequeue(out List <Double> res);
                        Signal <Double> sig = new Signal <double>(res.ToArray());
                        formsPlot1.plt.Clear();
                        try
                        {
                            int level = Convert.ToInt32(this.ResolveText.Text);
                            DiscreteWaveletTransform rs  = DiscreteWaveletTransform.Estimate(sig, Wavelets.Daubechies(2), new ZeroPadding <Double>());
                            DiscreteWaveletTransform rs1 = rs.EstimateMultiscale(new ZeroPadding <Double>(), level);

                            if (showType == 0)
                            {
                                //formsPlot1.plt.PlotSignal(rs.Detail.ToArray(), label: "第一层细节");
                                showGraph(rs1, level, showType);
                            }
                            else
                            {
                                //formsPlot1.plt.PlotSignal(rs1.Approximation.ToArray(), label: "第一层概貌");
                                showGraph(rs1, level, showType);
                            }
                            formsPlot1.plt.Legend();
                            formsPlot1.Render();
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e.Message);
                        }
                    }
                }
            }
        }