0.5 Amplitude Modulation
Using Python Functions to Perform Operations
Now, let's write a simple function to multiply two signals. In particular, we will multiply the speech signal with a cosine signal . We will use the multiply function from NumPy.
def multiply_signals(x, omega, Fs):
w = (float(omega) / Fs)
return np.multiply(x, np.cos(w * np.arange(0,len(x))))Possible explorations are to try other operations and other functions. See NumPy documentation for more. We will use multiply_signal on the speech signal.
alien_voice = multiply_signals(s, 3000, Fs)
IPython.display.Audio(alien_voice, rate=Fs)Let's be sure to save the result. Don't want to miss out on hearing aliens again!
wavfile.write('alien.wav', Fs, alien_voice)
plot_signal(alien_voice, xaxis_label=r'$n$',
yaxis_label=r'$s[n]\cos(\omega_0n)$', save='output')Checkpoint
Can you notice differences in the signals?
If yes, and explain why the speech signals sound different based on the observations.
If no, comment why you think the speech signals sound different.
Let's see the answers in the Fourier domain. We will write a function to plot the spectrum of the signal using the fft function.
def plot_spec(x, Fs, max_freq=None, do_fft=True):
C = int(len(x) / 2)
if max_freq:
C = int(C * max_freq / float(Fs) * 2)
X = np.abs(np.fft.fft(x)[0:C]) if do_fft else x[0:C]
N = Fs * np.arange(0, C) / len(x);
plt.plot(N, X)
plt.xlabel(r'$\gamma$')
plt.ylabel(r'$\hat{x}(\gamma)$')
return N, X
plot_spec(s, Fs, Fs/2)Model the speech as a continuous-time signal , and consider the carrier signal . The output of amplitude modulation using the cosine carrier will have the Fourier transform:
achieving shifting up of the spectrum.
plot_spec(multiply_signals(s, 3000, Fs), Fs, Fs/2);Note that the spectrum of the amplitude modulated signal moves up to around 500 Hz. Also, since the implementation is in discrete time, the spectrum also undergoes aliasing. All these effects are observed in the audio file.
Last updated
Was this helpful?