I am looking to determine whether a given audio file contains a certain frequency, similar to this question. However, as a beginner, I need help understanding the output.
If I am understanding the linked question correctly, we start by observing the fftfreq output, which is the x axis if understood graphically. Since my sampling rate is 44kHz, the fftfreq contains approximately 22,000 bins. If I wanted to query what magnitude occurred at 800hz, I would simply access value = fftfreq_output[800]
, then index the actual fft values using this new value like so: fft_output[value]
. However, I am confused by the values that are returned. My code is below:
from scipy.io import wavfile
from scipy.fft import fft, fftfreq
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
user_in = input("Please enter the relative path to your wav file --> ")
sampling_rate, data = wavfile.read(user_in)
print("sampling rate:", sampling_rate)
duration = len(data) / float(sampling_rate)
print("duration:", duration)
number_samples_in_seg = int(sampling_rate * duration)
fft_of_data = fft(data)
fft_bins_from_data = fftfreq(number_samples_in_seg, 1 / sampling_rate)
fft_bins_from_data = fft_bins_from_data[0:number_samples_in_seg//2]
fft_of_data = abs(fft_of_data[0:number_samples_in_seg//2])
value = fft_bins_from_data[800]
print(value)
output = fft_of_data[int(value)]
print(output)
inputing a random wav file of a conversation, my output is this:
6.1500615006150054
71544.37927836686
My questions are:
Am I properly indexing the fft_output?
How can I interpret these numbers to observe what is the magnitude of the signal at a frequency of 800hz?
Thank you for any help.