public static Tuple <double, double>[] FFTSpectr(double[] signal, int sd, int d, int osframe, int lastInData) { int size = 1 << osframe; var ret = new Tuple <double, double> [size]; var Frame = new Complex[size]; for (int i = 0; i < size; i++) { Frame[i] = 0; if (i * d < lastInData && i * d + sd < signal.Length) { Frame[i] = new Complex(signal[i * d + sd] * WindowFilters.Gausse(i, lastInData), 0); } } var spectr = DecimationInTime(Frame, false); for (var i = 0; i < spectr.Length; i++) { spectr[i] /= size; } for (int i = 0; i < size; i++) { ret[i] = new Tuple <double, double>(i, spectr[i].Magnitude); } return(ret); }
public static double[,] WindowFFT(double[] signal, int WindowSize) { double[,] ret = new double[signal.Length, WindowSize]; for (int q = WindowSize / 2; q < signal.Length; q += 1) { var convertSignal = new double[WindowSize]; for (int i = 0; i < WindowSize; i++) { convertSignal[i] = 0; if (i + q < signal.Length) { convertSignal[i] = signal[i + q - WindowSize / 2] * WindowFilters.Gausse(i, WindowSize); } } var FFT = DecimationInTime(convertSignal.Select(x => { return(new Complex(x, 0)); }).ToArray(), false); for (var i = 0; i < FFT.Length; i++) { FFT[i] /= WindowSize; } for (int i = 0; i < WindowSize; i++) { ret[q, i] = FFT[i].Magnitude; } } return(ret); }
public static double[,] WindowFFTParalell(double[] signal, int WindowSize, int step, int d, int st) { double[,] ret = new double[signal.Length / step, WindowSize / d / 2]; var tasks = new List <Task>(); //for (int q = WindowSize / 2; q < signal.Length/ step; q ++ ) //{ // int pq = q* step; // var t = new Task(() => // { // var convertSignal = new double[WindowSize]; // for (int i = 0; i < WindowSize; i++) // { // convertSignal[i] = 0; // if (i*d + pq < signal.Length) // convertSignal[i] = signal[i*d + pq - WindowSize / 2] * WindowFilters.Gausse(i, WindowSize); // } // var FFT = DecimationInTime(convertSignal.Select(x => { return new Complex(x, 0); }).ToArray(), false); // for (var i = 0; i < FFT.Length; i++) // { // FFT[i] /= WindowSize; // } // for (int i = 0; i < WindowSize; i++) // { // ret[pq/ step, i] = FFT[i].Magnitude; // } // }); // tasks.Add(t); // t.Start(); //} for (int q = 0; q < signal.Length - step + 1; q += step) { int pq = q; var t = new Task(() => { var convertSignal = new double[WindowSize]; for (int i = 0; i < WindowSize / d; i++) { convertSignal[i] = 0; if (pq + (i - WindowSize / 2) * d > 0 && pq + (i - WindowSize / 2) * d < signal.Length) { convertSignal[i] = signal[pq + (i - WindowSize / 2) * d] * WindowFilters.Gausse(i, WindowSize); } } var FFT = FFTSpectr(convertSignal, 0, 1, st, WindowSize / d); for (int i = 0; i < WindowSize / d / 2; i++) { ret[pq / step, i] = FFT[i].Item2; } //var FFT = DecimationInTime(convertSignal.Select(x => { return new Complex(x, 0); }).ToArray(), false); //for (int i = 0; i < WindowSize; i++) //{ // ret[pq / step, i] = FFT[i].Magnitude; //} }); tasks.Add(t); t.Start(); } Task.WaitAll(tasks.ToArray()); return(ret); }