Assignment 1 Rajveer Saini: Question 2 Code
Assignment 1 Rajveer Saini: Question 2 Code
ASSIGNMENT 1
Rajveer Saini
Question 1
B) x = np.linspace(0,5,200000)
f1= 500
f2= 501
y = np.sin(2 * np.pi * f1 * x) + np.sin(2 * np.pi * f2 * x)
sd.play(y,samplerate=48000)
Question 2 Code
# Function to load an audio file and return its sample rate and signal
def load_audio(file_path):
sample_rate, data = wavfile.read(file_path) # Read WAV file
if data.ndim > 1: # Convert stereo to mono if necessary
data = data.mean(axis=1)
return sample_rate, data
# Function to perform FFT and identify the dominant frequency in the signal
def find_dominant_frequency(signal, sample_rate):
n = len(signal) # Get the number of samples
yf = fft(signal) # Compute the Fast Fourier Transform (FFT)
xf = fftfreq(n, 1 / sample_rate) # Compute frequency bins
Question 2 Results
Below are the results from the analysis, including frequency spectra and spectrograms.