There is a medical term for what you are experiencing and it is called a dream anxiety attack
and are associated with an increase in heart rate, an increase in the rate of breathing, etc.
Medication can be the underlying cause, unresolved stress issues, etc. I have oftened thought about a heart condition and a nightmare, and could that be the cause of death while asleep for some individuals...I believe there is an association . If it is too uncomfortable for you, I'm sure your doctor would help you through it, just let him/her know.
Thanks for sharing and take care
When asleep it is usual that the heart will respond to what you are dreaming. This is why after a nightmare you can wake up panting and sweating. Perhaps you are having uncomfortable dreams. When you wake up, your heart will relax quite quickly which is why everything settles down. I am not sure what can be done about it, perhaps a chat with your Doctor for some advice? Are you going through stressful times at the moment? or maybe you suffer anxiety in general?