I'm working on converting the Goertzel algorithm for detecting DTMF frequencies from floating to fixed point, in the hope that it will save some code space and maybe speed things up. It appears I will need to multiply two fixed point signed integers, one Q1.14 and the other Q13.2, with the result scaled to Q13.2.
If I understand correctly, the product long will be Q.16. So to bring it back to Q13.2, I would need to right-shift 14 places. But I'm wondering if instead I could left-shift the long two places, and then use a union to extract the high word.
I'm pretty sure the range of numbers I'm dealing with leave room on the left for the two shifts. But I read that a left shift in C++ does not preserve the sign bit. So if it's a negative product, I thought I would need to copy the sign bit, then restore it after the shifts. But then I thought, well, if the size of positive numbers would permit shifting left two places, then if it's a negative number, those bits are going to be 1's to begin with. This is based on my understanding that negative numbers are stored in 2's complement form, which means any unfilled bits on the left of a positive number would be zeros, but in 2's complement they would be ones. So the sign bit would be correct automatically.
This is my first attempt to deal with fixed point math(s), so I would appreciate any comments on my logic from those with more experience.
