During Self Inquiry one can try to figure out how vrittis (mental modifications, thought waves) originate or how thoughts pop up every now and then making us do things like puppets are made to do things. This eventually leads us to know that we are programmed and are not really the doers. Loss of doership is the key in the final stages of Self Realisation where the one who was doing the Self Inquiry surrenders knowing that it is not the doer.
[Panchadasi Chapter 8, Kootasthadeep Prakraran, Verse 20]
Meaning: All the vrittis are born sequentially after gaps. When one vritti is destroyed, another one is born. One should understand the origin of third, fourth etc. vrittis. All vrittis disappear during deep sleep, unconscious state, samadhi and not even one remains out of those.
Q: Where do thoughts come from?
A: Right now if you wish you can think of your favourite actor. This thought is triggered by conscious mind and the image comes from the memory/causal body/karana sharira (unconscious mind). You can bring this thought whenever you wish. However, a thought that just pops in without you consciously desiring is triggered by the subconscious mind and is delivered by the causal body. What thought will pop in from causal body depends on the activities of conscious/subconscious mind. Your conscious/subconscious mind is actually a tuner. When it is in resonance at certain thought frequency, it attracts that type of thoughts from the causal body. On a side note, since it is about tuning, if you identify with misery, you may attract chain of thoughts close to misery and the opposite is also true. Now, you can choose what type of thoughts you would like to harbour and which types of thoughts you would like to kick out the moment they pop-up in your mind.