Complete the code to create a simple sine wave signal.
import numpy as np import matplotlib.pyplot as plt t = np.linspace(0, 1, 500) signal = np.sin(2 * np.pi * [1] * t) plt.plot(t, signal) plt.title('Sine Wave Signal') plt.show()
The frequency of the sine wave is set to 50 Hz to create a clear signal for modulation.
Complete the code to modulate the sine wave signal by multiplying with a carrier wave.
carrier_freq = 100 carrier = np.sin(2 * np.pi * [1] * t) modulated_signal = signal * carrier plt.plot(t, modulated_signal) plt.title('Amplitude Modulated Signal') plt.show()
The carrier frequency is set to 100 Hz to modulate the original 50 Hz signal.
Fix the error in the code to correctly demodulate the signal by multiplying with the carrier again.
demodulated = modulated_signal * np.sin(2 * np.pi * [1] * t) plt.plot(t, demodulated) plt.title('Demodulated Signal') plt.show()
Demodulation requires multiplying by the same carrier frequency used in modulation, which is 100 Hz.
Fill both blanks to create a dictionary comprehension that maps words to their lengths only if length is greater than 3.
words = ['data', 'science', 'ai', 'ml', 'python'] lengths = {word: [1] for word in words if [2] > 3} print(lengths)
We use len(word) to get the length and filter words with length greater than 3.
Fill all three blanks to create a dictionary comprehension that maps uppercase words to their lengths if length is greater than 2.
words = ['cat', 'dog', 'a', 'elephant'] result = { [1]: [2] for w in words if [3] > 2 } print(result)
The dictionary keys are uppercase words, values are their lengths, filtered by length greater than 2.
