public IEnumerable <Point> Filtration(int M, double fo, IEnumerable <Point> points, IWindow window, FilterType filterType) { var fp = 1 / (points.ElementAt(1).X - points.ElementAt(0).X); if (filterType == FilterType.HighPassFilter) { fo = fp / 2 - fo; } var response = new List <Point>(); var K = fp / fo; for (var i = 0; i < M; i++) { response.Add(new Point(i, ImpulseResponse.Response(i, K, M) * window.Window(i, M) * filterTypes[filterType](i))); } var ret = Convolution.Convolute(points, response); var amplitude = ret.Select(p => p.Y).Max() * 2; amplitude = points.Select(p => p.Y).Max() / amplitude; foreach (var point in ret) { point.Y *= amplitude; } return(ret); }
/// <summary> /// Create a filter to remove low frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateHighpass(ImpulseResponse mode, double sampleRate, double cutoffRate) { return(CreateHighpass( mode, sampleRate, cutoffRate, mode == ImpulseResponse.Finite ? 64 : 4)); // order }
/// <summary> /// Create a filter to remove middle (all but low and high) frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateBandstop(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate) { return(CreateBandstop( mode, sampleRate, cutoffLowRate, cutoffHighRate, mode == ImpulseResponse.Finite ? 64 : 4)); // order }
/// <summary> /// Create a filter to remove low and high frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateBandpass(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate) { return CreateBandpass( mode, sampleRate, cutoffLowRate, cutoffHighRate, mode == ImpulseResponse.Finite ? 64 : 4); // order }
/// <summary> /// Samples the input stream and applies a high-pass filter (using MathNet.Filtering) over the sampled input stream. Removes low frequencies. /// </summary> /// <param name="input">The input source of doubles.</param> /// <param name="sampleRate">The desired sample rate for the filter.</param> /// <param name="cutoffRate">The desired cutoff for the filter.</param> /// <param name="impulseResponse">Specifies how the filter will respond to an impulse input (Finite or Infinite). Default is Finite.</param> /// <param name="sampleInterpolator">Optional sampling interpolator over the input. Default is a reproducible linear interpolation.</param> /// <param name="alignmentDateTime">If non-null, this parameter specifies a time to align the sampled messages with, and the sampled messages /// will have originating times that align with (i.e., are an integral number of intervals away from) the specified alignment time.</param> /// <param name="deliveryPolicy">An optional delivery policy for the input stream.</param> /// <returns>A high-pass filtered version of the input.</returns> public static IProducer <double> HighpassFilter( this IProducer <double> input, double sampleRate, double cutoffRate, ImpulseResponse impulseResponse = ImpulseResponse.Finite, Interpolator <double, double> sampleInterpolator = null, DateTime?alignmentDateTime = null, DeliveryPolicy <double> deliveryPolicy = null) { var filter = OnlineFilter.CreateHighpass(impulseResponse, sampleRate, cutoffRate); return(MathNetFilter(input, sampleRate, sampleInterpolator ?? Reproducible.Linear(), alignmentDateTime, filter, deliveryPolicy)); }
CreateLowpass( ImpulseResponse mode, double sampleRate, double cutoffRate ) { return(CreateLowpass( mode, sampleRate, cutoffRate, mode == ImpulseResponse.Finite ? 64 : 4 // order )); }
CreateBandstop( ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate ) { return(CreateBandstop( mode, sampleRate, cutoffLowRate, cutoffHighRate, mode == ImpulseResponse.Finite ? 64 : 4 // order )); }
/// <summary> /// Create a filter to remove middle (all but low and high) frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateBandstop(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate, int order) { if (mode == ImpulseResponse.Finite) { double[] c = FirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate, order >> 1); return(new OnlineFirFilter(c)); } if (mode == ImpulseResponse.Infinite) { double[] c = IirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate); return(new OnlineIirFilter(c)); } throw new ArgumentException("mode"); }
/// <summary> /// Create a filter to remove middle (all but low and high) frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateBandstop(ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate, int order) { if (mode == ImpulseResponse.Finite) { double[] c = FirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate, order >> 1); return new OnlineFirFilter(c); } if (mode == ImpulseResponse.Infinite) { double[] c = IirCoefficients.BandStop(sampleRate, cutoffLowRate, cutoffHighRate); return new OnlineIirFilter(c); } throw new ArgumentException("mode"); }
/// <summary> /// Create a filter to remove low frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateHighpass(ImpulseResponse mode, double sampleRate, double cutoffRate, int order) { if (mode == ImpulseResponse.Finite) { double[] c = FirCoefficients.HighPass(sampleRate, cutoffRate, order >> 1); return(new OnlineFirFilter(c)); } if (mode == ImpulseResponse.Infinite) { // TODO: investigate (bandwidth) double[] c = IirCoefficients.HighPass(sampleRate, cutoffRate, cutoffRate); return(new OnlineIirFilter(c)); } throw new ArgumentException("mode"); }
CreateBandpass( ImpulseResponse mode, double sampleRate, double cutoffLowRate, double cutoffHighRate, int order ) { if (mode == ImpulseResponse.Finite) { double[] c = FIR.FirCoefficients.BandPass(sampleRate, cutoffLowRate, cutoffHighRate, order >> 1); return(new FIR.OnlineFirFilter(c)); } if (mode == ImpulseResponse.Infinite) { double[] c = IIR.IirCoefficients.BandPass(sampleRate, cutoffLowRate, cutoffHighRate); return(new IIR.OnlineIirFilter(c)); } throw new ArgumentException("mode"); }
/// <summary> /// Create a filter to remove high frequencies in online processing scenarios. /// </summary> public static OnlineFilter CreateLowpass(ImpulseResponse mode, double sampleRate, double cutoffRate, int order) { if (mode == ImpulseResponse.Finite) { double[] c = FirCoefficients.LowPass(sampleRate, cutoffRate, order >> 1); return new OnlineFirFilter(c); } if (mode == ImpulseResponse.Infinite) { // TODO: investigate (bandwidth) double[] c = IirCoefficients.LowPass(sampleRate, cutoffRate, cutoffRate); return new OnlineIirFilter(c); } throw new ArgumentException("mode"); }