# How do I generate a QAM signal using Python?

I have created a 16-QAM Constellation diagram ranging from {-3-3j ... +1+1j}. I then transform a given input string into symbols where each symbol is log2(16) = 4 bits wide. I then map each symbol to a constellation point, i.e. symbol 15 would be the constellation point 1+1j and symbol 0 would be -3-3j

The next step is to create a playable sound, for this I am trying to generate samples using the following formula that I found on Wikipedia and in other places:

s = sin(2*pi*fc*t)*I(t) + cos(2+pi*fc*t)*Q(t)

sample = np.math.sin(w * t) * constellation[symbol].real + np.math.cos(w * t) * constellation[symbol].imag


Where w = 2 * pi * fc

And finally, appending the single samples to a full sample list and multiplying by the maximum amplitude (32767):

samples.append(int(sample * 32767))


before saving the data into a .wav file:

qam_file.writeframes(struct.pack('%dh' % len(samples), *samples))


Something doesn't add up, and I have no idea what, am I using the correct formula or am I doing something wrong with the In-phase and Quadrature Components?

Any help would be greatly appreciated since I am fairly new to DSP.

• It is unclear... What you are trying to do? What is the problem? What did you get? What did you expect?
– ThP
Dec 4 '20 at 20:27