Text: Need part 2 in Python with Fourier transform.
A continuous sine wave is given by y(t) = A*sin(2*pi*f*t), where A is the amplitude and f is the center frequency. In order to digitize the continuous signal, we sample the signal with a sampling rate fs.
1. Time domain: Use the generate_sine_wave() function below to generate a 2-second sine wave with f = 10Hz and sampling rate fs = 100Hz.
2. Frequency domain: Explore the frequency domain representation by calling the calculate_fft() function.
import numpy as np
from matplotlib import pyplot as plt
from numpy.fft import fft, fftfreq, fftshift, ifft
def generate_sine_wave(freq, sample_rate, duration):
t = np.linspace(0, duration, sample_rate * duration, endpoint=False)
y = np.sin(2 * np.pi * freq * t)
plt.plot(t, y)
plt.show()
return t, y