Correlación cruzada y FFT en C # para autenticación de voz

Esta es una pregunta similar a las otras preguntas pero no una duplicada. Sin embargo, todavía no puedo obtener el resultado correcto.

Básicamente estoy tratando de grabar dos archivos Wav (1 - Archivo base 2 - Archivo de temperatura) y luego convertirlo en byte y pasarlo a Aforge FFT y luego la Correlación.

Hay poca confusión. Cuando grabo el archivo, estoy usando 44100 Khz con 16 bits. Por lo tanto, creo que devolverá 44100 bytes por segundo. FFT acepta bytes en potencia de 2, por lo que estoy pasando 16384 bytes a la vez y almacenando eso en la matriz principal y luego estoy usando el Alogoritmo de Core Corelation para ver la similitud y solo devuelve alrededor de 0.30 todo el tiempo. De nuevo, no estoy muy seguro de haber seguido el camino correcto.

Adjunto el código de muestra y las referencias relativas.

        static void Start()
        {

            waveSource = new WaveInEvent();
            //waveSource.WaveFormat = new WaveFormat(44100, 1);//44khz rate
            waveSource.WaveFormat = new WaveFormat(44100, 16, 1);


            waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
            waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);
            Random rnd = new Random();

            int card = rnd.Next(52);
            waveFile = new WaveFileWriter(@Environment.CurrentDirectory.ToString() + @"\Recording" + card.ToString() + "0001.wav", waveSource.WaveFormat);

            waveSource.StartRecording();
        }

        private static void FileCompare(string file1, string file2)
        {
            double[] r1;


             // readWav(file1, out permanent, out r);
              //readWav(file2, out temp, out l);
               openWav(file1, out permanent, out r1);
               openWav(file2, out temp, out r1);

              double[] odoubledata = new double[163840];
              double[] odoubledata1 = new double[163840];
              int n = 0;
              int k = 0;
            for (int lk = 0; lk <10; lk++)
            {

             //   if (lk != 0   || lk != 9)
                {
                    AForge.Math.Complex[] c = new AForge.Math.Complex[16384];
                    for (int i = 0; i < 16384; i++)
                    {


                        c[i].Re = permanent[i];
    ,                    c[i].Im = 0;

                    }

                    AForge.Math.Complex[] c1 = new AForge.Math.Complex[16384];
                    for (int i = 0; i < 16384; i++)
                    {

                        c1[i].Re = temp[i];
                        c1[i].Im = 0;

                    }

                  FourierTransform.FFT(c, FourierTransform.Direction.Forward);
                    FourierTransform.FFT(c1, FourierTransform.Direction.Forward);
                    //   FourierTransform.DFT(c1, FourierTransform.Direction.Forward);
                    double[] doubledata = new double[c.Length];
                    double[] doubledata1 = new double[c1.Length];
                    for (int i = 0; i < c.Length; i++)
                    {
                        doubledata[i] = c[i].Re;
                        odoubledata[k] = c[i].Re;
                        k = k + 1;
                    }

                    for (int i = 0; i < c1.Length; i++)
                    {
                        doubledata1[i] = c1[i].Re ;
                        odoubledata1[n] = c1[i].Re;
                        n = n + 1;
                    }

                }


            }


            double temq2;
            int off;
            CalcCrossCorrelation(odoubledata, odoubledata1, out off, out temq2);
            Console.WriteLine("Similarity  " + temq2);

        }

Referencias - Almacenamiento de archivos Wavhttps://stackoverflow.com/a/17983876/4124478

Lectura de archivo Wavhttps://stackoverflow.com/a/11162668/4124478

Correlación cruzadahttps://stackoverflow.com/a/27277120/4124478

Código FFThttps://stackoverflow.com/a/170413/4124478

Actualizar

Estoy almacenando los archivos de muestra con los mismos bytes, ya que será fácil de comparar. La grabación se detendrá después de 4 segundos.

static void Start()
        {

            waveSource = new WaveInEvent();
            //waveSource.WaveFormat = new WaveFormat(44100, 1);//44khz rate

            waveSource.WaveFormat = new WaveFormat(8192, 16, 1);

            waveSource.DataAvailable += new EventHandler<WaveInEventArgs>(waveSource_DataAvailable);
            waveSource.RecordingStopped += new EventHandler<StoppedEventArgs>(waveSource_RecordingStopped);
            Random rnd = new Random();

            int card = rnd.Next(52);
            waveFile = new WaveFileWriter(@Environment.CurrentDirectory.ToString() + @"\Recording" + card.ToString() + "0001.wav", waveSource.WaveFormat);

            waveSource.StartRecording();
        }

static void waveSource_DataAvailable(object sender, WaveInEventArgs e)
        {
            if (waveFile != null)
            {
                waveFile.Write(e.Buffer, 0, e.BytesRecorded);
                int seconds = (int)(waveFile.Length / waveFile.WaveFormat.AverageBytesPerSecond);
                if (seconds > 4)
                {
                    waveFile.Flush();
                    Stop();

                }

            }
        }

Además, no pude enviar todos los bytes ya que la longitud total no estaba en potencia de 2. Por lo tanto, solo envío 2 bytes a la vez y normalmente obtengo una similitud de 0.60.

private static void FileCompare(string file1, string file2)
        {
            double[] l;
            double[] r;
            double[] r1;


            // readWav(file1, out permanent, out r);
            //  readWav(file2, out temp, out l);

            openWav(file1, out permanent, out r1);
            openWav(file2, out temp, out r1);

            double[] odoubledata = new double[41769];
            double[] odoubledata1 = new double[41769];

            Console.WriteLine("-------cross correlation--------");

            int n = 0;
            int k = 0;
            for (int i = 0; i < permanent.Length; i = i + 2)
            {

                Complex[] test1 = new Complex[2];
                test1[0].Re = permanent[n];
                test1[0].Im = 0;
                test1[1].Re = permanent[n + 1];
                test1[1].Im = 0;
                FourierTransform.FFT(test1, FourierTransform.Direction.Forward);
                odoubledata[n] = test1[0].Magnitude + test1[0].SquaredMagnitude;
                odoubledata[n + 1] = test1[1].Magnitude + test1[1].SquaredMagnitude;
                n = n + 1;
            }
            for (int i = 0; i < temp.Length; i = i + 2)
            {

                Complex[] test1 = new Complex[2];
                test1[0].Re = temp[k];
                test1[0].Im = 0;
                test1[1].Re = temp[k + 1];
                test1[1].Im = 0;
                FourierTransform.FFT(test1, FourierTransform.Direction.Forward);
                odoubledata1[k] = test1[0].Magnitude + test1[0].SquaredMagnitude;
                odoubledata1[k + 1] = test1[1].Magnitude + test1[1].SquaredMagnitude;
                k = k + 1;
            }
            double temwe2;
            int offs;
            CalcCrossCorrelation(odoubledata, odoubledata1, out offs, out temwe2);
            Console.WriteLine("Similarity Total together " + temwe2);
}

No estoy seguro de si estoy almacenando los valores de salida correctos sumando Magnitud y Magnitud al cuadrado.

Respuestas a la pregunta(0)

Su respuesta a la pregunta