In above picture, red square wave is the input and blue wave is the output of an RC circuit. I'm not able to understand why I get a perfect sine wave when I feed a sine wave as input. The capacitor has to take some time to charge and discharge. So my intuition cries the output to be some periodic wave whose period is half the input. Could somebody clear this up for me ? Thanks!
In time domain shouldn't it do something like this ?
At t=0, the capacitor has 0 voltage. Since the input voltage is large, the capacitor keeps charging and meets the input sine wave when its falling.
Then the input voltage goes lower than the capacitor voltage, so the capacitor starts discharging and again meets the input sine wave when it is rising.
Learn to think in frequency space. This is one of those things that is difficult to see in the time domain, but falls out nicely in the frequency domain.
A sine wave is a single "pure" frequency. A RC filter is a linear system that can't distort, meaning it can't create frequencies in the output that aren't in the input. When you only put in one frequency, the output can only contain that one frequency. The only questions are what the relative amplitude and phase shift will be from input to output.
The reason that a square wave in does not result in a square wave out is because a square wave contains lots of frequencies. Each of those can be attenuated and phase shifted independently. When you change the relative strength and phases of harmonics, you get a different looking signal in the time domain.
A square wave can be thought of as the superposition of a infinite series of sines. These are at all the odd harmonics (odd integer multiples of the fundamental frequency). The amplitude of these harmonics falls off at higher frequencies.
You can pass a square wave thru several RC low pass filters in succession, each with a rolloff frequency well below that of the square wave frequency. After each filter, the result looks more and more like a sine. That is because such filters attenuate high frequencies more than low ones. This means the harmonics of the square wave are attenuated more than the fundamental. If you do this enough, the harmonics have so little amplitude relative to the fundamental, that all you see is the fundamental. That's a single frequency, so a sine.
This is not how any RC filter would react:
For a RC low pass filter, when the input frequency is well below the rolloff, the output mostly just follows the input. At well above the rolloff frequency, the output is the integral of the input.
Either way, there won't be sudden changes in output slope as you show. There is nothing special about the input crossing above or below the output since this happens smoothly. You get a inflection point in the output, but its a smooth hump since the input approaches smoothly before and leaves smoothly after.
It might be instructive to write a loop to simulate this yourself. All you have to do each step is change the output by a small fraction of the instantaneous difference of the input minus the output. That's it. Then throw a sine wave at it and see how the output smoothly follows to make another sine, although lagging in phase and lower in amplitude.