コード例 #1
0
ファイル: WTransform.cs プロジェクト: nik709/WT
        private RangeFunctor.RangeFunctor _translations; // translations functor used

        public WTransform(RangeFunctor.RangeFunctor Scales, RangeFunctor.RangeFunctor Translations,
                          Wavelet.Wavelet MotherWavelet, string Name)
        {
            _name = Name;
            _rows = Scales.Steps();
            _cols = Translations.Steps();

            // transform result cannot be empty
            if (_rows <= 0 || _cols <= 0)
            {
                throw new ArgumentException("Invalid dimensions provided!");
            }

            // copy necessary objects
            _scales       = Scales;
            _translations = Translations;
            _wavelet      = MotherWavelet;

            // allocate storage
            _re = new double[_rows * _cols];
            _im = new double[_rows * _cols];
        }
コード例 #2
0
ファイル: CWTalgorithm.cs プロジェクト: nik709/WT
        public static WTransform cwt(Signal s, RangeFunctor.RangeFunctor Scales,
                                     RangeFunctor.RangeFunctor Translations, Wavelet.Wavelet MotherWavelet, int ivalp, string Name)
        {
            // Result
            WTransform wt;

            // references to internal Signal/WTransform data
            double[] s_re, s_im;
            double[] wt_re, wt_im;
            // signal params
            int    n  = s.length();
            double fs = s.getFs();
            // WT params
            double a, b, T;
            double i, istep;
            // indexes and dimensions
            int dx, dy;
            int rows, cols;
            int row, row_dx;


            // check arguments
            if (Scales.Steps() <= 0 || Translations.Steps() <= 0 || n <= 0 ||
                fs <= 0.0 || ivalp <= 0)
            {
                throw new ArgumentException();
            }

            // create result object
            wt = new WTransform(Scales, Translations, MotherWavelet, Name);

            // obtain result dimensions and references to data
            rows  = wt.rows();
            cols  = wt.cols();
            wt_re = wt.reData();
            wt_im = wt.imData();
            s_re  = s.reData();
            s_im  = s.imData();

            // index step (used in convolution stage)
            istep = 1.0 / (double)ivalp;

            // Scales
            for (dy = 0; dy < rows; dy++)
            {
                // obtain current scale
                a = Scales.Evaluate(dy) * fs;
                if (Math.Abs(a) < 0.0)
                {
                    a = Double.MinValue;
                }

                // set starting index of current row
                row = dy * cols;

                // Translations
                for (dx = 0; dx < cols; dx++)
                {
                    // obtain current translation
                    b = Translations.Evaluate(dx) * fs;

                    // index of convolution result
                    row_dx = row + dx;

                    // Perform convolution
                    wt_re[row_dx] = 0.0;
                    wt_im[row_dx] = 0.0;
                    for (i = 0.0; i < n; i += istep)
                    {
                        T              = (i - b) / a;
                        wt_re[row_dx] += cmplxMulRe(s_re[(int)i], s_im[(int)i],
                                                    MotherWavelet.reT(T), -MotherWavelet.imT(T));
                        wt_im[row_dx] += cmplxMulRe(s_re[(int)i], s_im[(int)i],
                                                    MotherWavelet.reT(T), -MotherWavelet.imT(T));
                        // NOTE: "-" before Wavelet imaginary part indicates complex
                        // conjunction.
                    }

                    wt_re[row_dx] *= 1.0 / (Math.Sqrt(a) * ivalp);
                    wt_im[row_dx] *= 1.0 / (Math.Sqrt(a) * ivalp);
                }
            }

            return(wt);
        }