<commit_before>/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */


package edu.cmu.sphinx.frontend.frequencywarp;

import edu.cmu.sphinx.frontend.BaseDataProcessor;
import edu.cmu.sphinx.frontend.Data;
import edu.cmu.sphinx.frontend.DataProcessingException;
import edu.cmu.sphinx.frontend.DataProcessor;
import edu.cmu.sphinx.frontend.DoubleData;
import edu.cmu.sphinx.frontend.FrontEndFactory;

import edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform;

import edu.cmu.sphinx.util.SphinxProperties;
import edu.cmu.sphinx.util.Timer;

import java.io.IOException;

/**
 * Filters an input power spectrum through a bank of mel-filters. 
 * The number of mel-filters in the bank is controlled by the
 * SphinxProperty:
 * <p>
 * <code>edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank.numberFilters</code>
 * <p>
 * which defaults to 40.
 * <p>
 * The output is an array of filtered values, each corresponding to the
 * result of filtering the input spectrum through an individual filter.
 * Therefore, the length of the output array is equal to the number
 * of filters created.
 * <p>
 * The filters in the filter bank are placed in the frequency axis so as to
 * mimic the critical band, representing different perceptual effect
 * at different frequency bands. Pictorially, the filter bank looks like:
 * <p>
 * <img src="doc-files/melfilterbank.jpg">
 * <br><center><b>Figure 1: A Mel-filter bank.</b></center>
 * <p>
 * The minimum frequency has a default value of 130Hz, while 
 * the maximum frequency has a default value of 6800Hz.
 * These frequencies depend on the channel and the sampling frequency
 * that you are using. For telephone speech, since the telephone channel
 * corresponds to a bandpass filter with cutoff frequencies of 
 * around 300Hz and 3700Hz, using limits wider than these would waste
 * bandwidth. For clean speech, the minimum frequency should be higher 
 * than about 100Hz, since there's no speech information below it.
 * Furthermore, by setting the lower frequency above 50/60Hz,
 * we get rid of the hum resulting from the AC power, if present.
 * <p>
 * The maximum frequency has to be lower than the Nyquist frequency,
 * that is, half the sampling rate. Furthermore, there isn't much
 * information above 6800Hz that can be used for improving separation
 * between models. Particularly for very noisy channels,
 * maximum frequency of around 5000Hz may help cut off the noise.
 * <p>
 * The mel-frequency scale is a nonlinear scale which models
 * the behavior of the human auditory system. Davis and Mermelstein
 * showed that Mel-frequency cepstral coefficients are good for
 * speech recognition. For details, see Davis and Mermelstein,
 * <i>Comparison of Parametric Representations for Monosyllable
 * Word Recognition in Continuously Spoken Sentences, IEEE
 * Transactions on Acoustic, Speech and Signal Processing, 1980</i>.
 * 
 * @see MelFilter
 */
public class MelFrequencyFilterBank extends BaseDataProcessor {

    /**
     * Sphinx property prefix for this MelFrequencyFilterBank.
     */
    private static final String PROP_PREFIX =
	"edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank.";

    /**
     * The name of the Sphinx Property for the number of filters in
     * the filterbank.
     */
    public static final String PROP_NUMBER_FILTERS
	= PROP_PREFIX + "numFilters";


