Complete the code to define a continuous-time signal using a sine wave.
import numpy as np import matplotlib.pyplot as plt t = np.linspace(0, 1, 1000) x = np.sin(2 * np.pi * 5 * [1]) plt.plot(t, x) plt.title('Continuous-time signal') plt.show()
The variable t represents continuous time values, so it should be used inside the sine function to create a continuous-time signal.
Complete the code to create a discrete-time signal sampled from a sine wave.
import numpy as np import matplotlib.pyplot as plt n = np.arange(0, 50) x = np.sin(2 * np.pi * 0.1 * [1]) plt.stem(n, x) plt.title('Discrete-time signal') plt.show()
The variable n represents discrete time indices, so it should be used inside the sine function to create a discrete-time signal.
Fix the error in the code to correctly plot a discrete-time signal.
import numpy as np import matplotlib.pyplot as plt n = np.arange(0, 20) x = np.sin(2 * np.pi * 0.2 * n) plt.plot(n, [1]) plt.title('Discrete-time signal') plt.show()
The variable x holds the signal values to plot against the discrete time indices n.
Fill both blanks to create a dictionary mapping discrete time indices to signal values for samples greater than 0.5.
n = np.arange(0, 30) x = np.sin(2 * np.pi * 0.1 * n) samples = { [1]: [2] for [1] in n if x[[1]] > 0.5 }
n as a key instead of an index.x[n] which is the whole array instead of a single value.We use i as the loop variable iterating over n. The dictionary keys are i, and the values are the corresponding signal values x[i] where the condition is met.
Fill all three blanks to create a dictionary of squared signal values for discrete times where the signal is positive.
n = np.arange(0, 40) x = np.sin(2 * np.pi * 0.05 * n) squared_positive = { [1]: [2]**2 for [1] in n if [3] > 0 }
n as a key.We use k as the loop variable. The dictionary keys are k, the values are the squares of x[k], and the condition checks if x[k] is positive.
