Example #1
0
        private const int numberWaveletTransforms = 2;          // number of wavelet transform iterations, 3?

        /// <summary>
        /// Create a Mfcc object
        /// This method is not optimized in the sense that the Mel Filter Bands
        /// and the DCT is created here (and not read in)
        /// Only support an overlap of half the window size
        /// </summary>
        /// <param name="winsize">window size</param>
        /// <param name="srate">sample rate</param>
        /// <param name="numberFilters">number of filters (MEL COEFFICIENTS). E.g. 36 (SPHINX-III uses 40)</param>
        /// <param name="numberCoefficients">number of MFCC COEFFICIENTS. E.g. 20</param>
        public MFCC(int winsize, int srate, int numberFilters, int numberCoefficients)
        {
            this.numberCoefficients = numberCoefficients;

            // Compute the Mel Frequencey Filters
            var melFilter = new MelFilter(winsize, srate, numberFilters, 20);

            this.melScaleFreqsIndex      = melFilter.MelScaleFreqsIndex;
            this.melScaleTriangleHeights = melFilter.MelScaleTriangleHeights;
            this.filterWeights           = melFilter.FilterWeights;

            // Compute the DCT
            dct = new DctMatrix(numberCoefficients, numberFilters).Matrix;

                        #if DEBUG
            // dct.WriteAscii("dct-mirage-orig.ascii");
            // dct.DrawMatrixGraph("dct-mirage-orig.png");
                        #endif
        }
Example #2
0
        public void TestMelFrequencyFiltering()
        {
            var audio = BassProxy.Instance;

            //const string fileName = @"Tests\Passacaglia, Handel-Saw-86bmp.wav";
            const string fileName = @"Tests\Passacaglia, Handel-Sine-86bmp.wav";

            const int  sampleRate     = 44100;
            const int  fftWindowsSize = 2048;
            const int  fftOverlap     = 1024;
            const bool colorize       = true;
            const int  melFilters     = 120;

            var monoSignal = BassProxy.ReadMonoFromFile(fileName, sampleRate);

            double[][] specNormal    = FFTUtils.CreateSpectrogramLomont(monoSignal, fftWindowsSize, fftOverlap);
            var        specNormalMat = new Matrix(specNormal).Transpose();

            specNormalMat.DrawMatrixImage("spec_normal.png", -1, -1, colorize, true);

            // Mel Scale Filterbank
            // Mel-frequency is proportional to the logarithm of the linear frequency,
            // reflecting similar effects in the human's subjective aural perception)
            var melFilter = new MelFilter(fftWindowsSize, sampleRate, melFilters, 0);

            var specNormalMelMat = melFilter.FilterWeights * specNormalMat;

            specNormalMelMat.DrawMatrixImage("spec_normal_mel.png", -1, -1, colorize, true);

            melFilter.FilterWeights.WriteCSV("melfilter_orig.csv");
            melFilter.FilterWeights.DrawMatrixGraph("melfilter_orig.png");

            var melFilterBank    = new MelFilterBank(0, sampleRate / 2, melFilters, fftOverlap, sampleRate);
            var melFilterBankMat = melFilterBank.Matrix;

            melFilterBankMat.WriteCSV("melfilter_new.csv");
            melFilterBankMat.DrawMatrixGraph("melfilter_new.png");

            var specNormalMelMatNew = melFilterBankMat * specNormalMat;

            specNormalMelMatNew.DrawMatrixImage("spec_normal_mel_new.png", -1, -1, colorize, true);
        }