can you write a simple python code to generate fft of a signal?
- User
can you write a simple python code to generate fft of a signal?
Assistant
pythonimport numpy as np import matplotlib.pyplot as plt # Define the signal t = np.linspace(0, 1, 1000) x = np.sin(2 * np.pi * 100 * t) + np.cos(2 * np.pi * 200 * t) # Compute the FFT X = np.fft.fft(x) # Plot the magnitude and phase of the FFT plt.figure() plt.subplot(2, 1, 1) plt.plot(np.abs(X), 'r') plt.title('Magnitude of the FFT') plt.xlabel('Frequency (Hz)') plt.subplot(2, 1, 2) plt.plot(np.angle(X), 'b') plt.title('Phase of the FFT') plt.xlabel('Frequency (Hz)') plt.show()
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.