The problem is improper mass connection of the RF antenna.
It is a bit of a weak spot of the iPhone 3GS.
Have a good look at the two small golden pins in the right lower corner (if your iPhone is opened ,dock connector on downside).
BOTH SHOULD TOUCH THE OUTER METAL RIM. MOST OF THE TIMES ONE OF THEM IS NOT TOUCHING THE RIM PROPERLY.
One is mass from the logic board, the other is mass from the antenna.
If one of them does not connect well, which is often the case after a drop, a dock replacement or just after a years or so of use, then interference is the result because the RF signal to the antenna reflects back and flows into the audio circuit where it induces the interference.
If you are brave enough, take the logic board out, bend the golden pin a bit outwards (don't break it) and put the logic board back making sure the pin pushes against the metal rim.
Same for the antenna/audio dock.
Good luck