/// <summary>
 ///   Applies the filter to a windowed signal.
 /// </summary>
 /// 
 public ComplexSignal[] Apply(params ComplexSignal[] complexSignal)
 {
     ComplexSignal[] s = new ComplexSignal[complexSignal.Length];
     for (int i = 0; i < complexSignal.Length; i++)
         s[i] = Apply(complexSignal[i]);
     return s;
 }
Exemple #2
0
        /// <summary>
        ///   Splits a signal using a window
        /// </summary>
        /// 
        public static ComplexSignal[] Split(this ComplexSignal signal, IWindow window, int step)
        {
            int n = (int)System.Math.Floor(signal.Length / (double)step);

            ComplexSignal[] windows = new ComplexSignal[n];

            for (int i = 0; i < n; i++)
            {
                windows[i] = window.Apply(signal, i * step);
            }

            return windows;
        }
        /// <summary>
        ///   Processes the filter.
        /// </summary>
        /// 
        protected unsafe override void ProcessFilter(ComplexSignal sourceData, ComplexSignal destinationData)
        {
            int length = sourceData.Length;

            Complex* src = (Complex*)sourceData.Data.ToPointer();
            Complex* dst = (Complex*)destinationData.Data.ToPointer();

            for (int i = 0; i < length - 1; i++, src++, dst++)
            {
                double re = src[i + 1].Real - src[i].Real;

                // Retain only if difference is positive
                *dst = (re > 0) ? new Complex(re, 0) : Complex.Zero;
            }
        }
        /// <summary>
        ///   Applies the filter to a signal.
        /// </summary>
        /// 
        public ComplexSignal Apply(ComplexSignal complexSignal)
        {
            // get number of channels and samples
            int channels = complexSignal.Channels;
            int samples = complexSignal.Length;

            // retrieve other information
            int rate = complexSignal.SampleRate;

            // create new signal of required format
            ComplexSignal dstSignal = new ComplexSignal(channels, samples, rate);

            // process the filter
            ProcessFilter(complexSignal, dstSignal);

            // return the processed signal
            return dstSignal;
        }
        /// <summary>
        ///   Processes the filter.
        /// </summary>
        /// 
        protected override void ProcessFilter(ComplexSignal sourceData, ComplexSignal destinationData)
        {
            int length = sourceData.Length;

            unsafe
            {
                Complex* src = (Complex*)sourceData.Data.ToPointer();
                Complex* dst = (Complex*)destinationData.Data.ToPointer();

                Complex d = new Complex();

                for (int i = 0; i < length - 1; i++, src++, dst++)
                {
                    d.Re = src[i + 1].Re - src[i].Re;

                    // Retain only if difference is positive
                    *dst = (d.Re > 0) ? d : Complex.Zero;
                }
            }
        }
 /// <summary>
 ///   Processes the filter.
 /// </summary>
 /// 
 protected abstract void ProcessFilter(ComplexSignal sourceData, ComplexSignal destinationData);
        /// <summary>
        ///   Splits a signal using the window.
        /// </summary>
        /// 
        public virtual ComplexSignal Apply(ComplexSignal complexSignal, int sampleIndex)
        {
            Complex[,] resultData = new Complex[Length, complexSignal.Channels];
            ComplexSignal result = ComplexSignal.FromArray(resultData, complexSignal.SampleRate);

            int channels = result.Channels;
            int minLength = System.Math.Min(complexSignal.Length - sampleIndex, Length);

            unsafe
            {
                for (int c = 0; c < complexSignal.Channels; c++)
                {
                    Complex* dst = (Complex*)result.Data.ToPointer() + c;
                    Complex* src = (Complex*)complexSignal.Data.ToPointer() + c + channels * sampleIndex;

                    for (int i = 0; i < minLength; i++, dst += channels, src += channels)
                    {
                        *dst = window[i] * (*src);
                    }
                }
            }

            return result;
        }