What is the output magnitude array when applying the Fourier transform to a pure sine wave?
import numpy as np from scipy.fft import fft # Create a sine wave signal fs = 100 # Sampling frequency T = 1/fs # Sampling interval t = np.arange(0, 1, T) # Time vector f = 1 # Frequency of sine wave signal = np.sin(2 * np.pi * f * t) # Compute Fourier transform fft_result = fft(signal) magnitude = np.abs(fft_result) print(magnitude[:10])
Recall that the magnitude at the sine wave frequency is related to half the number of samples.
The Fourier transform of a sine wave of frequency 1 Hz sampled 100 times over 1 second has a peak magnitude near 50 at the corresponding frequency bin. Due to numerical precision, the value is very close to 50 but slightly less.
Which explanation best describes why the Fourier transform reveals the frequency components of a signal?
Think about how sine and cosine waves relate to frequency.
The Fourier transform expresses any signal as a combination of sine and cosine waves at different frequencies. The coefficients show how much each frequency is present.
Given a signal sampled at 200 Hz with 400 samples, what is the frequency value of the 50th FFT bin?
import numpy as np fs = 200 # Sampling frequency N = 400 # Number of samples freqs = np.fft.fftfreq(N, 1/fs) print(round(freqs[50], 2))
Frequency bin = index * sampling_rate / number_of_samples
The frequency for bin k is k * fs / N. Here, 50 * 200 / 400 = 25 Hz.
What error does the following code produce?
import numpy as np fs = 100 N = 256 freqs = np.fft.fftfreq(N, fs) print(freqs[:5])
Check the meaning of the second argument in np.fft.fftfreq.
The second argument to np.fft.fftfreq is the sampling interval (1/fs), not the sampling frequency fs. Passing fs directly causes wrong frequency values.
You have a noisy signal composed of a 10 Hz sine wave plus random noise, sampled at 100 Hz for 2 seconds. Which code snippet correctly identifies the dominant frequency?
import numpy as np from scipy.fft import fft fs = 100 T = 2 N = fs * T t = np.linspace(0, T, N, endpoint=False) signal = np.sin(2 * np.pi * 10 * t) + 0.5 * np.random.randn(N) # Which code finds dominant frequency?
Remember to use the correct sampling interval and find the index of the maximum magnitude.
Option A correctly uses 1/fs as the sampling interval, computes FFT, finds the index of the maximum magnitude, and prints the absolute frequency.
Option A uses fs instead of 1/fs, causing wrong frequencies.
Option A does not take absolute value of frequency index, which can be negative.
Option A finds minimum magnitude, which is incorrect.