Here is a breakdown of how it all works, based on Kapila’s sankhya, explained in the final chapters of Śrīmad Bhagavatam’s Third Canto.
The senses feed their data into the intellect.
The intellect has three sub-organs within it. Each performs its own function:
1) Pattern recognition
2) Pattern matching
3) Memory (storage of patterns)
So, intellect can take the raw data from the senses, recognize the patterns, and figure out what the patterns are – by matching those patterns with the information stored in memory. “Education” is the process of putting recognized patterns into the memory.
The mind observes the intellect. Mind reflects consciousness. With this reflected consciousness it observes the intellect, so it observes the processed data from the senses, and the order and meaning that the intellect has digested from that data. Then the mind reacts to it. It also has three sub-organs, each performing its own function:
Observing a recognized pattern presented by the intellect as an object, the mind develops a preference towards that object, or away from it. For example, the nose smells something. The intellect comprehends the pattern of olfactory data to be the scent of roasting spices. The mind, which always observes the intellect, reacts to this by a perference: “I love this!” or “I hate this!” Or something somewhere in between these two extremes.
Next, the mind establishes desire based on that preference. If the preference is “I love it” the desire is “I want more of it.” If the preference is “I hate it” the desire is “I want less of it”
Next the mind produces emotions based on that desire. If the desire is fulfilled, the emotion is happiness. If the desire is unfulfilled, the emotion is sadness. Other emotions represent various versions of or precursors to happiness or sadness.