It looks as though the DC wander is caused by the android phone output, which is switching from 0V when the signal is off to some mixture of 0V and some negative voltage when the signal is on. The mean value when the signal is on is therefore a negative voltage (roughly half the peak voltage), which constitutes a DC offset from the no-signal value.
If you can change the android phone output, try making the signal symmetric (off bits at -1V, on bits at 1V, for example), which will remove this offset.
It looks as though you have an additional problem, which is that your biasing network sets the DC point of the android output to the same (Vcc/2) as the other input of the comparator; thus noise is causing unwanted transitions. Looking at your first scope trace, note that if the comparator threshold was instead set to the value of the thicker horizontal grid line across the centre of the screen (0V?), it would detect every transition without needing to modify the android code or use a Schmitt trigger.
Assuming ideal components, when the diode is "on", the equivalent circuit is:
simulate this circuit – Schematic created using CircuitLab
The charging current clockwise through C1 produces a voltage across the parallel combination of resistors.
When the diode is "off", the equivalent circuit is:
simulate this circuit
Now, you can see that R1 is provide a path for a counter-clockwise current to discharge the capacitor.
Also, see that R2 is required to pull the output voltage to zero while the diode is off.
Why is the path that R1 provides needed? if it's not there, then there
is an open-circuit, no current flows. Theoretically the end result
should be the same: the negative part of the signal does not appear at
the output.
If there is no path for a counter-clockwise current through the capacitor, the voltage across the capacitor will only increase and this voltage will oppose the positive signal voltage. Eventually, the capacitor voltage will be large enough that the diode will not turn on and the output voltage will be zero.
Below is a simulation I ran without R1. The top trace is the voltage across the capacitor; the bottom trace is the output voltage. The input source is 1kHz sine wave.
Note that the voltage across the capacitor increases while the diode is on but doesn't decrease while the diode is off. Note the effect of this on the output voltage.
Best Answer
I would recommend a precision rectifier.