2. Write the Python code for synthesizing a periodic signal with inputs: length T (in seconds), Fourier coefficients {00
Posted: Sun May 15, 2022 8:22 pm
Please answer this, and the answer below is NOT the
correct answer.
2. Write the Python code for synthesizing a periodic signal with inputs: length T (in seconds), Fourier coefficients {00,..., an}, fundamental frequency fo, and sampling rate Fs (in Hz).
import numpy as np from matplotlib import pyplot as plt SAMPLE_RATE= 44100 # Hertz DURATION = 5 # Seconds def generate_sine_wave(freq, sample_rate, duration): x= np.linspace(0, duration, sample_rate * duration, endpoint=False) frequencies = x * freq # 2pi because np.sin takes radians y = np.sin((2 * np.pi) * frequencies) return x, y # Generate a 2 hertz sine wave that lasts for 5 seconds X, y = generate_sine_wave(2, SAMPLE_RATE, DURATION) plt.plot(x, y)
correct answer.
2. Write the Python code for synthesizing a periodic signal with inputs: length T (in seconds), Fourier coefficients {00,..., an}, fundamental frequency fo, and sampling rate Fs (in Hz).
import numpy as np from matplotlib import pyplot as plt SAMPLE_RATE= 44100 # Hertz DURATION = 5 # Seconds def generate_sine_wave(freq, sample_rate, duration): x= np.linspace(0, duration, sample_rate * duration, endpoint=False) frequencies = x * freq # 2pi because np.sin takes radians y = np.sin((2 * np.pi) * frequencies) return x, y # Generate a 2 hertz sine wave that lasts for 5 seconds X, y = generate_sine_wave(2, SAMPLE_RATE, DURATION) plt.plot(x, y)