Exemple #1
0
        public float[] ProcessFrame(float[] frame)
        {
            DSPTools.PreEmphasise(frame, this.PreEmphasiseFactor);

            DSPTools.ApplyWindow(frame, this.FilterWindow);

            int valid_nfft = this.MBI.nfft / 2 + 1;

            Complex[] Outputs = DSPTools.FFT(frame.Select(D => new Complex(D, 0.0f)).ToArray(), valid_nfft);

            float[] Internals = Outputs.Select(O => (float)O.Magnitude).ToArray();

            float[] Results = new float[this.dct.dctlen];

            for (int i = 0; i < this.dct.dctlen; i++)
            {
                double t = 0.0f;
                for (int j = 0; j < this.MBI.nfilters; j++)
                {
                    //DCT变换,解卷积
                    t += this.dct.coeff[i, j] * Math.Log(
                        DSPTools.Product(Internals, this.MBI.filter, j, valid_nfft) +
                        DSPTools.EPS,
                        DSPTools.NewBase);
                }
                Results[i] = (float)(t * this.LifterWindow[i]);//倒谱提升
            }
            return(Internals);
        }
Exemple #2
0
        public MFCC(int sample_rate = 8000, int frame_length = 512, int nfft = 512, int low = 0, int high = 4000, int nfilters = 24, int ndcts = 12)
        {
            this.MBI.nfft     = nfft;
            this.MBI.low      = low;
            this.MBI.high     = high;
            this.MBI.nfilters = nfilters;
            this.dct.dctlen   = ndcts;
            int valid_nfft = nfft / 2 + 1;

            DSPTools.DctCoeff(ndcts, nfilters, this.dct.coeff = new float[ndcts, nfilters]);

            DSPTools.MelBank(sample_rate, nfft, low, high, nfilters, this.MBI.filter = new float[nfilters, valid_nfft]); //Mel滤波器系数

            DSPTools.CreateHammingWindow(this.FilterWindow = new float[frame_length]);                                   //加窗

            DSPTools.CreateLiftWindow(this.LifterWindow = new float[this.dct.dctlen]);
        }