You can tell by the position of the body. A cat that's coughing is hunched while a cat that is coughing up a hairball is in the same position as eating- all four feet bent and body lowered with the head straight ...
My Monti was coughing and I thought it was hairballs. I think I waited too long to take him to the vet, then when I did we found out it was a bad lower resp. infection. I shouldn't have waited so long.
It sounds very different. One of my cats recently had a very bad asthma attack.
At first we thought he was throwing up or had an upper respiratory infection. We got him in right away and he had a very inflamed airway. You should get kitty in for a checkup if there is coughing. Respiratory issues are very serious.