/** * Creates all the filters in the bank. * * @param sampleFrequency sample frequency in Hz * @param melFilterWidth filter width in Mel frequency scale * @param N spectrum size of each filter */ public MelFiltersBank(double sampleFrequency, ushort melFilterWidth, int N) { sampleFreq = sampleFrequency; N_ = N; for (int i = 0; i < Dtw.MELFILTERS; ++i) { //filters.push_back(new MelFilter(sampleFrequency)); MelFilter filter = new MelFilter(sampleFrequency); filter.CreateFilter(i, melFilterWidth, N); filters.Add(filter); } }
public MelFiltersBank(double sampleFrequency, int N, bool isHfcc) { sampleFreq = sampleFrequency; N_ = N; // and here the magic happens ;) double f_low_global = 0.0; double f_high_global = sampleFrequency / 2.0; const double a = 6.23e-6; const double b = 93.39e-3; const double c = 28.52; double a1 = 0.0; double b1 = 0.0; double c1 = 0.0; double b2 = 0.0; double c2 = 0.0; a1 = 0.5 / (700.0 + f_low_global); b1 = 700 / (700.0 + f_low_global); c1 = (-f_low_global / 2.0) * (1.0 + 700 / (700.0 + f_low_global)); b2 = (b - b1) / (a - a1); c2 = (c - c1) / (a - a1); double fc_0 = 0.5 * (-b2 + Math.Sqrt(b2 * b2 - 4 * c2)); a1 = -0.5 / (700.0 + f_high_global); b1 = -700 / (700.0 + f_high_global); c1 = (f_high_global / 2.0) * (1.0 + 700 / (700.0 + f_high_global)); b2 = (b - b1) / (a - a1); c2 = (c - c1) / (a - a1); double fc_last = 0.5 * (-b2 + Math.Sqrt(b2 * b2 - 4 * c2)); double fc_0_mel = MelFilter.LinearToMel(fc_0); double fc_last_mel = MelFilter.LinearToMel(fc_last); double delta_f_mel = (fc_last_mel - fc_0_mel) / (double)(Dtw.MELFILTERS - 1); double fc_mel = 0.0; double fc = 0.0; double ERB = 0.0; double f_low = 0.0; double f_high; //filters.reserve(Dtw.MELFILTERS); for (int i = 0; i < Dtw.MELFILTERS; i++) { if (0 == i) { fc_mel = fc_0_mel; } else if ((Dtw.MELFILTERS - 1) == i) { fc_mel = fc_last_mel; } else { fc_mel = fc_0_mel + i * delta_f_mel; } // convert to linear scale, calculate ERB and filter boundaries fc = MelFilter.MelToLinear(fc_mel); ERB = a * fc * fc + b * fc + c; f_low = -(700.0 + ERB) + Math.Sqrt((700.0 + ERB) * (700.0 + ERB) + fc * (fc + 1400)); f_high = f_low + 2 * ERB; //filters.push_back(new MelFilter(sampleFrequency)); filters[i].GenerateFilterSpectrum(f_low, fc, f_high, N); } }