コード例 #1
0
 // reduce feature size by applying a pca
 private float[] framePca(float[] procBuffer)
 {
     // substract pca mean values from data
     LinearAlgebraUtils.VecSub(procBuffer, pcaMean, pcaMeanDims[0]);
     // dot multiply transposed component matrix with data vector (comp * vec.T)
     return(LinearAlgebraUtils.MatVecDot(pcaComp, procBuffer, pcaCompDims));
 }
コード例 #2
0
 // transform a data buffer into its magnitude spectrum
 public void transform(float[] dataRe, int n)
 {
     /* windowing */
     float[] window = fftWin;
     // create custom window for smaller segment processing
     if (n < winLen)
     {
         window = hannWindow(n);
     }
     // multiply data buffer with window
     LinearAlgebraUtils.VecMul(dataRe, window, n, 0);
     // define temporary buffer for complex calculations
     float[] dataIm = new float[winLen];
     // calculate fourier transform
     complexFourier(dataRe, dataIm);
     // get absolute real magnitude spectrum and extrema
     for (int i = 0; i <= winLen / 2 - simdLenFp32; i += simdLenFp32)
     {
         Vector <float> vecDataRe = new Vector <float>(dataRe, i);
         Vector <float> vecDataIm = new Vector <float>(dataIm, i);
         Vector.SquareRoot(vecDataRe * vecDataRe + vecDataIm * vecDataIm).CopyTo(dataRe, i);
     }
     dataRe[winLen / 2] = (float)Math.Sqrt(dataRe[winLen / 2] * dataRe[winLen / 2] + dataIm[winLen / 2] * dataIm[winLen / 2]);
     Array.Clear(dataRe, winLen / 2 + 1, winLen / 2 - 1);
     // scale magnitudes between 0 and 1
     LinearAlgebraUtils.VecMinMax(dataRe, dataRe.Min(), dataRe.Max(), winLen / 2 + 1);
 }
コード例 #3
0
 public PitchClassifier(string w1File, string w2File, string b1File, string b2File)
 {
     // load weights and biases from files
     LinearAlgebraUtils.loadNdarray(w1File, out w1, out w1Dims);
     LinearAlgebraUtils.loadNdarray(w2File, out w2, out w2Dims);
     LinearAlgebraUtils.loadNdarray(b1File, out b1, out b1Dims);
     LinearAlgebraUtils.loadNdarray(b2File, out b2, out b2Dims);
 }
コード例 #4
0
 // get the pitch probabilities for the feature array
 public float[] predictProb(float[] features)
 {
     float[] l1 = LinearAlgebraUtils.MatVecDot(w1, features, w1Dims);
     LinearAlgebraUtils.VecAdd(l1, b1, b1Dims[0]);
     LinearAlgebraUtils.VecReLu(l1, w1Dims[0]);
     float[] l2 = LinearAlgebraUtils.MatVecDot(w2, l1, w2Dims);
     LinearAlgebraUtils.VecAdd(l2, b2, b2Dims[0]);
     return(softMax(l2, w2Dims[0]));
 }
コード例 #5
0
 public AudioPreprocessor(string pcaMeanFile, string pcaCompFile)
 {
     // load pca mean vector
     LinearAlgebraUtils.loadNdarray(pcaMeanFile, out pcaMean, out pcaMeanDims);
     // load pca component matrix
     LinearAlgebraUtils.loadNdarray(pcaCompFile, out pcaComp, out pcaCompDims);
     // init magnitude spectrum transformer
     magnitudeSpectrum = new MagnitudeSpectrum(WinLen);
 }
コード例 #6
0
    // uses the complex fft to transform two signals simultaniously
    public void stereoTransform(float[] dataRe, float[] dataIm, int n)
    {
        /* windowing */
        float[] window = fftWin;
        // create custom window for smaller segment processing
        if (n < winLen)
        {
            window = hannWindow(n);
        }
        // multiply data buffer with window
        LinearAlgebraUtils.VecMul(dataRe, window, n, 0);
        LinearAlgebraUtils.VecMul(dataIm, window, n, 0);
        // calculate fourier transform
        complexFourier(dataRe, dataIm);
        // split combined spectrum into magnitude signal spectra
        float aRe = 0, aIm = 0, bRe = 0, bIm = 0;
        float tmpRe = dataRe[winLen / 2 - 1];
        float tmpIm = dataIm[winLen / 2 - 1];

        for (int i = 1; i < winLen / 2; i++)
        {
            aRe       = dataRe[i] + dataRe[winLen - i];
            aIm       = dataIm[i] - dataIm[winLen - i];
            bRe       = dataIm[i] + dataIm[winLen - i];
            bIm       = dataRe[winLen - i] - dataRe[i];
            dataRe[i] = (float)Math.Sqrt(aRe * aRe + aIm * aIm);
            dataIm[i] = (float)Math.Sqrt(bRe * bRe + bIm * bIm);
        }
        aRe = dataRe[winLen / 2] + tmpRe;
        aIm = dataIm[winLen / 2] - tmpIm;
        bRe = dataIm[winLen / 2] + tmpIm;
        bIm = tmpRe - dataRe[winLen / 2];
        dataRe[winLen / 2] = (float)Math.Sqrt(aRe * aRe + aIm * aIm);
        dataIm[winLen / 2] = (float)Math.Sqrt(bRe * bRe + bIm * bIm);
        // set unused buffer parts to zero
        Array.Clear(dataRe, winLen / 2 + 1, winLen / 2 - 1);
        Array.Clear(dataIm, winLen / 2 + 1, winLen / 2 - 1);
        // scale magnitudes between 0 and 1
        LinearAlgebraUtils.VecMinMax(dataRe, dataRe.Min(), dataRe.Max(), winLen / 2 + 1);
        LinearAlgebraUtils.VecMinMax(dataIm, dataIm.Min(), dataIm.Max(), winLen / 2 + 1);
    }