Elevating the head of your bed could also help if it is acid reflux. Coughing when lying down can also be a symptom of congestive heart failure. When I was undiagnosed with sleep apnea, I would awaken in a violent coughing fit like something had gone down the wrong way, and in retrospect realize those were likely times when my breathing stopped and had struggled to resume. Have you been seen by a doctor for this? No matter what the cause, medical treatment may be able to help and prevent it worsening.
It may also be acid reflux. You might try some over the counter acid controllers to see if that helps.