    /**
     * The default value for PROP_NUMBER_FILTERS.<commit_msg>Some re-arrangement of javadoc contents.<commit_after>/*
 * Copyright 1999-2002 Carnegie Mellon University.  
 * Portions Copyright 2002 Sun Microsystems, Inc.  
 * Portions Copyright 2002 Mitsubishi Electronic Research Laboratories.
 * All Rights Reserved.  Use is subject to license terms.
 * 
 * See the file "license.terms" for information on usage and
 * redistribution of this file, and for a DISCLAIMER OF ALL 
 * WARRANTIES.
 *
 */


package edu.cmu.sphinx.frontend.frequencywarp;

import edu.cmu.sphinx.frontend.BaseDataProcessor;
import edu.cmu.sphinx.frontend.Data;
import edu.cmu.sphinx.frontend.DataProcessingException;
import edu.cmu.sphinx.frontend.DataProcessor;
import edu.cmu.sphinx.frontend.DoubleData;
import edu.cmu.sphinx.frontend.FrontEndFactory;

import edu.cmu.sphinx.frontend.transform.DiscreteFourierTransform;

import edu.cmu.sphinx.util.SphinxProperties;
import edu.cmu.sphinx.util.Timer;

import java.io.IOException;

/**
 * Filters an input power spectrum through a bank of mel-filters. 
 * The number of mel-filters in the bank is controlled by the
 * SphinxProperty:
 * <p>
 * <code>edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank.numberFilters</code>
 * <p>
 * which defaults to 40.
 * <p>
 * The output is an array of filtered values, each corresponding to the
 * result of filtering the input spectrum through an individual filter.
 * Therefore, the length of the output array is equal to the number
 * of filters created.
 * <p>
 * The filters in the filter bank are placed in the frequency axis so as to
 * mimic the critical band, representing different perceptual effect
 * at different frequency bands. Pictorially, the filter bank looks like:
 * <p>
 * <img src="doc-files/melfilterbank.jpg">
 * <br><center><b>Figure 1: A Mel-filter bank.</b></center>
 * <p>
 * As you might notice in the above figure, the triangles are of
 * decreasing height and increasing width. The distance at the base
 * from the center to the left edge is different from the center to
 * the right edge. This is due to the mel-frequency scale,
 * which is a nonlinear scale that models the behavior of the 
 * human auditory system. The area under each triangle is equal to 1.
 * <p>
 * The minimum frequency has a default value of 130Hz, while 
 * the maximum frequency has a default value of 6800Hz.
 * These frequencies depend on the channel and the sampling frequency
 * that you are using. For telephone speech, since the telephone channel
 * corresponds to a bandpass filter with cutoff frequencies of 
 * around 300Hz and 3700Hz, using limits wider than these would waste
 * bandwidth. For clean speech, the minimum frequency should be higher 
 * than about 100Hz, since there's no speech information below it.
 * Furthermore, by setting the lower frequency above 50/60Hz,
 * we get rid of the hum resulting from the AC power, if present.
 * <p>
 * The maximum frequency has to be lower than the Nyquist frequency,
 * that is, half the sampling rate. Furthermore, there isn't much
 * information above 6800Hz that can be used for improving separation
 * between models. Particularly for very noisy channels,
 * maximum frequency of around 5000Hz may help cut off the noise.
 * <p>
 * Davis and Mermelstein showed that Mel-frequency cepstral
 * coefficients are good for speech recognition.
 * For details, see Davis and Mermelstein,
 * <i>Comparison of Parametric Representations for Monosyllable
 * Word Recognition in Continuously Spoken Sentences, IEEE
 * Transactions on Acoustic, Speech and Signal Processing, 1980</i>.
 * 
 * @see MelFilter
 */
public class MelFrequencyFilterBank extends BaseDataProcessor {

    /**
     * Sphinx property prefix for this MelFrequencyFilterBank.
     */
    private static final String PROP_PREFIX =
	"edu.cmu.sphinx.frontend.frequencywarp.MelFrequencyFilterBank.";

    /**
     * The name of the Sphinx Property for the number of filters in
     * the filterbank.
     */
    public static final String PROP_NUMBER_FILTERS
	= PROP_PREFIX + "numFilters";


    /**
     * The default value for PROP_NUMBER_FILTERS.
{'fraction_non_alphanumeric': 0.07082008900190719, 'fraction_numerical': 0.013350286077558804, 'mean_word_length': 4.0552699228791775, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3435850', 'n_tokens_mistral': 2345, 'n_tokens_neox': 2136, 'n_words': 922}