日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python频率_Python中的频率分析

發布時間:2023/12/10 python 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python频率_Python中的频率分析 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我試圖使用Python來檢索現場音頻輸入的主頻率。目前,我正在試驗使用音頻流我的筆記本內置麥克風,但當測試以下代碼時,我得到了非常差的結果。# Read from Mic Input and find the freq's

import pyaudio

import numpy as np

import bge

import wave

chunk = 2048

# use a Blackman window

window = np.blackman(chunk)

# open stream

FORMAT = pyaudio.paInt16

CHANNELS = 1

RATE = 1920

p = pyaudio.PyAudio()

myStream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, frames_per_buffer = chunk)

def AnalyseStream(cont):

data = myStream.read(chunk)

# unpack the data and times by the hamming window

indata = np.array(wave.struct.unpack("%dh"%(chunk), data))*window

# Take the fft and square each value

fftData=abs(np.fft.rfft(indata))**2

# find the maximum

which = fftData[1:].argmax() + 1

# use quadratic interpolation around the max

if which != len(fftData)-1:

y0,y1,y2 = np.log(fftData[which-1:which+2:])

x1 = (y2 - y0) * .5 / (2 * y1 - y2 - y0)

# find the frequency and output it

thefreq = (which+x1)*RATE/chunk

print("The freq is %f Hz." % (thefreq))

else:

thefreq = which*RATE/chunk

print("The freq is %f Hz." % (thefreq))

# stream.close()

# p.terminate()

該代碼是從this question中分離出來的,后者處理波形文件的傅里葉分析。它在當前的模塊化結構中,因為我是在Blender游戲環境中實現它的(因此在頂部是import bge),但是我很確定我的問題在AnalyseStream模塊中。

如果您能提供任何建議,我們將不勝感激。

更新:我時不時地得到正確的值,但在不正確的值中很少發現這些值(<10Hz)。這個程序運行得很慢。

總結

以上是生活随笔為你收集整理的python频率_Python中的频率分析的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。