Complete the code to create a simple signal as a list of values.
signal = [0, 1, 0, [1], 0]
The signal is a sequence of values. Here, 1 represents a peak in the signal.
Complete the code to generate a time vector for the signal.
time = [i for i in range([1])]
The time vector should cover 5 points to match the signal length.
Fix the error in the code to plot the signal using matplotlib.
import matplotlib.pyplot as plt plt.plot(time, [1]) plt.show()
The plot function needs the signal values as the second argument to plot against time.
Fill both blanks to create a dictionary mapping time to signal values for points greater than zero.
signal_dict = { [1]: [2] for [1] in time if signal[[1]] > 0 }We use 't' as the loop variable for time, and map it to signal[t] for values greater than zero.
Fill all three blanks to compute the average of signal values above a threshold.
threshold = 0 above_threshold = [[1] for [2] in signal if [3] > threshold] average = sum(above_threshold) / len(above_threshold)
We use 'val' consistently as the variable for list comprehension, loop variable, and condition.
