Exemplo n.º 1
0
        // Initialize the filter with a set of SmoothParameters.
        public void Init(SmoothParameters smoothParameters)
        {
            this.smoothingType    = SmoothingType.Default;
            this.smoothParameters = smoothParameters;

            Reset();
            init = true;
        }
Exemplo n.º 2
0
        public static FilterProfile Profile(ISoundObj impulse, SmoothingType type, double resolution)
        {
            uint nSR  = impulse.SampleRate;
            uint nSR2 = nSR / 2;

            ushort nChannels = impulse.NumChannels;

            for (ushort c = 0; c < nChannels; c++)
            {
                // Read channel into a buffer
                SingleChannel channel = impulse.Channel(c);
                SoundBuffer   buff    = new SoundBuffer(channel);
                buff.ReadAll();

                // And then double in length to prevent wraparound
                buff.PadTo(buff.Count * 2);
                // Pad to next higher power of two
                buff.PadToPowerOfTwo();
                // Read out into array of complex
                Complex[][] data  = buff.ToComplexArray();
                Complex[]   cdata = data[0];

                // Then we're done with the buffer for this channel
                buff = null;
                GC.Collect();

                // FFT in place
                Fourier.FFT(cdata.Length, cdata);

                int n = cdata.Length / 2;

                // Now we have an array of complex, from 0Hz to Nyquist and back again.
                // We really only care about the first half of the cdata buffer, but
                // treat it as circular anyway (i.e. wrap around for negative values).
                //
                // We're only working with magnitudes from here on,
                // so we can save some space by computing mags right away and storing them in the
                // real part of the complex array; then we can use the imaginary portion for the
                // smoothed data.
                for (int j = 0; j < cdata.Length; j++)
                {
                    cdata[j].Re = cdata[j].Magnitude;
                    cdata[j].Im = 0;
                }

                // Take a rectangular window of width (resolution)*(octave or ERB band)
                // Add up all magnitudes falling within this window
                //
                // Move the window forward by one thingummajig
                //double wMid = 0;    // center of the window
                //double wLen = 0;
            }
            return(new FilterProfile()); // temp
        }
Exemplo n.º 3
0
        private static string ConvertSmoothingType(SmoothingType smoothingType)
        {
            switch (smoothingType)
            {
            case SmoothingType.Cubic:
                return(SR.LabelFilmSmoothingTypeCubic);

            default:
                return(smoothingType.ToString());
            }
        }
Exemplo n.º 4
0
    public GoSmoothedQuaternion( Quaternion quat )
    {
        _currentValue = quat;
        _start = quat;
        _target = quat;
        _startTime = Time.time;

        // set sensible defaults
        duration = 0.2f;
        smoothingType = SmoothingType.Lerp;
    }
Exemplo n.º 5
0
    public GoSmoothedQuaternion(Quaternion quat)
    {
        _currentValue = quat;
        _start        = quat;
        _target       = quat;
        _startTime    = Time.time;

        // set sensible defaults
        duration      = 0.2f;
        smoothingType = SmoothingType.Lerp;
    }
Exemplo n.º 6
0
    public GoSmoothedVector3(Vector3 vector)
    {
        _currentValue = vector;
        _start        = vector;
        _target       = vector;
        _startTime    = Time.time;

        // set sensible defaults
        duration      = 0.2f;
        smoothingType = SmoothingType.Lerp;
    }
Exemplo n.º 7
0
        public Chromatogram CreateSmoothChromatogram(SmoothingType smoothing, int points)
        {
            switch (smoothing)
            {
            case SmoothingType.BoxCar:
                double[] newTimes       = XArray.BoxCarSmooth(points);
                double[] newIntensities = YArray.BoxCarSmooth(points);
                return(new Chromatogram(newTimes, newIntensities, false));

            default:
                return(new Chromatogram(this));
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Change the smoothing type to the specified type.
        /// </summary>
        /// <param name="type">The type to change the value to.</param>
        private void ChangeInputType(SmoothingType type)
        {
            // Revert the old.
            SetButtonColor((int)m_SmoothingType, m_NormalColor);
            StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SmoothingType), m_SmoothingType), false);

            // Set the new smoothing type.
            m_SmoothingType = type;
            SetButtonColor((int)m_SmoothingType, m_PressedColor);
            StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SmoothingType), type), true);

            EnableInput();
        }
