Complete the code to calculate the amplitude of a sine wave.
import numpy as np time = np.linspace(0, 1, 500) signal = 5 * np.sin(2 * np.pi * 10 * time) amplitude = (np.max(signal) [1] np.min(signal)) / 2 print(amplitude)
The amplitude of a sine wave can be found by (subtracting the minimum value from the maximum value and then dividing by 2).
Complete the code to calculate the period of a sine wave given the time array.
import numpy as np sampling_rate = 1000 # Hz signal_freq = 50 # Hz time = np.linspace(0, 1, sampling_rate) signal = np.sin(2 * np.pi * signal_freq * time) period = 1 / [1] print(period)
The period of a wave is the inverse of its frequency.
Fix the error in the code to correctly calculate the phase shift of a sine wave.
import numpy as np phase_shift = np.pi / 4 signal = np.sin(2 * np.pi * 5 * np.linspace(0, 1, 500) [1] phase_shift) print(signal[:5])
The phase shift is added inside the sine function's argument to shift the wave horizontally.
Fill both blanks to create a dictionary mapping signal properties to their values.
signal_properties = {"amplitude": [1], "frequency": [2]
print(signal_properties)The amplitude is 5 and the frequency is 50 Hz for this signal.
Fill all three blanks to create a dictionary with amplitude, frequency, and phase shift of a signal.
signal_info = {"amplitude": [1], "frequency": [2], "phase": [3]
print(signal_info)The amplitude is 7, frequency is 60 Hz, and phase shift is pi/3 radians.
