From what I have read about signal (de)modulation I understand that multiplying two sine waves, both with the same frequency, gives a two frequency component sine wave. One at DC and one at $2\omega$. Using a low pass filter will let us remove the $2\omega$ component. Now DC amplitude is proportional to the phase difference between the two sine waves.
So: $$ A \sin(\omega t) \sin(\omega t + \theta) = \frac{A}{2}\cos(\theta) + \frac{A}{2}\cos(2\omega t + \theta) \rightarrow {\rm LPF} \rightarrow \frac{A}{2}\cos(\theta) $$ where $\omega$ is the frequency, LPF is Low Pass Filter, $A$ is the amplitude and $\theta$ is the phase difference between the sine waves.
I made a Matlab program to plot this, then I tried with a square wave multiplied with a sine wave. I can see that there is still a connection between DC and phase by doing a FFT as well as in the time domain. I would like to see the math for the relationship between DC and phase.
For sine $\times$ sine, I have read that sampling with a frequency four times the modulated signal frequency will make it possible to get the I and Q values by subtracting samples in the following order:
$$ I(t) = s(t) - s(t-2) $$ $$ Q(t) = s(t-3) - s(t-1) $$ where $$ s(t) = A\sin(\omega t + \theta) $$
This I do not quite understand yet and therefore leads me to be unable to determine if this also is valid for a square $\times$ sine. Can anyone try to explain this to me?
I will appreciate any feedback on how to effectively do IQ demodulation on a micro-controller using a square reference waveform.
Additional information:
I wish to use a micro-controller to sample the analog sine and square (reference) signal and do IQ demodulation. I almost only find information about sine $\times$ sine and therefore want to know if there are any pitfalls using a reference square wave that I am not seeing yet.