public Vector<double> butterworth(Vector<double> signal, double fs, double fc, int order, Filtr_Type type) { //TODO: Comments int L = signal.Count; int DCGain = 1; double[] DoubleArray = new double[L]; DoubleArray = signal.ToArray(); Complex[] ComplexArray = new Complex[L]; for (int i = 0; i < L; i++) { ComplexArray[i] = new Complex(DoubleArray[i], 0); } Fourier.Forward(ComplexArray, FourierOptions.Matlab); double binWidth, binFreq, gain; if (fc > 0) { binWidth = fs / L; for(int i = 0; i < (L/2); i++) { binFreq = binWidth * (i+1); gain = DCGain / Math.Sqrt(1 + Math.Pow(binFreq/fc, 2.0 * order)); if (type == Filtr_Type.HIGHPASS) { gain = 1 - gain; } ComplexArray[i] *= gain; ComplexArray[L - 1 - i] *= gain; } } Fourier.Inverse(ComplexArray, FourierOptions.Matlab); for (int i = 0; i < L; i++) { DoubleArray[i] = ComplexArray[i].Real; } Vector<double> output_signal = Vector<double>.Build.DenseOfArray(DoubleArray); return output_signal; }
public static string ConvertToString(BigInteger n, bool escape, int radix) { if (radix == -1) { radix = (int)Runtime.GetDynamic(Symbols.PrintBase); } if (radix == -1) { radix = 10; } else if (radix < 2 || radix > 36) { throw new LispException("Invalid number base: {0}", radix); } if (n == 0) { return "0"; } var sign = (n >= 0) ? "" : "-"; n = (n >= 0) ? n : -n; var stk = new Vector(); while (n != 0) { var d = (int)(n % radix); if (d <= 9) { stk.Add((char)(d + '0')); } else { stk.Add((char)(d - 10 + 'a')); } n = n / radix; } stk.Reverse(); if (escape) { switch (radix) { case 10: return sign + Runtime.MakeString(stk.ToArray()); case 16: return sign + "0x" + Runtime.MakeString(stk.ToArray()); case 8: return sign + "0" + Runtime.MakeString(stk.ToArray()); case 2: return "#b" + sign + Runtime.MakeString(stk.ToArray()); default: return "#" + radix + "r" + sign + Runtime.MakeString(stk.ToArray()); } } else { return sign + Runtime.MakeString(stk.ToArray()); } }
public static string WriteToString(object item, params object[] kwargs) { using (var stream = new StringWriter()) { var kwargs2 = new Vector(kwargs); kwargs2.Add(Symbols.Stream); kwargs2.Add(stream); Write(item, kwargs2.ToArray()); return stream.ToString(); } }