/// <summary> /// Windowd Sinc method /// </summary> /// <param name="length">Length</param> /// <param name="bw">Bandwidth</param> /// <returns></returns> public static double[] WindowedSinc_max(int length, double bw) { // http://www.dspguide.com/ch16/1.htm int i = 0; int bwl = 0; // integer transition bandwidth double tbw; // double transition bandwidth double[] h; // kernel double x; // position in the antiderivate of the Blackman function of the sample we're at double coef; // coefficient obtained from the function tbw = bw * (double)(length - 1); bwl = GlobalMembersUtil.RoundUp(tbw); h = new double[length]; for (i = 1; i < length; i++) { h[i] = 1.0; } for (i = 0; i < bwl; i++) { x = (double)i / tbw; // position calculation between 0.0 and 1.0 // antiderivative of the Blackman window function coef = 0.42 * x - (0.5 / (2.0 * PI)) * Math.Sin(2.0 * PI * x) + (0.08 / (4.0 * PI)) * Math.Sin(4.0 * PI * x); coef *= 1.0 / 0.42; h[i + 1] = coef; h[length - 1 - i] = coef; } return(h); }
/// <summary> /// Downsampling of the signal by a Blackman function /// </summary> /// <param name="in">Signal</param> /// <param name="Mi">Mi is the original signal's length</param> /// <param name="Mo">Mo is the output signal's length</param> /// <returns>Downsampled Signal</returns> public static double[] BlackmanDownsampling(double[] @in, int Mi, int Mo) { int i = 0; // general purpose iterators int j = 0; double[] @out = new double[Mo]; double pos_in; // position in the original signal double x; // position of the iterator in the blackman(x) formula double ratio; // scaling ratio (> 1.0) double ratio_i; // ratio^-1 double coef; // Blackman coefficient double coef_sum; // sum of coefficients, used for weighting /* * Mi is the original signal's length * Mo is the output signal's length */ ratio = (double)Mi / Mo; ratio_i = 1.0 / ratio; for (i = 0; i < Mo; i++) { pos_in = (double)i * ratio; coef_sum = 0; for (j = GlobalMembersUtil.RoundUp(pos_in - ratio); j <= pos_in + ratio; j++) { if (j >= 0 && j < Mi) // if the read sample is within bounds { x = j - pos_in + ratio; // calculate position within the Blackman function coef = 0.42 - 0.5 * Math.Cos(PI * x * ratio_i) + 0.08 * Math.Cos(2 * PI * x * ratio_i); coef_sum += coef; @out[i] += @in[j] * coef; // convolve } } @out[i] /= coef_sum; } return(@out); }