Esempio n. 1
0
        /// <summary>
        /// Minimizes the phase of a spectrum.
        /// </summary>
        /// <remarks>This function does not handle zeros in the spectrum.
        /// Make sure there is a threshold before using this function.</remarks>
        public static void MinimumPhaseSpectrum(Complex[] response, FFTCache cache = null)
        {
            bool customCache = false;

            if (cache == null)
            {
                cache       = new FFTCache(response.Length);
                customCache = true;
            }
            int halfLength = response.Length / 2;

            for (int i = 0; i < response.Length; ++i)
            {
                response[i] = Complex.Log(response[i].Real);
            }
            if (CavernAmp.Available)
            {
                CavernAmp.InPlaceIFFT(response, cache);
            }
            else
            {
                response.InPlaceIFFT(cache);
            }
            for (int i = 1; i < halfLength; ++i)
            {
                response[i].Real      += response[^ i].Real;
Esempio n. 2
0
 /// <summary>
 /// Fast Fourier transform a 1D signal.
 /// </summary>
 public static Complex[] FFT(this float[] samples, FFTCache cache)
 {
     Complex[] complexSignal = new Complex[samples.Length];
     for (int sample = 0; sample < samples.Length; ++sample)
     {
         complexSignal[sample].Real = samples[sample];
     }
     complexSignal.InPlaceFFT(cache);
     return(complexSignal);
 }
Esempio n. 3
0
 /// <summary>
 /// Inverse Fast Fourier Transform of a transformed signal, while keeping the source array allocation.
 /// </summary>
 public static void InPlaceIFFT(this Complex[] samples)
 {
     if (CavernAmp.Available)
     {
         CavernAmp.InPlaceIFFT(samples);
         return;
     }
     using FFTCache cache = new FFTCache(samples.Length);
     samples.InPlaceIFFT(cache);
 }
Esempio n. 4
0
 public static void InPlaceFFT(this Complex[] samples, FFTCache cache)
 {
     if (CavernAmp.Available)
     {
         CavernAmp.InPlaceFFT(samples, cache);
     }
     else
     {
         ProcessFFT(samples, cache, QMath.Log2(samples.Length) - 1);
     }
 }
Esempio n. 5
0
 public static void InPlaceFFT(this float[] samples, FFTCache cache)
 {
     if (CavernAmp.Available)
     {
         CavernAmp.InPlaceFFT(samples, cache);
     }
     else
     {
         ProcessFFT(samples, cache);
     }
 }
Esempio n. 6
0
 /// <summary>
 /// Apply a delay on the <paramref name="signal"/> even with fraction <paramref name="samples"/>.
 /// </summary>
 public static void Delay(float[] signal, float samples, FFTCache cache)
 {
     Complex[] fft = signal.ParseForFFT();
     fft.InPlaceFFT(cache);
     Delay(signal, samples, cache);
     fft.InPlaceIFFT(cache);
     for (int i = 0; i < signal.Length; ++i)
     {
         signal[i] = fft[i].Real;
     }
 }
Esempio n. 7
0
 public static void InPlaceFFT(this float[] samples)
 {
     if (CavernAmp.Available)
     {
         CavernAmp.InPlaceFFT(samples);
     }
     else
     {
         using FFTCache cache = new FFTCache(samples.Length);
         ProcessFFT(samples, cache);
     }
 }
Esempio n. 8
0
 /// <summary>
 /// Inverse Fast Fourier Transform of a transformed signal.
 /// </summary>
 public static Complex[] IFFT(this Complex[] samples, FFTCache cache)
 {
     samples = samples.FastClone();
     if (CavernAmp.Available)
     {
         CavernAmp.InPlaceIFFT(samples, cache);
     }
     else
     {
         samples.InPlaceIFFT(cache);
     }
     return(samples);
 }
Esempio n. 9
0
 /// <summary>
 /// Inverse Fast Fourier Transform of a transformed signal.
 /// </summary>
 public static Complex[] IFFT(this Complex[] samples)
 {
     if (CavernAmp.Available)
     {
         samples = samples.FastClone();
         CavernAmp.InPlaceIFFT(samples);
     }
     else
     {
         using FFTCache cache = new FFTCache(samples.Length);
         samples.InPlaceIFFT(cache);
     }
     return(samples);
 }
Esempio n. 10
0
        /// <summary>
        /// Inverse Fast Fourier Transform of a transformed signal, while keeping the source array allocation.
        /// </summary>
        public static void InPlaceIFFT(this Complex[] samples, FFTCache cache)
        {
            if (CavernAmp.Available)
            {
                CavernAmp.InPlaceIFFT(samples, cache);
                return;
            }
            ProcessIFFT(samples, cache, QMath.Log2(samples.Length) - 1);
            float multiplier = 1f / samples.Length;

            for (int i = 0; i < samples.Length; ++i)
            {
                samples[i].Real      *= multiplier;
                samples[i].Imaginary *= multiplier;
            }
        }
Esempio n. 11
0
 internal static void InPlaceIFFT(Complex[] samples, FFTCache cache = null) =>
 InPlaceIFFTCall(samples, samples.Length, cache == null ? IntPtr.Zero : cache.Native);
Esempio n. 12
0
 /// <summary>
 /// Spectrum of a signal's FFT.
 /// </summary>
 public static float[] FFT1D(this float[] samples, FFTCache cache)
 {
     samples = samples.FastClone();
     samples.InPlaceFFT(cache);
     return(samples);
 }
Esempio n. 13
0
 /// <summary>
 /// Spectrum of a signal's FFT.
 /// </summary>
 public static float[] FFT1D(this float[] samples)
 {
     using FFTCache cache = new FFTCache(samples.Length);
     return(samples.FFT1D(cache));
 }
Esempio n. 14
0
 /// <summary>
 /// Fast Fourier transform a 2D signal.
 /// </summary>
 public static Complex[] FFT(this Complex[] samples, FFTCache cache)
 {
     samples = samples.FastClone();
     samples.InPlaceFFT(cache);
     return(samples);
 }
Esempio n. 15
0
 /// <summary>
 /// Fast Fourier transform a 2D signal.
 /// </summary>
 public static Complex[] FFT(this Complex[] samples)
 {
     using FFTCache cache = new FFTCache(samples.Length);
     return(samples.FFT(cache));
 }
Esempio n. 16
0
 /// <summary>
 /// Apply a delay on the <paramref name="signal"/> even with fraction <paramref name="samples"/>.
 /// </summary>
 public static void Delay(float[] signal, float samples)
 {
     using FFTCache cache = new FFTCache(QMath.Base2Ceil(signal.Length));
     Delay(signal, samples);
 }