Complete the code to compute the magnitude spectrum of a signal using its Fourier Transform.
magnitude = abs([1])The magnitude spectrum is the absolute value of the Fourier Transform of the signal.
Complete the code to compute the phase spectrum of a signal using its Fourier Transform.
phase = [1](np.fft.fft(signal))The phase spectrum is the angle of the Fourier Transform of the signal.
Fix the error in the code to correctly compute the magnitude spectrum.
magnitude = np.abs(np.fft.[1](signal))The magnitude spectrum requires the forward FFT, not the inverse FFT or shifts.
Fill both blanks to create a dictionary with magnitude and phase spectra of the signal.
spectrum = {'magnitude': [1], 'phase': [2]The magnitude is the absolute value of the FFT, and the phase is the angle of the FFT.
Fill the blanks to compute magnitude and phase spectra and plot them using matplotlib.
import matplotlib.pyplot as plt import numpy as np fft_result = np.fft.fft(signal) magnitude = [1] phase = [2] plt.figure(figsize=(10,4)) plt.subplot(1,2,1) plt.plot(magnitude) plt.title('Magnitude Spectrum') plt.subplot(1,2,2) plt.plot(phase) plt.title('Phase Spectrum') plt.show()
Magnitude is the absolute value of the FFT result, phase is the angle of the FFT result.
