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 bool GenerateFilterMatrix(bool UseMeasuredSignal = false) { if (matchedFilterEnabled) { Debug.WriteLine("Generating beaconsignal."); FileInfo beaconfile = new FileInfo(@"resources/beaconfile.bin"); if (beaconfile.Exists && UseMeasuredSignal) { long samples = beaconfile.Length / 4; //singles beaconsignal = DenseVector.Create(Convert.ToInt32(samples), 0); using (BinaryReader br = new BinaryReader(beaconfile.OpenRead())) { int i = 0; while (i < samples) { beaconsignal[i] = br.ReadSingle(); i++; } } Debug.WriteLine("Used measurement data for beaconsignal."); } else { //Own Code: e65a 20e5 b37a c60d beaconsignal = Tools.refsignal(Tools.Timer0Freq.Carrier10kHz, Tools.Timer1Freq.Code2500Hz, Tools.Timer3Freq.Repeat10Hz, "e65a20e5", ASIO.Fs); Debug.WriteLine("Used reference data for beaconsignal."); } int endpoint = beaconsignal.Count-1; while (beaconsignal[endpoint] == 0 && endpoint > 0) { endpoint--; } int startpoint = 0; while (beaconsignal[startpoint] == 0 && startpoint < endpoint) { startpoint++; } beaconsignal = beaconsignal.SubVector(startpoint, endpoint - startpoint); //Trimmed int samplenumber = 0; Vector<double> bsreverse = new DenseVector(beaconsignal.Count); // WAS: Convert.ToInt32(Math.Round(ASIO.Fs * sampleLength)) //samplenumber = 0; foreach (double d in beaconsignal.Reverse()) { bsreverse[samplenumber] = d; samplenumber++; if (samplenumber == bsreverse.Count) break; } if (!matchedFilterToep) { // Get the matchedfilter convolution vector matchedfilterVector = bsreverse; } else { //Circulant Convolution Debug.WriteLine("Generating Toeplitz matrix."); //Figure out corrent matchedfilter matrix //Normal Convolution //Matrix<double> X = Tools.Toep(bsreverse, bsreverse.Count*2-1, bsreverse.Count, false); //Circulant Convolution Matrix<double> X = Tools.Toep(bsreverse, bsreverse.Count, bsreverse.Count); bsreverse = null; Debug.WriteLine("Generating matched filter matrix."); //X is a circulant matrix. matchedfilter = X; } } else { Debug.WriteLine("Matched filter is disabled."); } return true; }