/// <summary> /// Performs the convolution of two real signals. The real result is returned. /// </summary> /// <remarks>Requires <paramref name="excitation"/> and <paramref name="impulse"/> /// to match in a length of a power of 2.</remarks> public static float[] Convolve(float[] excitation, float[] impulse, FFTCache cache = null) { Complex[] result = cache != null? ConvolveFourier(excitation, impulse, cache) : ConvolveFourier(excitation, impulse); result.InPlaceIFFT(); return(Measurements.GetRealPart(result)); }
/// <summary> /// Gets a linear phase convolution filter that results in this EQ when applied. /// </summary> /// <param name="eq">Source <see cref="Equalizer"/></param> /// <param name="sampleRate">Sample rate of the target system the convolution filter could be used on</param> /// <param name="length">Length of the convolution filter in samples, must be a power of 2</param> /// <param name="gain">Signal voltage multiplier</param> /// <param name="initial">Custom initial spectrum to apply the EQ on - phases will be corrected, this is not convolved, /// and has to be twice the size of <paramref name="length"/></param> public static float[] GetLinearConvolution(this Equalizer eq, int sampleRate, int length = 1024, float gain = 1, Complex[] initial = null) { Complex[] filter = new Complex[length]; if (initial == null) { for (int i = 0; i < length; ++i) { filter[i].Real = i % 2 == 0 ? gain : -gain; // FFT of DiracDelta(x - length/2) } } else { for (int i = 0; i < length; ++i) { filter[i].Real = initial[i].Magnitude * (i % 2 == 0 ? gain : -gain); } } eq.Apply(filter, sampleRate); filter.InPlaceIFFT(); return(Measurements.GetRealPart(filter)); }