Exemplo n.º 9
0
        public Chromatogram Smooth(SmoothingType smoothing, int points)
        {
            switch (smoothing)
            {
            case SmoothingType.BoxCar:
                double[] newTimes       = _times.BoxCarSmooth(points);
                double[] newIntensities = _intensities.BoxCarSmooth(points);
                return(new Chromatogram(newTimes, newIntensities, false));

            case SmoothingType.SavitzkyGolay:
                throw new NotImplementedException();

            default:
                return(new Chromatogram(this));
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initialize the filter with a set of manually specified TransformSmoothParameters.
        /// </summary>
        /// <param name="smoothingValue">Smoothing = [0..1], lower values is closer to the raw data and more noisy.</param>
        /// <param name="correctionValue">Correction = [0..1], higher values correct faster and feel more responsive.</param>
        /// <param name="predictionValue">Prediction = [0..n], how many frames into the future we want to predict.</param>
        /// <param name="jitterRadiusValue">JitterRadius = The deviation distance in m that defines jitter.</param>
        /// <param name="maxDeviationRadiusValue">MaxDeviation = The maximum distance in m that filtered positions are allowed to deviate from raw data.</param>
        public void Init(float smoothingValue, float correctionValue, float predictionValue, float jitterRadiusValue, float maxDeviationRadiusValue)
        {
            this.smoothingType = SmoothingType.Default;
            smoothParameters   = new SmoothParameters();

            smoothParameters.smoothing          = smoothingValue;          // How much soothing will occur.  Will lag when too high
            smoothParameters.correction         = correctionValue;         // How much to correct back from prediction.  Can make things springy
            smoothParameters.prediction         = predictionValue;         // Amount of prediction into the future to use. Can over shoot when too high
            smoothParameters.jitterRadius       = jitterRadiusValue;       // Size of the radius where jitter is removed. Can do too much smoothing when too high
            smoothParameters.maxDeviationRadius = maxDeviationRadiusValue; // Size of the max prediction radius Can snap back to noisy data when too high

            // Check for divide by zero. Use an epsilon of a 10th of a millimeter
            smoothParameters.jitterRadius = Math.Max(0.0001f, this.smoothParameters.jitterRadius);

            Reset();
            init = true;
        }
Exemplo n.º 11
0
 public static SmoothingFunction GetSmoothingFunction(SmoothingType smoothingType)
 {
     switch (smoothingType)
      {
     case SmoothingType.Identity:
        return new SmoothingFunction(Identity);
     case SmoothingType.Sigmoid:
        return new SmoothingFunction(Sigmoid);
     case SmoothingType.Sigmoid2:
        return new SmoothingFunction(Sigmoid2);
     case SmoothingType.Sigmoid3:
        return new SmoothingFunction(Sigmoid3);
     case SmoothingType.Sigmoid4:
        return new SmoothingFunction(Sigmoid4);
     default:
        throw new System.Exception("Smoothing function not supported: " + smoothingType.ToString());
      }
 }
Exemplo n.º 12
0
        public static double WindowLength(int bin, int bins, double sampleRate, SmoothingType type, double resolution, out int bin0, out int bin1)
        {
            double len = 0;

            bin0 = bin;
            bin1 = bin;

            // Frequency (Hz) of the center of the given bin:
            // Bins range from 0 through sampleRate-1,
            // so the width of each bin is (sampleRate/bins) Hz,
            // and the center of bin <N> is (<N> * (sampleRate/bins)) + half a bin
            double binw = sampleRate / bins;
            double freq = (0.5 + bin) * binw;

            // The window goes from f0=(freq/X) to f1=(freq*X)
            // where the width of the window is (resolution)*(octaves or ERB bands)
            double bw = 0;

            if (type == SmoothingType.OCTAVE)
            {
                // Fraction X of an octave is f(x) = 2^x
                bw = freq * Math.Pow(2, resolution);
            }
            else if (type == SmoothingType.ERB)
            {
                bw = ERB.ERBWidth(freq) * resolution;
            }

            // f.x - f/x = bw
            // f.x.x - bw.x - f = 0
            // f.x.(x-(bw/f)) = f
            // x.(x-(bw/f)) = 1
            // x.x - bw.x - 1/

            if (type == SmoothingType.OCTAVE)
            {
                // One octave is frequency*2.  Two is freq*4.
                // Fraction X of an octave is f(x) = 2^x
//                double f1 = freq * (1 - Math.Pow(2, r2));
//                double f2 = freq * (1 - Math.Pow(2, r2));
            }

            return(len * resolution);
        }
Exemplo n.º 13
0
        // Initialize the filter with a set of SmoothParameters.
        public void Init(SmoothingType smoothingType)
        {
            this.smoothingType = smoothingType;
            smoothParameters   = new SmoothParameters();

            switch (smoothingType)
            {
            case SmoothingType.Light:
                smoothParameters.smoothing          = 0.3f;
                smoothParameters.correction         = 0.35f;
                smoothParameters.prediction         = 0.35f;
                smoothParameters.jitterRadius       = 0.15f;
                smoothParameters.maxDeviationRadius = 0.15f;
                break;

            case SmoothingType.Medium:
                smoothParameters.smoothing          = 0.5f;
                smoothParameters.correction         = 0.1f;
                smoothParameters.prediction         = 0.5f;
                smoothParameters.jitterRadius       = 0.1f;
                smoothParameters.maxDeviationRadius = 0.1f;
                break;

            case SmoothingType.Aggressive:
                smoothParameters.smoothing          = 0.7f;
                smoothParameters.correction         = 0.3f;
                smoothParameters.prediction         = 1.0f;
                smoothParameters.jitterRadius       = 1.0f;
                smoothParameters.maxDeviationRadius = 1.0f;
                break;

            //case SmoothingType.Default:
            default:
                smoothParameters.smoothing          = 0.5f;
                smoothParameters.correction         = 0.5f;
                smoothParameters.prediction         = 0.5f;
                smoothParameters.jitterRadius       = 0.05f;
                smoothParameters.maxDeviationRadius = 0.04f;
                break;
            }

            Reset();
            init = true;
        }
Exemplo n.º 14
0
 public static SmoothingFunction Function(SmoothingType type) {
     switch (type) {
         case SmoothingType.Linear: return Linear;
         case SmoothingType.Hermite3: return Hermite3;
         case SmoothingType.Hermite5: return Hermite5;
         case SmoothingType.Hermite7: return Hermite7;
         case SmoothingType.Power2: return Power2;
         case SmoothingType.Power3: return Power3;
         case SmoothingType.Power4: return Power4;
         case SmoothingType.Root2: return Root2;
         case SmoothingType.Root3: return Root3;
         case SmoothingType.Root4: return Root4;
         case SmoothingType.CircleX: return CircleX;
         case SmoothingType.CircleY: return CircleY;
         case SmoothingType.CircleXY: return CircleXY;
         case SmoothingType.CircleYX: return CircleYX;
     }
     return null;
 }
Exemplo n.º 15
0
        public static Smoother GetSmoother(SmoothingType type)
        {
            switch (type)
            {
            case SmoothingType.Linear:
                return(new LinearSmoother());

            case SmoothingType.Lerp:
                return(new LerpSmoother());

            case SmoothingType.Accurate:
                return(new AccurateSmoother());

            case SmoothingType.Adaptive:
                return(new AdaptiveSmoother());

            default:
                return(null);
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// Change the smoothing type to the specified type.
        /// </summary>
        /// <param name="type">The type to change the value to.</param>
        private void ChangeInputType(SmoothingType type)
        {
            // Revert the old.
            m_ButtonImages[(int)m_SmoothingType].color = m_NormalColor;
            var buttonColors = m_Buttons[(int)m_SmoothingType].colors;

            buttonColors.normalColor = m_NormalColor;
            m_Buttons[(int)m_SmoothingType].colors = buttonColors;
            StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SmoothingType), m_SmoothingType), false);

            // Set the new smoothing type.
            m_SmoothingType = type;
            m_ButtonImages[(int)m_SmoothingType].color = m_PressedColor;
            buttonColors             = m_Buttons[(int)m_SmoothingType].colors;
            buttonColors.normalColor = m_PressedColor;
            m_Buttons[(int)m_SmoothingType].colors = buttonColors;
            StateManager.SetState(m_ActiveCharacter, System.Enum.GetName(typeof(SmoothingType), type), true);

            EnableInput();
        }
Exemplo n.º 17
0
        public override void LoadParametersV2(XElement xElement)
        {
            UseSmoothing  = GetBoolVal(xElement, "ApplySavitzkyGolay", UseSmoothing);
            SmoothingType = (Globals.SmoothingType)GetEnum(xElement, "SmoothingType", SmoothingType.GetType(), SmoothingType);  //Smoothing type does not yet exist in parameter file

            var smoothLeft  = GetIntValue(xElement, "SGNumLeft", (SavitzkyGolayNumPointsInSmooth - 1) / 2);
            var smoothRight = GetIntValue(xElement, "SGNumRight", (SavitzkyGolayNumPointsInSmooth - 1) / 2);

            SavitzkyGolayNumPointsInSmooth = smoothLeft + smoothRight + 1;
            SavitzkyGolayOrder             = GetIntValue(xElement, "SGOrder", SavitzkyGolayOrder);

            UseZeroFilling            = GetBoolVal(xElement, "ZeroFillDiscontinousAreas", UseZeroFilling);
            ZeroFillingNumZerosToFill = GetIntValue(xElement, "NumZerosToFill", ZeroFillingNumZerosToFill);

            SaturationThreshold = GetDoubleValue(xElement, "SaturationThreshold", SaturationThreshold);

            MaxMinutesPerScan  = GetIntValue(xElement, "MaxMinutesPerScan", MaxMinutesPerScan);
            MaxMinutesPerFrame = GetIntValue(xElement, "MaxMinutesPerFrame", MaxMinutesPerFrame);
            MaxHoursPerDataset = GetIntValue(xElement, "MaxHoursPerDataset", MaxHoursPerDataset);
        }
Exemplo n.º 18
0
        public new MassRangeChromatogram Smooth(SmoothingType smoothing, int points)
        {
            Chromatogram chrom = base.Smooth(smoothing, points);

            return(new MassRangeChromatogram(chrom, Range));
        }
Exemplo n.º 19
0
        public static FilterProfile Profile(ISoundObj impulse, SmoothingType type, double resolution)
        {
            uint nSR = impulse.SampleRate;
            uint nSR2 = nSR / 2;

            ushort nChannels = impulse.NumChannels;
            for (ushort c = 0; c < nChannels; c++)
            {
                // Read channel into a buffer
                SingleChannel channel = impulse.Channel(c);
                SoundBuffer buff = new SoundBuffer(channel);
                buff.ReadAll();

                // And then double in length to prevent wraparound
                buff.PadTo(buff.Count * 2);
                // Pad to next higher power of two
                buff.PadToPowerOfTwo();
                // Read out into array of complex
                Complex[][] data = buff.ToComplexArray();
                Complex[] cdata = data[0];

                // Then we're done with the buffer for this channel
                buff = null;
                GC.Collect();

                // FFT in place
                Fourier.FFT(cdata.Length, cdata);

                int n = cdata.Length / 2;

                // Now we have an array of complex, from 0Hz to Nyquist and back again.
                // We really only care about the first half of the cdata buffer, but
                // treat it as circular anyway (i.e. wrap around for negative values).
                //
                // We're only working with magnitudes from here on,
                // so we can save some space by computing mags right away and storing them in the
                // real part of the complex array; then we can use the imaginary portion for the
                // smoothed data.
                for (int j = 0; j < cdata.Length; j++)
                {
                    cdata[j].Re = cdata[j].Magnitude;
                    cdata[j].Im = 0;
                }

                // Take a rectangular window of width (resolution)*(octave or ERB band)
                // Add up all magnitudes falling within this window
                //
                // Move the window forward by one thingummajig
                //double wMid = 0;    // center of the window
                //double wLen = 0;
            }
            return new FilterProfile(); // temp
        }
Exemplo n.º 20
0
        public static double WindowLength(int bin, int bins, double sampleRate, SmoothingType type, double resolution, out int bin0, out int bin1)
        {
            double len = 0;
            bin0 = bin;
            bin1 = bin;

            // Frequency (Hz) of the center of the given bin:
            // Bins range from 0 through sampleRate-1,
            // so the width of each bin is (sampleRate/bins) Hz,
            // and the center of bin <N> is (<N> * (sampleRate/bins)) + half a bin
            double binw = sampleRate / bins;
            double freq = (0.5 + bin) * binw;

            // The window goes from f0=(freq/X) to f1=(freq*X)
            // where the width of the window is (resolution)*(octaves or ERB bands)
            double bw = 0;
            if (type == SmoothingType.OCTAVE)
            {
                // Fraction X of an octave is f(x) = 2^x
                bw = freq * Math.Pow(2, resolution);
            }
            else if(type==SmoothingType.ERB)
            {
                bw = ERB.ERBWidth(freq)*resolution;
            }

            // f.x - f/x = bw
            // f.x.x - bw.x - f = 0
            // f.x.(x-(bw/f)) = f
            // x.(x-(bw/f)) = 1
            // x.x - bw.x - 1/

            if (type == SmoothingType.OCTAVE)
            {
                // One octave is frequency*2.  Two is freq*4.
                // Fraction X of an octave is f(x) = 2^x
            //                double f1 = freq * (1 - Math.Pow(2, r2));
            //                double f2 = freq * (1 - Math.Pow(2, r2));
            }

            return len * resolution;
        }
Exemplo n.º 21
0
 public new MassRangeChromatogram Smooth(SmoothingType smoothing, int points)
 {
     Chromatogram chrom = base.Smooth(smoothing, points);
     return new MassRangeChromatogram(chrom, Range);
 }