Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohamedhany99 authored Mar 2, 2022
1 parent ac6fb72 commit a5a0304
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
Binary file added Frequency Extraction explaination.pdf
Binary file not shown.
36 changes: 36 additions & 0 deletions Frequency Extractor using FFT (100% work but not filtered).py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 29 00:52:24 2020
@author: aa
"""
from scipy.io import wavfile
#import wave
#import struct
import numpy as np
#first way to enter the wave file data (nframes + frame rate) using the wave lib
#wave_file = wave.open("HH3.wav",'r')
#nframes = wave_file.getnframes()
#data = wave_file.readframes(nframes)
#frate = wave_file.getframerate
#wave_file.close()
#data = struct.unpack('{n}h'.format(n=data_size), data)


#second way to enter the wave file data (nframes + frame rate) using wavfile lib (100% work done but it is not filtered)
fname = "test.wav"
frate, data = wavfile.read(fname)


data = np.array(data)
w = np.fft.fft(data)
freqs = np.fft.fftfreq(len(w))
print(freqs.min(), freqs.max())
# (-0.5, 0.499975)

# Find the peak in the coefficients
idx = np.argmax(np.abs(w))
freq = freqs[idx]
freq_in_hertz = abs(freq * frate)
print(freq_in_hertz)
# 439.8975 for the test.wav
Binary file added test.wav
Binary file not shown.

0 comments on commit a5a0304

Please sign in to comment.