Had a nearly identical experience 28 years ago on my very first flight after my PP checkride. Had wife and dog in a 152 on 3 hour XC when engine started running rough and losing altitude. I did not declare an emergency. However, I did call FF, told them I had a rough running engine, and asked them to vector me to the nearest airfield. They asked if I wanted emergency services to meet me at the field, but by then the engine was running better and holding altitude, so I said no. I landed, found a mechanic, did some ground runups, but could not replicate the problem. I spiral climbed up over the airfield to 6500 AGL, circled a few times to make sure it was running OK, and finished the trip. Chalked it up to either carb ice or mixture error. It spooked me a bit, so I put my wife and dog in a rental car for the return trip.
It's fine that you declared, but I don't think I would have in your situation. I think I would simply have told FF what the issue was, and informed them that I was diverting as a precaution. You have their attention and they are monitoring if things get worse and you have a real emergency, instead of a potential one.