Simvik

Q15 multiplication

Multiply two fractional fixed-point numbers. A medium embedded C problem (Fixed-point and signal processing), run and graded in the browser.

medium · Fixed-point and signal processing · fixed-point · q15

Q15 represents a fraction in an int16_t: the stored integer divided by 32768. So 16384 means 0.5, and the range is -1.0 to just under +1.0.

Return the Q15 product of a and b: the 32-bit product shifted right by 15. The one product that does not fit, -1.0 times -1.0, must saturate to 32767.

Starter code

int16_t q15_mul(int16_t a, int16_t b) {
  // (a / 32768) * (b / 32768), expressed in Q15 again.
  return 0;
}

Example tests

Half times half

printf("%d\n", q15_mul(16384, 16384));

Expected output:

8192

Almost one times half

printf("%d\n", q15_mul(32767, 16384));

Expected output:

16383

Learn it first

More Fixed-point and signal processing problems