private void getPxxFx(ComplexArray signal, double samplingRate, out DoubleArray Pxx, out DoubleArray Fx) { //Implements Matlab's PWelch. Same as [Pxx, Fx] = pwelch(x, w, 0, nfft, Fs), where x = signal, w is calculated below, nfft = signal.count, Fs = samplingRate (hz) int Nx = signal.Count; DoubleArray w = DoubleArray.From(hamming(Nx)); double std = w.Std(); double mean = w.Mean(); ComplexArray xw = signal.ElementMultiply(w); int nfft = Nx; ComplexArray X = FFTComp.FFTComplex(xw); DoubleArray absX = X.Abs(); DoubleArray mx = absX.ElementMultiply(absX); DoubleArray wt = w.Transpose(); double res = w.Multiply(wt)[0]; mx = mx.Divide(res); int numUniquePts = nfft / 2 + 1; Slice slice = new Slice(0, numUniquePts - 1); mx = mx.GetSlice(slice); double temp1 = mx[0]; double temp2 = mx[mx.Count - 1]; mx = mx.Multiply(2); mx[0] = temp1; mx[mx.Count - 1] = temp2; Pxx = mx.Divide(samplingRate); Fx = getFx(numUniquePts, samplingRate, nfft); w.Dispose(); absX.Dispose(); mx.Dispose(); wt.Dispose(); }
private void GetPxxFx(ComplexArray signal, out DoubleArray Pxx, out DoubleArray Fx) { ComplexArray X = FFTComp.FFTComplex(signal); Pxx = X.Abs(); Fx = GetFx(signal.Length); X.Dispose(); }