What is the output of the following Python code using numpy.fft.fft on a simple signal?
import numpy as np signal = np.array([1, 0, 1, 0]) fft_result = np.fft.fft(signal) print(np.round(fft_result, 2))
Remember FFT output is complex and symmetric for real inputs.
The FFT of the signal [1, 0, 1, 0] produces [2.+0.j 0.+0.j 2.+0.j 0.+0.j] (rounded to 2 decimals), corresponding to DC and Nyquist components. The output is symmetric for real inputs.
For a signal sampled at 8 Hz with 8 samples, what frequency does the 3rd FFT bin represent?
Frequency bin = (bin index) * (sampling rate / number of samples)
Frequency for bin k is k * (Fs / N). Here, k=3, Fs=8 Hz, N=8, so frequency = 3 * (8/8) = 3 Hz.
What error will this code raise?
import numpy as np signal = [1, 2, 3] fft_result = np.fft.fft(signal, n=2) print(fft_result)
Check how FFT handles the n parameter when smaller than signal length.
FFT with n smaller than signal length truncates the signal. No error is raised.
What is the magnitude spectrum output of this code?
import numpy as np signal = np.array([0, 1, 0, -1]) fft_result = np.fft.fft(signal) magnitude = np.abs(fft_result) print(np.round(magnitude, 2))
Magnitude is the absolute value of complex FFT output.
The FFT of [0,1,0,-1] has magnitude [0,2,0,2].
You have a signal sampled at 100 Hz with 1000 samples. Which code snippet correctly finds the dominant frequency in the signal?
Remember to use fftfreq with correct sample spacing and find frequency corresponding to max magnitude.
Option C correctly calculates frequencies with sample spacing 1/100 and finds the frequency with max FFT magnitude.
