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 s[n]s[n] with a cosine signal cos(ω0n)\cos(\omega_0 n). 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.

What is the expected outcome? Can you guess? Better, can you analytically show the outcome?

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

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 x(t) x(t), and consider the carrier signal cos(2πf0t) \cos(2\pi f_0 t). The output of amplitude modulation using the cosine carrier x(t)cos(2πf0t) x(t)\cos(2\pi f_0 t) will have the Fourier transform:

12[x^(γ+f0)+x^(γf0)],\frac{1}{2}\left[\hat{x}(\gamma+f_0) + \hat{x}(\gamma-f_0)\right],

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?