/// <summary> /// Compute complex analytic signal /// </summary> /// <param name="samples">Array of samples</param> /// <returns>Complex analytic signal</returns> public ComplexDiscreteSignal AnalyticSignal(double[] samples) { var analyticSignal = new ComplexDiscreteSignal(1, samples); var re = analyticSignal.Real; var im = analyticSignal.Imag; _fft.Direct(re, im); for (var i = 1; i < re.Length / 2; i++) { re[i] *= 2; im[i] *= 2; } for (var i = re.Length / 2 + 1; i < re.Length; i++) { re[i] = 0.0; im[i] = 0.0; } _fft.Inverse(re, im); return(analyticSignal); }
/// <summary> /// Does Fast Hilbert Transform. /// </summary> /// <param name="input">Input data</param> /// <param name="output">Output data</param> public void Direct(double[] input, double[] output) { // just here, for code brevity, use alias _im for output (i.e. it's not internal _im) var _im = output; Array.Clear(_re, 0, _re.Length); Array.Clear(_im, 0, _im.Length); input.FastCopyTo(_re, input.Length); _fft.Direct(_re, _im); for (var i = 1; i < _re.Length / 2; i++) { _re[i] *= 2; _im[i] *= 2; } for (var i = _re.Length / 2 + 1; i < _re.Length; i++) { _re[i] = 0.0f; _im[i] = 0.0f; } _fft.Inverse(_re, _im); }
/// <summary> /// Compute complex analytic signal, double precision /// </summary> /// <param name="samples">Array of samples</param> /// <param name="norm">Normalize by fft size</param> /// <returns>Complex analytic signal</returns> public ComplexDiscreteSignal AnalyticSignal(double[] samples, bool norm = true) { var analyticSignal = new ComplexDiscreteSignal(1, samples); var re = analyticSignal.Real; var im = analyticSignal.Imag; _fft64.Direct(re, im); for (var i = 1; i < re.Length / 2; i++) { re[i] *= 2; im[i] *= 2; } for (var i = re.Length / 2 + 1; i < re.Length; i++) { re[i] = 0.0; im[i] = 0.0; } _fft64.Inverse(re, im); if (norm) { analyticSignal.Attenuate(re.Length); } return(analyticSignal); }