Added resonance function and comments

Added resonance function for recognition tasks.
Added comments for readability.