-
-
Save fedden/d06cd490fcceab83952619311556044a to your computer and use it in GitHub Desktop.
| import numpy as np | |
| import matplotlib.pyplot as plt | |
| modulator_frequency = 4.0 | |
| carrier_frequency = 40.0 | |
| modulation_index = 1.0 | |
| time = np.arange(44100.0) / 44100.0 | |
| modulator = np.sin(2.0 * np.pi * modulator_frequency * time) * modulation_index | |
| carrier = np.sin(2.0 * np.pi * carrier_frequency * time) | |
| product = np.zeros_like(modulator) | |
| for i, t in enumerate(time): | |
| product[i] = np.sin(2. * np.pi * (carrier_frequency * t + modulator[i])) | |
| plt.subplot(3, 1, 1) | |
| plt.title('Frequency Modulation') | |
| plt.plot(modulator) | |
| plt.ylabel('Amplitude') | |
| plt.xlabel('Modulator signal') | |
| plt.subplot(3, 1, 2) | |
| plt.plot(carrier) | |
| plt.ylabel('Amplitude') | |
| plt.xlabel('Carrier signal') | |
| plt.subplot(3, 1, 3) | |
| plt.plot(product) | |
| plt.ylabel('Amplitude') | |
| plt.xlabel('Output signal') | |
| plt.show() |
How does the plt.plot has one value (modulator/carrier/product)? The graph looks like it has 2 values for x and y axis.
This is great for demonstration purposes! One thing I'm curious about; however, is that it appears that the frequency of the carrier is modulated by the slope of the base-band signal, rather than by it's amplitude. The max and min frequencies in the output signal appear to coincide with the PGT and NGT zeroes in the base-band signal. I was always under the impression it should be the opposite.
I'm also under the impression that the output signal is modulated by the slope of the base-band signal, rather than by it's amplitude, and think it should be the other way around 🤔
Anyone looking up the code,
-
Remove the
2.0 * np.piparts as it is unnecessary -
change
product[i] = np.sin(2. * np.pi * (carrier_frequency * t + modulator[i]))
to
product[i] = np.sin(carrier_frequency * time - modulation_index * np.cos(modulator_frequency * time))
Shouldn't the modulation signal be without the 2*pi