音频处理七:(极坐标转换)
程序設(shè)計(jì)七:極坐標(biāo)轉(zhuǎn)換
一:需求分析
? 在數(shù)學(xué)中,極坐標(biāo)系是一個(gè)二維坐標(biāo)系統(tǒng)。該坐標(biāo)系統(tǒng)中的點(diǎn)由一個(gè)夾角和一段相對(duì)中心點(diǎn)——極點(diǎn)(相當(dāng)于我們較為熟知的直角坐標(biāo)系中的原點(diǎn))的距離來(lái)表示。極坐標(biāo)系的應(yīng)用領(lǐng)域十分廣泛,包括數(shù)學(xué)、物理、工程、航海以及機(jī)器人領(lǐng)域。在兩點(diǎn)間的關(guān)系用夾角和距離很容易表示時(shí),極坐標(biāo)系便顯得尤為有用;而在平面直角坐標(biāo)系中,這樣的關(guān)系就只能使用三角函數(shù)來(lái)表示。對(duì)于很多類型的曲線,極坐標(biāo)方程是最簡(jiǎn)單的表達(dá)形式,甚至對(duì)于某些曲線來(lái)說(shuō),只有極坐標(biāo)方程能夠表示。
wavtxtifft -i fft.txt -o polor.txt二:參考知識(shí)
1.本地.txt信息
fft_BAC009S0003W0121.txt BAC009S0003W0121.wav語(yǔ)音進(jìn)行FFT變換后的取值2.坐標(biāo)轉(zhuǎn)換后
fft_polar.txt 是fft_BAC009S0003W0121.txt復(fù)數(shù)轉(zhuǎn)換為極坐標(biāo)輸出(半徑 角度)三:python代碼
求取半徑
r=y2+x2r=\sqrt{y^{2}+x^{2}} r=y2+x2?
r = np.sqrt(complex_real ** 2 + complex_imag ** 2)求取角度
tan?θ=yx\tan \theta=\frac{y}{x} tanθ=xy?
完整代碼
holiday07.py import numpy as np import sys import getopt ''' 將復(fù)數(shù)形式的FFT數(shù)據(jù)轉(zhuǎn)換為極坐標(biāo)形式 ''' def main(argv):try:opts, args = getopt.getopt(argv, "-h-i:-o:", ["help", "input=", "output="])except getopt.GetoptError:print('將讀取到的FFT數(shù)據(jù),轉(zhuǎn)換為極坐標(biāo)形式')print('python holiday07.py -i fft_BAC009S0003W0121.txt -o fft_polar.txt')sys.exit(2)# 處理 返回值options是以元組為元素的列表。for opt, arg in opts:if opt in ("-h", "--help"):print("音頻數(shù)據(jù)轉(zhuǎn)換到極坐標(biāo)")print('將讀取到的FFT數(shù)據(jù),轉(zhuǎn)換為極坐標(biāo)形式')print('python holiday07.py -i fft_BAC009S0003W0121.txt -o fft_polar.txt')sys.exit()elif opt in ("-i", "--input"):input = argelif opt in ("-o", "--output"):output = arg# fft_BAC009S0003W0121.txtcomplex_array = np.loadtxt(input, dtype=np.complex)length = len(complex_array) # 求Nfile = open(output, 'w')for index in range(length):complex_real = np.real(complex_array[index])complex_imag = np.imag(complex_array[index])r = np.sqrt(complex_real ** 2 + complex_imag ** 2)angle = np.arctan(complex_imag / complex_real ) # 默認(rèn)產(chǎn)生的是弧度angle = angle * (180 / np.pi) # 弧度轉(zhuǎn)換為角度# angle = np.arctan(complex_imag / complex_real )s = '(' + str(r) + ' ' + str(angle) + ')' + '\n'file.write(s)file.close()if __name__ == "__main__":# sys.argv[1:]為要處理的參數(shù)列表,sys.argv[0]為腳本名,所以用sys.argv[1:]過(guò)濾掉腳本名。main(sys.argv[1:])#python holiday07.py -i fft_BAC009S0003W0121.txt -o fft_polar.txt四:實(shí)現(xiàn)結(jié)果
1.請(qǐng)求幫助
python holiday07.py -h 音頻數(shù)據(jù)轉(zhuǎn)換到極坐標(biāo) 將讀取到的FFT數(shù)據(jù),轉(zhuǎn)換為極坐標(biāo)形式 python holiday07.py -i fft_BAC009S0003W0121.txt -o fft_polar.txt2.極坐標(biāo)轉(zhuǎn)換
- -i 輸入FFT數(shù)據(jù)
- -o 極坐標(biāo)數(shù)據(jù)
五:結(jié)果顯示及分析
1.結(jié)果顯示
fft_polar.txt 是fft_BAC009S0003W0121.txt復(fù)數(shù)轉(zhuǎn)換為極坐標(biāo)輸出(半徑 角度)
2.結(jié)果比對(duì)
根據(jù)公式可以反算出原始數(shù)據(jù),以其中第二行數(shù)據(jù)(384.47795984237615 -46.14453170047742)為例
x=ρcos?θx=\rho \cos \theta x=ρcosθ
y=ρsin?θy=\rho \sin \theta y=ρsinθ
x=384.47795984237615 *cos(-46.14453170047742)=266.38231
y=384.47795984237615*sin(-46.14453170047742)=-277.2431
原始數(shù)據(jù)為:
與50位技術(shù)專家面對(duì)面20年技術(shù)見(jiàn)證,附贈(zèng)技術(shù)全景圖總結(jié)
以上是生活随笔為你收集整理的音频处理七:(极坐标转换)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 音频处理六:(音频的反FFT)
- 下一篇: 音频处理八:(MFCC 的计算)