/// <summary> /// In-place signal attenuation by coeff /// </summary> /// <param name="signal"></param> /// <param name="coeff"></param> public static void Attenuate(this DiscreteSignal signal, float coeff) { if (Math.Abs(coeff) < 1e-10) { throw new ArgumentException("Attenuation coefficient can't be zero"); } signal.Amplify(1 / coeff); }
/// <summary> /// Normalizes <paramref name="signal"/> by its max absolute value (to range [-1, 1]). /// </summary> /// <param name="signal">Signal</param> /// <param name="bitsPerSample">Bit depth</param> public static void NormalizeMax(this DiscreteSignal signal, int bitsPerSample = 0) { var norm = 1 / signal.Samples.Max(s => Math.Abs(s)); if (bitsPerSample > 0) { norm *= (float)(1 - 1 / Math.Pow(2, bitsPerSample)); } signal.Amplify(norm); }
/// <summary> /// In-place signal attenuation by coeff /// </summary> /// <param name="signal"></param> /// <param name="coeff"></param> public static void Attenuate(this DiscreteSignal signal, float coeff) { Guard.AgainstNonPositive(coeff, "Attenuation coefficient"); signal.Amplify(1 / coeff); }