Example #1
0
        private void ComputeAndClassify(double[] arr)
        {
            double[] magnitudes;

            for (int i = 0; i < realIn.Length; i++)
            {
                realIn[i] = arr[i];
            }

            Console.WriteLine("FFT");
            fft.Execute();

            magnitudes = new double[comOut.Length];
            for (int i = 0; i < 4000; i++)
            {
                magnitudes[i] = 10 * Math.Log10((comOut[i].Magnitude / bufferSize) * (comOut[i].Magnitude / bufferSize));

                if (10 * Math.Log10((comOut[i].Magnitude / bufferSize) * (comOut[i].Magnitude / bufferSize)) > 40)
                {
                    //Console.WriteLine("Bin: " + i * sampleRate / comOut.Length + " " + 10 * Math.Log10((comOut[i].Magnitude / bufferSize) * (comOut[i].Magnitude / bufferSize)));
                }
            }
            DataSample sample = new DataSample(magnitudes);

            Console.WriteLine("Classification");
            network.DataClassification(sample);
        }
        static double[] FFT(WaveFileObject obj, PinnedArray <double> pin, FftwArrayComplex com, FftwPlanRC fft)
        {
            Console.WriteLine("FFT");
            double[] magnitudes;
            Console.WriteLine(obj.soundData.Count);
            double[] input = new double[obj.soundData.Count + 20286];
            Array.Clear(input, 0, input.Length);
            obj.soundData.CopyTo(input, 0);

            switch (obj.header.channels)
            {
            case 1:
                for (int i = 0; i < pin.Length; i++)
                {
                    pin[i] = input[i];
                    //Console.Write(pin[i] + " : ");
                }
                break;

            case 2:
                for (int i = 0; i < pin.Length; i++)
                {
                    pin[i] = input[i + i];
                    //Console.WriteLine(pin[i]);
                }
                break;

            default:
                break;
            }

            fft.Execute();

            magnitudes = new double[com.Length];
            for (int i = 0; i < 4000; i++)
            {
                magnitudes[i] = 10 * Math.Log10((com[i].Magnitude / inputSize) * (com[i].Magnitude / inputSize));

                /*
                 * if (10 * Math.Log10((com[i].Magnitude / inputSize) * (com[i].Magnitude / inputSize)) > 10)
                 * {
                 *  Console.WriteLine("Bin: " + i * sampleRate / com.Length + " " + 10 * Math.Log10((com[i].Magnitude / inputSize) * (com[i].Magnitude / inputSize)));
                 * }
                 */
            }

            Console.WriteLine(com.Length);
            Console.WriteLine();

            Console.WriteLine("Returning magnitudes");
            return(magnitudes);
        }